Пример #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}");
 }