public function beforeSave() { if (empty($this->assignedTo)) { $this->assignedTo = Yii::app()->user->getName(); } $this->updatedBy = Yii::app()->user->getName(); return parent::beforeSave(); }
/** * Remembers if this was a new record before saving. * @returns the answer from {@link CActiveRecord::beforeSave()} */ public function beforeSave() { if ($this->asa('ContactsNameBehavior')) { $this->asa('ContactsNameBehavior')->setName(); } $this->_runAfterCreate = $this->getIsNewRecord(); if (!$this->_runAfterCreate) { $this->updateNameId(); } else { // Safeguard against duplicate entries (violating unique constraint // on the nameId column): set uniqueId before submitting to // some unique value, and let it be updated to a proper uniqueId // value after saving. This is just in case the nameId update after // insertion fails, which is easily corrected. if ($this->hasAttribute('nameId')) { $this->nameId = uniqid(); } } return parent::beforeSave(); }
protected function beforeSave() { if (empty($this->timestamp)) { $this->timestamp = time(); } $this->lastUpdated = time(); if (!empty($this->user) && $this->isNewRecord) { $eventsData = X2Model::model('EventsData')->findByAttributes(array('type' => $this->type, 'user' => $this->user)); if (isset($eventsData)) { $eventsData->count++; } else { $eventsData = new EventsData(); $eventsData->user = $this->user; $eventsData->type = $this->type; $eventsData->count = 1; } $eventsData->save(); } if ($this->type == 'record_deleted') { $this->text = preg_replace('/(<script(.*?)>|<\\/script>)/', '', $this->text); } return parent::beforeSave(); }