Link Office to Ads.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 19 May 2012 19:03:21 +0000 (21:03 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 19 May 2012 19:03:21 +0000 (21:03 +0200)
I hate Symfony and PHP.

18 files changed:
apps/companyfront/config/app.yml
apps/companyfront/modules/office/actions/actions.class.php
apps/companyfront/modules/office/templates/_formCustomOffice.php
apps/companyfront/modules/office/templates/_formCustomOfficeAds.php
apps/companyfront/modules/office/templates/_list.php
apps/companyfront/modules/office/templates/editSuccess.php
apps/companyfront/modules/office/templates/indexSuccess.php
apps/companyfront/modules/office/templates/linkSuccess.php
apps/companyfront/modules/office/templates/newSuccess.php
lib/form/doctrine/MaxItemsPerPage.class.php [new file with mode: 0644]
lib/form/doctrine/OfficeAdsForm.class.php
lib/form/doctrine/OfficeForm.class.php
lib/model/doctrine/City.class.php
lib/model/doctrine/Country.class.php
lib/model/doctrine/Office.class.php
lib/model/doctrine/OfficeTable.class.php
lib/model/doctrine/Region.class.php
web/sfFormExtraPlugin [new symlink]

index 3c2b78e..adb5077 100644 (file)
@@ -5,6 +5,7 @@
 all:
   max_offices_on_pager: 3
   max_ads_on_pager: 2
+  max_categories_on_pager: 2
   default_language: eng                               # Everything must exist at least with this language
 
   sf_guard_plugin:
index 14c3305..71fe3c0 100644 (file)
@@ -19,7 +19,11 @@ class officeActions extends sfActions
     //Just 1 user owns a company. Should this be improved?
     $companyId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
 
-    $query=OfficeTable::getInstance()->getOfficesByCompanyIdQuery($companyId);
+    //Sort list
+    $this->sort = $request->getParameter('sort', 'id');
+    $orderBy = $this->validateSort($this->sort); 
+    
+    $query=OfficeTable::getInstance()->getOfficesByCompanyIdWithSortQuery($companyId, $orderBy);
 
     $this->pager = new sfDoctrinePager('Office', sfConfig::get('app_max_offices_on_pager'));
     $this->pager->setQuery($query);
@@ -36,6 +40,8 @@ class officeActions extends sfActions
   public function executeNew(sfWebRequest $request)
   {
     $this->form = new OfficeForm();
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
   }
 
   public function executeCreate(sfWebRequest $request)
@@ -52,7 +58,10 @@ class officeActions extends sfActions
 
     $this->form = new OfficeForm($officeInit);
 
-    $this->processForm($request, $this->form);
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+
+    $this->processForm($request, $this->form, $this->sort, $this->page);
 
     $this->setTemplate('new');
   }
@@ -74,6 +83,9 @@ class officeActions extends sfActions
 
     $this->forward404Unless($companyOfficeId == $companyUserId, sprintf('Office does not exist (%s).', $request->getParameter('id')));
 
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+
     $this->form = new OfficeForm($office);
   }
 
@@ -97,7 +109,10 @@ class officeActions extends sfActions
 
     $this->form = new OfficeForm($office);
 
-    $this->processForm($request, $this->form);
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+
+    $this->processForm($request, $this->form, $this->sort, $this->page);
 
     $this->setTemplate('edit');
   }
@@ -123,17 +138,20 @@ class officeActions extends sfActions
 
     $office->delete();
 
-    $this->redirect('office/index');
+    $sort = $request->getParameter('sort', 'id');
+    $page = $request->getParameter('page', 1);
+
+    $this->redirect('office/index?page='.$page.'&sort='.$sort);
   }
 
-  protected function processForm(sfWebRequest $request, sfForm $form)
+  protected function processForm(sfWebRequest $request, sfForm $form, $sort, $page)
   {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid())
     {
       $office = $form->save();
 
-      $this->redirect('office/edit?id='.$office->getId());
+      $this->redirect('office/edit?id='.$office->getId().'&page='.$page.'&sort='.$sort);
     }
   }
 
