Ejemplo n.º 1
0
 /**
  * Overriding doSave method from lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
  *
  * We are updating the data base in just 1 transaction
  * In case of unsetting longitude or latitude fields you will have to override this method.
  * TODO: create a Doctrine_Record for PostGIS
  */
 protected function doSave($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     if (!$this->getObject()->isNew()) {
         $office = OfficeTable::getInstance()->findOneById($this->getObject()->getId());
     } else {
         $office = new Office();
         $office->company_id = $this->getObject()->getCompanyId();
     }
     $office->city_id = $this->values['city_id'];
     $office->office_street_address = $this->values['office_street_address'];
     $office->office_zip = $this->values['office_zip'];
     //TODO: Symfony sucks
     $this->object = $office;
     $office->save();
     //Get latitude and longitude values. They will be translated to GEOGRAPHIC data.
     foreach ($this->values as $field => $value) {
         if ($field == 'longitude') {
             $longitude = $value;
         }
         if ($field == 'latitude') {
             $latitude = $value;
         }
     }
     //Catch id element. We will use this id to insert the PostGIS value in the right row.
     $rowId = $office->getId();
     //Update PostGIS
     //This connection will throw exception in case of error.
     Doctrine_Manager::connection()->execute("UPDATE office SET office_gps=ST_GeographyFromText('SRID=4326;POINT({$longitude} {$latitude})') WHERE id={$rowId}");
 }
Ejemplo n.º 2
0
 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');
 }