Пример #1
0
 public function beforeSave()
 {
     if (empty($this->assignedTo)) {
         $this->assignedTo = Yii::app()->user->getName();
     }
     $this->updatedBy = Yii::app()->user->getName();
     return parent::beforeSave();
 }
Пример #2
0
 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();
 }
Пример #3
0
 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;
 }
Пример #4
0
 protected function beforeDelete()
 {
     if (!empty($this->children)) {
         foreach ($this->children as $child) {
             $child->delete();
         }
     }
     return parent::beforeDelete();
 }
Пример #5
0
 /**
  * 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();
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * Save default layouts 
  */
 public function afterSave()
 {
     parent::afterSave();
     foreach ($this->_widgetLayouts as $name => $settings) {
         if ($settings) {
             $settings->save();
         }
     }
 }
Пример #8
0
 /**
  * Saves attributes on initial model lookup
  */
 public function afterFind()
 {
     $this->_oldAttributes = $this->getAttributes();
     parent::afterFind();
 }
Пример #9
0
 public function __construct($scenario = 'insert', $tableName)
 {
     $this->_tableName = $tableName;
     return parent::__construct($scenario);
 }