@@ -157,5 +175,113 @@ class officeActions extends sfActions
     $officeAds = OfficeAdsTable::getInstance()->findOneByOfficeId($officeId);
 
     $this->form = new OfficeAdsForm($officeAds, array('companyId' => $companyOfficeId));
+
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+    $this->officeId = $officeId;
+  }
+
+  public function executeCreateLink(sfWebRequest $request)
+  {
+    $this->forward404Unless($request->isMethod(sfRequest::POST));
+
+    $officeId = $request->getParameter('officeId');
+
+    //Get user Id
+    $userId = $this->getUser()->getGuardUser()->getId();
+
+
+    //Get company owned by that user and insert value in form
+    $companyUserId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
+    //Get company owned by that user and insert value in form
+    $companyOfficeId = OfficeTable::getInstance()->findOneById($officeId)->getCompanyId();
+
+    $this->forward404Unless($companyOfficeId == $companyUserId, sprintf('Office does not exist (%s).', $request->getParameter('officeId')));
+
+    $officeAdsInit = new OfficeAds();
+    $officeAdsInit->office_id = $officeId;
+
+    $this->form = new OfficeAdsForm($officeAdsInit, array('companyId' => $companyOfficeId));
+
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+    $this->officeId = $officeId;
+
+    $this->processAdsForm($request, $this->form, $this->sort, $this->page);
+
+    $this->setTemplate('link');
+  }
+
+  public function executeUpdateLink(sfWebRequest $request)
+  {
+    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
+    $this->forward404Unless($officeAds = Doctrine_Core::getTable('OfficeAds')->find(array($request->getParameter('id'))), sprintf('Object office ads does not exist (%s).', $request->getParameter('id')));
+
+    //Get user Id
+    $userId = $this->getUser()->getGuardUser()->getId();
+
+    //Get company owned by that user and insert value in form
+    $companyUserId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
+
+    //Get id number sent by the user (never trust the users)
+    $officeAdsId = $request->getParameter('id');
+    $companyOfficeId = OfficeAdsTable::getInstance()->findOneById($officeAdsId)->getOffice()->getCompanyId();
+
+    $this->forward404Unless($companyOfficeId == $companyUserId, sprintf('Office does not exist (%s).', $request->getParameter('id')));
+
+
+    $this->form = new OfficeAdsForm($officeAds, array('companyId' => $companyOfficeId));
+
+    $this->sort = $request->getParameter('sort', 'id');
+    $this->page = $request->getParameter('page', 1);
+    $this->officeId = $officeAds->getOfficeId();
+
+    $this->processAdsForm($request, $this->form, $this->sort, $this->page);
+
+    $this->setTemplate('link');
+  }
+
+
+  protected function processAdsForm(sfWebRequest $request, sfForm $form, $sort, $page)
+  {
+    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
+    if ($form->isValid())
+    {
+      $officeAds = $form->save();
+
+      $this->redirect('office/link?id='.$officeAds->getOfficeId().'&page='.$page.'&sort='.$sort);
+    }
+  }
+
+
+ /**
+  * We must validate the data coming from the user.
+  *
+  * @param sort value as string
+  * @return custom sort value, the office id by default
+  */
+  private function validateSort($sort)
+  {
+    switch ($sort) {
+        case "country":
+            $orderBy = "country.id";
+            break;
+        case "region":
+            $orderBy = "region.id";
+            break;
+        case "city":
+            $orderBy = "city.id";
+            break;
+        case "address":
+            $orderBy = "office_street_address";
+            break;
+        case "zip":
+            $orderBy = "office_zip";
+            break;
+        default:
+            $orderBy = "office.id";
+    }
+    
+    return $orderBy;
   }
 }
index 989caba..9dfda12 100644 (file)
@@ -10,9 +10,9 @@
       <tr>
         <td colspan="2">
           <?php echo $form->renderHiddenFields(false) ?>
