/** * 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; }