public function beforeSave() { if (empty($this->assignedTo)) { $this->assignedTo = Yii::app()->user->getName(); } $this->updatedBy = Yii::app()->user->getName(); return parent::beforeSave(); }
public function afterSave() { parent::afterSave(); $event = new Events(); $event->visibility = 1; $event->associationType = 'TopicRepies'; $event->associationId = $this->id; $event->user = Yii::app()->user->getName(); $event->type = 'topic_reply'; $event->save(); }
public function insert($attributes = null) { $succeeded = parent::insert($attributes); // Alter and save the nameId field: if ($succeeded && self::$autoPopulateFields) { $this->updateNameId(true); if ($this->hasEventHandler('onAfterInsert')) { $this->onAfterInsert(new CEvent($this)); } } return $succeeded; }
protected function beforeDelete() { if (!empty($this->children)) { foreach ($this->children as $child) { $child->delete(); } } return parent::beforeDelete(); }
/** * Validates the JSON data in $flow. * Sets createDate and lastUpdated. * @return boolean whether or not to proceed to validation */ public function beforeValidate() { $flowData = CJSON::decode($this->flow); if ($flowData === false) { $this->addError('flow', Yii::t('studio', 'Flow configuration data appears to be ' . 'corrupt.')); return false; } if (isset($flowData['trigger']['type'])) { $this->triggerType = $flowData['trigger']['type']; if (isset($flowData['trigger']['modelClass'])) { $this->modelClass = $flowData['trigger']['modelClass']; } } else { // $this->addError('flow',Yii::t('studio','You must configure a trigger event.')); } if (!isset($flowData['items']) || empty($flowData['items'])) { $this->addError('flow', Yii::t('studio', 'There must be at least one action in the ' . 'flow.')); } $this->lastUpdated = time(); if ($this->isNewRecord) { $this->createDate = $this->lastUpdated; } return parent::beforeValidate(); }
/** * Add duplicate validation */ public function beforeValidate() { $valid = parent::beforeValidate(); if ($valid) { if ($this->hasDuplicates()) { $this->addError('secondType', Yii::t('app', 'Relationship already exists')); $this->addErrors(array_map(function () { return null; }, array_flip(array('firstType', 'firstId', 'secondId')))); $valid = false; } } return $valid; }
/** * Save default layouts */ public function afterSave() { parent::afterSave(); foreach ($this->_widgetLayouts as $name => $settings) { if ($settings) { $settings->save(); } } }
/** * Saves attributes on initial model lookup */ public function afterFind() { $this->_oldAttributes = $this->getAttributes(); parent::afterFind(); }
public function __construct($scenario = 'insert', $tableName) { $this->_tableName = $tableName; return parent::__construct($scenario); }