-          &nbsp;<a href="<?php echo url_for('office/index') ?>"><?php echo __('Back to list') ?></a>
+          &nbsp;<a href="<?php echo url_for('office/index?'.'&page='.$page.'&sort='.$sort) ?>">Back to list</a>
           <?php if (!$form->getObject()->isNew()): ?>
-            &nbsp;<?php echo link_to('Delete', 'office/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
+            &nbsp;<?php echo link_to('Delete', 'office/delete?id='.$form->getObject()->getId().'&page='.$page.'&sort='.$sort, array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
           <?php endif; ?>
           <input type="submit" value=<?php echo __('Save') ?> />
         </td>
index 74bb006..5b4d515 100644 (file)
@@ -2,7 +2,7 @@
 <?php use_javascripts_for_form($form) ?>
 <?php use_javascript('/sfFormExtraPlugin/js/double_list.js') ?>
 
-<form action="<?php echo url_for('office/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
+<form action="<?php echo url_for('office/'.($form->getObject()->isNew() ? 'createLink' : 'updateLink').'?officeId='.$officeId.(!$form->getObject()->isNew() ? '&id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
 <?php if (!$form->getObject()->isNew()): ?>
 <input type="hidden" name="sf_method" value="put" />
 <?php endif; ?>
@@ -11,7 +11,7 @@
       <tr>
         <td colspan="2">
           <?php echo $form->renderHiddenFields(false) ?>
-          &nbsp;<a href="<?php echo url_for('office/index') ?>"><?php echo __('Back to list') ?></a>
+          &nbsp;<a href="<?php echo url_for('office/index?page='.$page.'&sort='.$sort) ?>"><?php echo __('Back to list') ?></a>
           <input type="submit" value=<?php echo __('Save') ?> />
         </td>
       </tr>
index 12cfef5..2e51a4f 100644 (file)
@@ -1,29 +1,37 @@
 <table id="rounded-corner">
   <thead>
     <tr>
-         <th scope="col" class="rounded-company"><?php echo __('Street Address') ?></th>
+      <th scope="col" class="rounded-company"><a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=country"><?php echo __('Country') ?></a></th>
+      <th scope="col" class="rounded"><a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=region"><?php echo __('Region') ?></a></th>
+         <th scope="col" class="rounded"><a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=city"><?php echo __('City') ?></a></th>
+      <th scope="col" class="rounded"><a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=address"><?php echo __('Street Address') ?></a></th>
+      <th scope="col" class="rounded"><a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=zip"><?php echo __('ZIP') ?></a></th>
          <th scope="col" class="rounded"><?php echo __('Longitude') ?></th>
          <th scope="col" class="rounded"><?php echo __('Latitude') ?></th>
       <th scope="col" class="rounded"><?php echo __('Edit') ?></th>
       <th scope="col" class="rounded"><?php echo __('Link to Ads') ?></th>
-      <th scope="col" class="rounded-q4"><?php echo __('Remove') ?></th>
+      <th scope="col" class="rounded-q4"></th>
     </tr>
   </thead>
   <tfoot>
     <tr>
-        <td colspan="5" class="rounded-foot-left"><em><?php echo __('Offices List') ?></em></td>
+        <td colspan="9" class="rounded-foot-left"><em><?php echo __('Offices List') ?></em></td>
         <td class="rounded-foot-right">&nbsp;</td>
     </tr>
   </tfoot>
   <tbody>
     <?php foreach ($offices as $office): ?>
     <tr>
+      <td><?php echo $office->getCity()->getRegion()->getCountry() ?></td>
+      <td><?php echo $office->getCity()->getRegion() ?></td>
+      <td><?php echo $office->getCity() ?></td>
       <td><?php echo $office->getOfficeStreetAddress() ?></td>
+      <td><?php echo $office->getOfficeZip() ?></td>
       <td><?php echo $office->getLongitude() ?></td>
          <td><?php echo $office->getLatitude() ?></td>
-         <td><a href="<?php echo url_for('office/edit?id='.$office->getId()) ?>"><img src="/images/pencil_add.png" alt="" title="" border="0" /></a></td>
-      <td><a href="<?php echo url_for('office/link?id='.$office->getId()) ?>"><img src="/images/link.png" alt="" title="" border="0" /></a></td>
-      <td><?php echo link_to('<img src="/images/inadminpanel/images/trash.png" alt="" title="" border="0" />', 'office/delete?id='.$office->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?></td>
+         <td><a href="<?php echo url_for('office/edit?id='.$office->getId().'&page='.$page.'&sort='.$sort) ?>"><img src="/images/pencil_add.png" alt="" title="" border="0" /></a></td>
+      <td><a href="<?php echo url_for('office/link?id='.$office->getId().'&page='.$page.'&sort='.$sort) ?>"><img src="/images/link.png" alt="" title="" border="0" /></a></td>
+      <td><?php echo link_to('<img src="/images/inadminpanel/images/trash.png" alt="" title="" border="0" />', 'office/delete?id='.$office->getId().'&page='.$page.'&sort='.$sort, array('method' => 'delete', 'confirm' => 'Are you sure?')) ?></td>
 
     </tr>
     <?php endforeach; ?>
index 5a0da86..14a7687 100644 (file)
@@ -1,3 +1,3 @@
 <h2><?php echo __('Edit Office') ?></h2>
 
-<?php include_partial('formCustomOffice', array('form' => $form)) ?>
+<?php include_partial('formCustomOffice', array('form' => $form, 'page' => $page, 'sort' => $sort)) ?>
index 2908f40..bcd27ae 100644 (file)
@@ -1,28 +1,33 @@
-<h2><?php echo __('Offices List') ?></h2>
+<h2><?php echo __('Offices Index') ?></h2>
+
+<?php if ($pager->haveToPaginate()): ?>
+    <?php include_partial('office/list', array('offices' => $pager->getResults(), 'page' => $pager->getPage(), 'sort' => $sort)) ?>
+<?php else: ?>
+    <?php include_partial('office/list', array('offices' => $pager->getResults(), 'page' => '1', 'sort' => $sort)) ?>
+<?php endif; ?>
 
-<?php include_partial('office/list', array('offices' => $pager->getResults())) ?>
 
 <?php if ($pager->haveToPaginate()): ?>
   <div class="pagination">
-    <a href="<?php echo url_for('offices_index') ?>?page=1"><?php echo __('first page') ?></a>
+    <a href="<?php echo url_for('offices_index') ?>?page=1&sort=<?php echo $sort ?>"><?php echo __('first page') ?></a>
 
-    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getPreviousPage() ?>"><?php echo __('<< prev') ?></a>
+    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getPreviousPage() ?>&sort=<?php echo $sort ?>"><?php echo __('<< prev') ?></a>
 
     <?php foreach ($pager->getLinks() as $page): ?>
       <?php if ($page == $pager->getPage()): ?>
         <?php echo $page ?>
       <?php else: ?>
-        <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>"><?php echo $page ?></a>
+        <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $page ?>&sort=<?php echo $sort ?>"><?php echo $page ?></a>
       <?php endif; ?>
     <?php endforeach; ?>
 
-    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getNextPage() ?>"><?php echo __('next >>') ?></a>
+    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getNextPage() ?>&sort=<?php echo $sort ?>"><?php echo __('next >>') ?></a>
 
-    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getLastPage() ?>"><?php echo __('last page') ?></a>
+    <a href="<?php echo url_for('offices_index') ?>?page=<?php echo $pager->getLastPage() ?>&sort=<?php echo $sort ?>"><?php echo __('last page') ?></a>
   </div>
 <?php endif; ?>
 
-  <a href="<?php echo url_for('office/new') ?>" class="bt_green"><span class="bt_green_lft"></span><strong><?php echo __('Create new Office') ?></strong><span class="bt_green_r"></span></a>
+  <a href="<?php echo url_for('office/new?page='.$page.'&sort='.$sort) ?>" class="bt_green"><span class="bt_green_lft"></span><strong><?php echo __('Create new Office') ?></strong><span class="bt_green_r"></span></a>
 
 
 
index f4174d5..4597260 100644 (file)
@@ -1,3 +1,3 @@
 <h2><?php echo __('Link to Ads') ?></h2>
 
-<?php include_partial('formCustomOfficeAds', array('form' => $form)) ?>
+<?php include_partial('formCustomOfficeAds', array('form' => $form, 'page' => $page, 'sort' => $sort, 'officeId' => $officeId)) ?>
index 5b24bdf..ce51efe 100644 (file)
@@ -1,3 +1,3 @@
 <h2><?php echo __('New Office') ?></h2>
 
-<?php include_partial('formCustomOffice', array('form' => $form)) ?>
+<?php include_partial('formCustomOffice', array('form' => $form, 'page' => $page, 'sort' => $sort)) ?>
diff --git a/lib/form/doctrine/MaxItemsPerPage.class.php b/lib/form/doctrine/MaxItemsPerPage.class.php
new file mode 100644 (file)
index 0000000..fae9546
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * Max items per page.
+ *
+ * Combobox to show the available languages.
+ *
+ * @package    mobiads
+ * @subpackage form
+ * @author     Gustavo Martin Morcuende
+ * @version
+ */
+class MaxItemsPerPage extends sfFormSymfony
+{
+  public function setup()
+  {
+    $this->setWidgets(array('max_items' => new sfWidgetFormInputText(),));
+
+    $this->setValidators(array('max_items' => new sfValidatorNumber(array('required' => true,
+                                                                          'trim' => true),
+                                                                    array('required' => 'The latitude field is required')),));
+
+
+    $this->widgetSchema->setNameFormat('max_items_page[%s]');
+
+
+    $this->widgetSchema->setLabels(array('max_items' => 'Max items per page: ',));
+
+
+    $this->validatorSchema->setOption('allow_extra_fields', false);
+    $this->validatorSchema->setOption('filter_extra_fields', true);
+
+    $this->widgetSchema->setFormFormatterName('table');
+
+    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
+
+    //i18n (Internationalization)
+    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('max_items_form');
+
+    parent::setup();
+  }  
+}
index f1689bd..dedc2d7 100644 (file)
@@ -10,6 +10,9 @@
  */
 class OfficeAdsForm extends BaseOfficeAdsForm
 {
+  protected $scheduledForSave = array();
+
+
   public function configure()
   {
     //Narrow down options.
@@ -25,9 +28,18 @@ class OfficeAdsForm extends BaseOfficeAdsForm
                                                                         'renderer_class' => 'sfWidgetFormSelectDoubleList',
                                                                         'query'          => $query));
 
+    $this->widgetSchema->setLabels(array('city_id'               => 'City: ',
+                                         'longitude'             => 'Longitude (180 to -180): ',
+                                         'latitude'              => 'Latitude (90 to -90): ',
+                                         'office_street_address' => 'Address: ',
+                                         'office_zip'            => 'ZIP:',));
+
+
     $this->validatorSchema['ad_id'] =  new sfValidatorDoctrineChoice(array('model'    => $this->getRelatedModelName('Ad'),
                                                                            'multiple' => true,
                                                                            'query'    => $query));
+
+    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('office_ads_form');
   }
 
  /**
@@ -51,4 +63,66 @@ class OfficeAdsForm extends BaseOfficeAdsForm
         $this->setDefault('ad_id', $already_chosen);
     }
   }
+
+
+ /**
+  * Overriding doSave method from lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
+  *
+  * We are updating the data base in just 1 transaction
+  */
+  protected function doSave($con = null)
+  {
+
+    if (null === $con)
+    {
+      $con = $this->getConnection();
+    }
+   
+    foreach ($this->scheduledForSave as $index => $value)
+    {
+        $value->save($con);
+    }
+  }
+
+
+ /**
+  * Overriding doBind method
+  *
+  * TODO: I am breaking the validations. How could I do this in a right way?
+  */  
+  protected function doBind(array $values)
+  {
+    if (!isset($values['ad_id']))
+    {
+        if (!$this->getObject()->isNew())
+        { 
+            $officeAds = OfficeAdsTable::getInstance()->findByOfficeId($this->getObject()->getOfficeId());
+           
+            foreach ($officeAds as $officeAd)
+            { 
+                $officeAd->delete();
+            }
+        }    
+        return;
+    }
+
+    $officeAds = OfficeAdsTable::getInstance()->findByOfficeId($this->getObject()->getOfficeId());
+
+    foreach ($values['ad_id'] as $index => $value)
+    {
+        if (!$this->getObject()->isNew())
+        { 
+            foreach ($officeAds as $officeAd)
+            {
+                if ($officeAd->getAdId() == $value)
+                    continue 2;
+            }
+        }
+        $officeAds = new OfficeAds();
+        $officeAds->office_id = $this->getObject()->getOfficeId();
+        $officeAds->ad_id = $value;
+        $this->scheduledForSave[$index] = $officeAds;
+    }
+  }
 }
index bab320c..4a0b661 100644 (file)
@@ -47,6 +47,17 @@ class OfficeForm extends BaseOfficeForm
                                          'office_street_address' => 'Address: ',
                                          'office_zip'            => 'ZIP:',));
 
