예제 #1
0
파일: SettingParam.php 프로젝트: hung5s/yap
 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: ');
     }
 }
예제 #2
0
파일: SettingsApi.php 프로젝트: hung5s/yap
 /**
  * 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');
             }
         }
     }
 }
예제 #3
0
 /**
  * Manages all models.
  */
 public function actionCompare()
 {
     //default workflow
     $workflow = $this->getWorkflow();
     $siteId = Yii::app()->request->getParam('site_id', Yii::app()->cmsManager->site['id']);
     $defaultSourceId = $workflow instanceof Workflow ? $workflow->id : null;
     $sourceId = Yii::app()->request->getParam('source_id', $defaultSourceId);
     $targetId = Yii::app()->request->getParam('target_id', null);
     //init setting params for current workflow
     if ($sourceId) {
         $this->api('Xpress.Settings.sync', array('workflowId' => $sourceId));
     }
     if ($targetId) {
         $this->api('Xpress.Settings.sync', array('workflowId' => $targetId));
     }
     $sourceSettings = null;
     $targetSettings = null;
     $targetOptions = array();
     $targetIdOptions = array();
     $targetDiff = array();
     if ($sourceId && $targetId) {
         $model = new SettingParam('search');
         $model->unsetAttributes();
         // Get params of source workflow
         $model->workflow_id = $sourceId;
         $sourceSettings = $model->search();
         $sourceSettings = $sourceSettings->getData();
         $sourceOptions = CHtml::listData($sourceSettings, 'name', 'value');
         // Get params of target workflow
         $model->workflow_id = $targetId;
         $targetSettings = $model->search();
         $targetSettings = $targetSettings->getData();
         $targetOptions = CHtml::listData($targetSettings, 'name', 'value');
         $targetIdOptions = CHtml::listData($targetSettings, 'name', 'id');
         $targetDiff = array_diff_key($targetOptions, $sourceOptions);
         $targetDiff = array_keys($targetDiff);
     }
     $workflows = $this->api('Cms.Workflow.getBySite', array('siteId' => $siteId));
     if (is_array($workflows) && count($workflows)) {
         $workflows = CHtml::listData($workflows, 'id', 'name');
     }
     //Get modules list
     $modules = app()->XService->run('Admin.Module.getAllByWorkflows', array('workflowIds' => array($sourceId, $targetId)));
     $this->render('compare_params', array('workflows' => $workflows, 'sourceId' => $sourceId, 'targetId' => $targetId, 'sourceSettings' => $sourceSettings, 'targetSettings' => $targetSettings, 'targetOptions' => $targetOptions, 'targetIdOptions' => $targetIdOptions, 'targetDiff' => $targetDiff, 'modules' => $modules));
 }
예제 #4
0
 /**
  * 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;
 }