public function beforeValidate($options = []) { $ret = parent::beforeValidate($options); if (isset($this->data['value'])) { $this->data['value'] = (double) $this->data['value']; } if (isset($this->data['code'])) { $this->data['code'] = mb_strtoupper($this->data['code']); $code = $this->data['code']; # intelligent autocomplete if (isset($this->data['name']) && empty($this->data['name'])) { if (!isset($this->CurrencyLib)) { //App::import('Component', 'Data.Currency'); $this->CurrencyLib = new CurrencyLib(); } $this->data['name'] = $this->CurrencyLib->getName($code, ''); } if (isset($this->data['value']) && $this->data['value'] == 0) { if (!isset($this->CurrencyLib)) { //App::import('Component', 'Data.Currency'); $this->CurrencyLib = new CurrencyComponent(); } $currencies = $this->availableCurrencies(); if (array_key_exists($code, $currencies)) { $this->data['value'] = $currencies[$code]; } } } return $ret; }
/** * District::beforeValidate() * * @param array $options * @return bool Success */ public function beforeValidate($options = []) { parent::beforeValidate($options); if (!empty($this->data['name']) && !empty($this->data['city_id'])) { $city = $this->City->field('name', ['id' => $this->data['city_id']]); $this->data['address'] = $this->data['name'] . ', ' . $city; } return true; }
public function beforeValidate($options = []) { parent::beforeValidate($options); # add country name for geocoder if (!empty($this->data['country_id'])) { $this->data['country'] = $this->Country->field('name', ['id' => $this->data['country_id']]); } if (!empty($this->data['postal_code'])) { unset($this->validate['city']['notBlank']); } elseif (!empty($this->data['city'])) { unset($this->validate['postal_code']['notBlank']); } if (isset($this->data['foreign_id']) && empty($this->data['foreign_id'])) { $this->data['foreign_id'] = 0; } # prevents NULL inserts into DB if (isset($this->data['lat'])) { $this->data['lat'] = number_format((double) $this->data['lat'], 6); } if (isset($this->data['lng'])) { $this->data['lng'] = number_format((double) $this->data['lng'], 6); } return true; }