public function validName($attribute, $params) { if ($this->id > 0) { $temp = SettingParam::model()->findByPk($this->id); if ($temp->name == $this->name) { return; } } $modules = $this->getModules(); $valid = true; $module = ''; foreach ($modules as $module) { if (empty($module) || in_array($module, array('Xpress', 'Admin'))) { continue; } if (stripos($this->name, $module . '_') === 0) { $valid = false; break; } } if ($valid == false) { $this->addError('name', 'Invalid name. The name can not include module id "' . $module . '_" in prefix: '); } }
/** * sync Global Settings and current workflow Settings * * @param int $id */ public function actionSync($workflowId) { $current = SettingParam::model()->findAll('workflow_id=:workflow_id', array(':workflow_id' => $workflowId)); $criteria = new CDbCriteria(); $criteria->addCondition('workflow_id = 0 OR workflow_id IS NULL'); if (count($current)) { $current = CHtml::listData($current, 'name', 'name'); $criteria->addNotInCondition('name', $current); } $new = SettingParam::model()->findAll($criteria); $this->result = count($new); if ($this->result) { /** @var SettingParam $model */ foreach ($new as $model) { $setting = new SettingParam(); $setting->attributes = $model->attributes; $setting->workflow_id = $workflowId; if (!$setting->save(false)) { Yii::log(CVarDumper::dumpAsString($setting->getErrors()), CLogger::LEVEL_ERROR, 'Xpress.Api.Settings'); } } } }
public function actionToggleVisible($id) { /** @var SettingParam $model */ $model = SettingParam::model()->findByPk($id); if (is_object($model)) { $model->saveAttributes(array('visible' => !CPropertyValue::ensureBoolean($model->visible))); } }
/** * copy params value from source to target * * @param array $attrs */ public function actionSync($sourceId, $targetId = 0, $targetWorkflowId = 0) { Yii::import('Cms.models.*'); //find source $source = SettingParam::model()->findByPk($sourceId); $target = null; if ($targetId) { $target = SettingParam::model()->findByPk($targetId); if (is_object($target)) { $targetWorkflowId = $target->workflow_id; } } //find other workflows if (is_object($source) && $targetWorkflowId) { return $this->result = $this->actionSyncValue($source->attributes, $targetWorkflowId); } return $this->result = null; }