+
+    //In the future the companies could pay for improvements in their accounts (premium accounts)
+    //1 premium company could avoid to other companies on the same GPS point. This validator should check if that GPS point is being used by
+    //another company and if that company is premium or not.  
+    $this->validatorSchema->setPostValidator(
+      new sfValidatorAnd(array(
+        new sfValidatorDoctrineUnique(array('model' => $this->getModelName(), 'column' => array('office_gps'))),
+      ))
+    );
+
+
     $this->validatorSchema->setOption('allow_extra_fields', false);
     $this->validatorSchema->setOption('filter_extra_fields', true);
 
index ce0018a..64302d5 100644 (file)
@@ -17,8 +17,8 @@ class City extends BaseCity
    *
    * @return string
    */
-  public function __toString()
-  {
-    return (string) $this->getCityName();
-  }
+   public function __toString()
+   {
+     return (string) $this->getCityName();
+   }
 }
index 2efc45a..e1b7a68 100644 (file)
  */
 class Country extends BaseCountry
 {
+  /**
+   * Returns the string representation of this object.
+   *
+   * @return string
+   */
+   public function __toString()
+   {
+     return (string) $this->getCountryName();
+   }
 }
index 0784d22..0789d37 100644 (file)
@@ -7,8 +7,8 @@
  * 
  * @package    mobiads
  * @subpackage model
