/** * Evaluates the value of the user. * The return result of this method will be assigned to the current attribute(s). * @param Event $event * @return mixed the value of the user. */ protected function getValue($event) { $attribute = $this->districtAttribute; $value = $this->owner->{$attribute}; $parentAttribute = $this->cityAttribute; $parent_id = $this->owner->{$parentAttribute}; $parent_valid = $parent_id > 0; if (is_numeric($value)) { return $value; } else { if (empty($value) or $parent_valid == FALSE) { return NULL; } else { $model = new RgnDistrict(['name' => $value, 'city_id' => $parent_id, 'status' => RgnDistrict::STATUS_ACTIVE]); return $model->save(FALSE) ? $model->id : 0; } } }