Ejemplo n.º 1
0
 public function beforeSave($options = [])
 {
     parent::beforeSave($options);
     if (isset($this->data['ext'])) {
         $this->data['ext'] = mb_strtolower($this->data['ext']);
     }
     if (isset($this->data['name'])) {
         $this->data['name'] = ucwords($this->data['name']);
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Location::beforeSave()
  *
  * @param mixed $options
  * @return bool Success
  */
 public function beforeSave($options = [])
 {
     parent::beforeSave($options);
     $additional = ['locality', 'sublocality'];
     foreach ($additional as $field) {
         if (!empty($this->data['geocoder_result'][$field])) {
             $this->data[$field] = $this->data['geocoder_result'][$field];
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 public function beforeSave($options = [])
 {
     parent::beforeSave($options);
     if (!empty($this->data['formatted_address']) && !empty($this->data['geocoder_result'])) {
         # fix city/plz?
         if (isset($this->data['postal_code']) && empty($this->data['postal_code'])) {
             $this->data['postal_code'] = $this->data['geocoder_result']['postal_code'];
         }
         if (isset($this->data['city']) && empty($this->data['city'])) {
             # use sublocality too?
             $this->data['city'] = $this->data['geocoder_result']['locality'];
         }
         if (isset($this->data['postal_code']) && empty($this->data['postal_code']) && !empty($this->data['geocoder_result']['postal_code'])) {
             # use postal_code
             $this->data['postal_code'] = $this->data['geocoder_result']['postal_code'];
         }
         # ensure province is correct
         if ($this->config['CountryProvince']) {
             if (isset($this->data['country_province_id']) && !empty($this->data['country_province_id']) && !empty($this->data['geocoder_result']['country_province_code'])) {
                 //$this->data['country_province_id']
                 $countryProvince = $this->Country->CountryProvince->find('first', ['conditions' => ['CountryProvince.id' => $this->data['country_province_id']]]);
                 if (!empty($countryProvince) && strlen($countryProvince['CountryProvince']['abbr']) === strlen($this->data['geocoder_result']['country_province_code']) && $countryProvince['CountryProvince']['abbr'] != $this->data['geocoder_result']['country_province_code']) {
                     $this->invalidate('country_province_id', 'Als Bundesland wurde für diese Adresse \'' . h($this->data['geocoder_result']['country_province']) . '\' erwartet - du hast aber \'' . h($countryProvince['CountryProvince']['name']) . '\' angegeben. Liegt denn deine Adresse tatsächlich in einem anderen Bundesland? Dann gebe bitte die genaue PLZ und Ort an, damit das Bundesland dazu auch korrekt identifiziert werden kann.');
                     return false;
                 }
                 # enter new id
             } elseif (isset($this->data['country_province_id']) && !empty($this->data['geocoder_result']['country_province_code'])) {
                 $countryProvince = $this->Country->CountryProvince->find('first', ['conditions' => ['OR' => ['CountryProvince.abbr' => $this->data['geocoder_result']['country_province_code'], 'CountryProvince.name' => $this->data['geocoder_result']['country_province']]]]);
                 if (!empty($countryProvince)) {
                     $this->data['country_province_id'] = $countryProvince['CountryProvince']['id'];
                 }
             }
         }
         # enter new id
         if (isset($this->data['country_id']) && empty($this->data['country_id']) && !empty($this->data['geocoder_result']['country_code'])) {
             $country = $this->Country->find('first', ['conditions' => ['Country.iso2' => $this->data['geocoder_result']['country_code']]]);
             if (!empty($country)) {
                 $this->data['country_id'] = $country['Country']['id'];
             }
         }
     }
     if (isset($this->data['geocoder_result']) && !$this->Behaviors->loaded('Jsonable')) {
         unset($this->data['geocoder_result']);
     }
     return true;
 }