- * @author     Your name here
- * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ * @author     Gustavo Martin Morcuende
+ * @version
  */
 class Office extends BaseOffice
 {
index 2d0bb0f..92bb1b5 100644 (file)
@@ -19,14 +19,18 @@ class OfficeTable extends Doctrine_Table
 
 
    /**
-    * Returns offices by company id.
+    * Returns offices by company id with sort
     *
     * @return related offices to a company id.
+    * TODO: order by longitude and latitude
     */
-    public function getOfficesByCompanyIdQuery($companyId)
+    public function getOfficesByCompanyIdWithSortQuery($companyId, $sort)
     {
          return $this->createQuery('office')->where('office.company_id = ?', $companyId)
-                                            ->orderBy('office.id');
+                                            ->innerjoin('office.City city')
+                                            ->innerjoin('city.Region region')
+                                            ->innerjoin('region.Country country')
+                                            ->orderBy($sort);
     }
 }
 
index bcd1c67..8d05853 100644 (file)
@@ -7,9 +7,18 @@
  * 
  * @package    mobiads
  * @subpackage model
- * @author     Your name here
- * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ * @author     Gustavo Martin Morcuende
+ * @version
  */
 class Region extends BaseRegion
 {
+  /**
+   * Returns the string representation of this object.
+   *
+   * @return string
+   */
+  public function __toString()
+  {
+    return (string) $this->getRegionName();
+  }
 }
diff --git a/web/sfFormExtraPlugin b/web/sfFormExtraPlugin
new file mode 120000 (symlink)
index 0000000..d198159
--- /dev/null
@@ -0,0 +1 @@
+../plugins/sfFormExtraPlugin/web
\ No newline at end of file