/** * Actions to take before validating the owner. * @param CModelEvent $event */ public function beforeValidate($event) { parent::beforeValidate($event); if ($this->owner->hasAttribute($this->statusAttribute) && !isset($this->owner->{$this->statusAttribute})) { $this->owner->{$this->statusAttribute} = $this->defaultStatus; } }
/** * @param CModelEvent $event */ public function beforeValidate($event) { if (method_exists($this->getOwner(), 'setDefaultAttributes')) { $this->getOwner()->setDefaultAttributes(); } // will the following will be called twice? return parent::beforeValidate($event); }
public function beforeValidate($event) { parent::beforeValidate($event); foreach ($this->fields as $field) { if (!is_a($this->owner->{$field}, 'CUploadedFile')) { $this->owner->{$field} = CUploadedFile::getInstance($this->owner->model(), $field); } } return true; }
public function beforeValidate($event) { $owner = $this->getOwner(); //salt if ($owner->getIsNewRecord() && $owner->hasAttribute('salt')) { $owner->salt = Common::generateSalt(); } if ($owner->getScenario() === Users::SCENARIO_CHANGE_PASSWORD) { $owner->currentPassword = $owner->salt . md5($owner->currentPassword); } return parent::beforeValidate($event); }
public function beforeValidate($event) { if (isset(Yii::app()->user)) { $availableColumns = array_keys($this->owner->tableSchema->columns); if ($this->owner->isNewRecord && empty($this->owner->{$this->createdByColumn})) { if (in_array($this->createdByColumn, $availableColumns)) { $this->owner->{$this->createdByColumn} = Yii::app()->user->id; } } if (empty($this->owner->{$this->updatedByColumn})) { if (in_array($this->updatedByColumn, $availableColumns)) { $this->owner->{$this->updatedByColumn} = Yii::app()->user->id; } } } return parent::beforeValidate($event); }
public function beforeValidate($event) { $setAttributes = array(); foreach ($this->attributes as $attribute => $format) { if (!$this->owner->hasAttribute($attribute)) { continue; } $value = $this->owner->getAttribute($attribute); if (empty($value) && $this->autoFill === false) { continue; } if (empty($value)) { $value = time(); } else { if (!is_numeric($value)) { $value = strtotime($value); } } $setAttributes[$attribute] = $value; } $this->owner->setAttributes($setAttributes); return parent::beforeValidate($event); }
public function beforeDelete($event) { UserFollow::model()->deleteAllByAttributes(array('object_model' => get_class($this->getOwner()), 'object_id' => $this->getOwner()->getPrimaryKey())); return parent::beforeValidate($event); }
/** * Invoked before the model is validated. * Validates the password first * @param CModelEvent $event the raised event */ public function beforeValidate($event) { $password = $event->sender->{$this->passwordAttribute}; $strategy = $this->getStrategy(); if ($strategy !== false && $password != $this->_hashedPassword && $password != "") { $strategy->attributes = array($this->passwordAttribute); $strategy->validate($event->sender); } return parent::beforeValidate($event); }
/** * @param CModelEvent $event */ public function beforeValidate($event) { $this->getOwner()->setDefaultAttributes(); return parent::beforeValidate($event); }