public function beforeValidation() { $validation = new Validation(); $validation->add('password', new Confirmation(array('message' => 'Password doesn\'t match confirmation', 'with' => 'retype_password'))); $validation->validate(['password' => $this->password, 'retype_password' => $this->retype_password]); $this->addMessages($validation->getMessages()); if (!empty($this->getMessages())) { return false; } if ($this->reg_date === null) { $this->reg_date = $this->timeService()->currentDateTime(); } if ($this->role === null) { $this->role = self::ROLE_USER; } if ($this->status === null) { $this->status = self::STATUS_NEW; } if ($this->rating === null) { $this->rating = (int) $this->rating; } if ($this->password !== null) { $this->password_hash = $this->createPasswordHash(); } return parent::beforeValidation(); }
public function beforeValidation() { if ($this->user_id === null) { $this->user_id = $this->user()->getID(); } if ($this->type === null) { $this->type = self::TYPE_NOTE; } if ($this->date === null) { $this->date = $this->timeService()->currentDateTime(); } if ($this->position === null) { $this->position = 0; } return parent::beforeValidation(); }
/** * Allows to query the first record that match the specified conditions * * @param mixed $parameters * @return LeftMenu */ public static function findFirst($parameters = null) { return parent::findFirst($parameters); }
public function beforeSave($insert) { $dateTime = Yii::$app->timeService->getCurrentDateTime(); if (!$this->userId) { $this->userId = Yii::$app->user->id; } if (!$this->createDate) { $this->createDate = $dateTime; } if (!$this->isNewRecord && !$this->lastEditTime) { $this->lastEditTime = $dateTime; } return parent::beforeSave($insert); }