Load ads pictures directly on the server.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 26 May 2012 18:23:55 +0000 (20:23 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 26 May 2012 18:23:55 +0000 (20:23 +0200)
apps/companyfront/config/app.yml
apps/companyfront/modules/ad/actions/actions.class.php
apps/companyfront/modules/ad/templates/_list.php
lib/form/doctrine/AdForm.class.php

index 40a5a99..c36f791 100644 (file)
@@ -3,10 +3,11 @@
 
 # default values
 all:
-  max_offices_on_pager: 3
-  max_ads_on_pager: 2
-  max_categories_on_pager: 3
-  default_language: eng                               # Everything must exist at least with this language
+  max_offices_on_pager:      3
+  max_ads_on_pager:          2
+  max_categories_on_pager:   3
+  default_picture_directory: /home/gustavo/symfonyreloaded/mobiads/web/uploads/images/
+  default_language:          eng                      # Everything must exist at least with this language
 
   sf_guard_plugin:
      remember_key_expiration_age: 2592000             # 30 days in seconds
index 9919373..76a177b 100644 (file)
@@ -159,6 +159,10 @@ class adActions extends sfActions
 
     $this->forward404Unless($companyId == $companyUserId, sprintf('Ad does not exist (%s).', $request->getParameter('id')));
 
+    //Remove picture from file system.
+    $fs = new sfFilesystem();
+    $fs->remove(sfConfig::get('app_default_picture_directory').$ad->getAdMobileImageLink());
+    //Remove ad from database.
     $ad->delete();
 
     $this->redirect('ad/index');
index ca8ac29..84322dc 100644 (file)
   <tbody>
     <?php foreach ($ads as $ad): ?>
     <tr>
-      <td><img src="<?php echo $ad->getAd()->getAdMobileImageLink() ?>" width="80" height="80" alt="<?php echo $ad->getAdName() ?>"/></td>
+      <td><img src="<?php echo "/uploads/images/".$ad->getAd()->getAdMobileImageLink() ?>" width="80" height="80" alt="<?php echo $ad->getAdName() ?>"/></td>
       <td>
         <?php if ($ad->getAd()->getCompanyCategId() != null): ?>
             <?php echo $ad->getAd()->getCompanyCategory() ?>
         <?php endif; ?>
       </td>
       <td><?php echo $ad->getAdName() ?></td>
-         <td><a href="<?php echo url_for('ad/edit?id='.$ad->getAd()->getId()) ?>"><img src="/images/pencil_add.png" alt="" title="" border="0" /></a></td>
+         <td><a href="<?php echo url_for('ad/edit?id='.$ad->getAd()->getId().'&page='.$page) ?>"><img src="/images/pencil_add.png" alt="" title="" border="0" /></a></td>
       <td><?php echo link_to('<img src="/images/inadminpanel/images/trash.png" alt="" title="" border="0" />', 'ad/delete?id='.$ad->getAd()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?></td>
 
     </tr>
index 7235442..6ad7420 100644 (file)
@@ -28,6 +28,19 @@ class AdForm extends BaseAdForm
                                                                                     'required' => false,
                                                                                     'query'    => $companyCategs));
 
+
+    $this->widgetSchema['ad_mobile_image_link'] =
+                new sfWidgetFormInputFileEditable(array('file_src'    => '/uploads/images/'.$this->getObject()->ad_mobile_image_link,
+                                                        'edit_mode'   => !$this->isNew(),
+                                                        'is_image'    => true,
+                                                        'with_delete' => false));
+
+
+    $this->validatorSchema['ad_mobile_image_link'] = new sfValidatorFile(array('mime_types' => 'web_images',
+                                                                               'path' => sfConfig::get('app_default_picture_directory'),
+                                                                               'required' => true));
+
+
     $this->widgetSchema->setLabels(array('company_categ_id'  => 'Company Category'));
     $this->widgetSchema->setLabels(array('ad_mobile_image_link' => "Picture on the user's mobile"));