/** * Lists all models. */ public function actionIndex() { $url = parse_url(app()->request->getHostInfo(), PHP_URL_HOST); $currentWorkflow = $this->api('Cms.Workflow.getByUrl', array('url' => $url)); $workflowId = 0; $workflows = array(); $workflow = $this->getWorkflow(); if (is_object($workflow)) { $workflowId = $workflow->id; } else { $workflow = $currentWorkflow; //get workflow by url if (is_object($currentWorkflow)) { $workflowId = $currentWorkflow->id; } } //find all workflows if (is_object($workflow)) { //init setting params for current workflow $this->api('Xpress.Settings.sync', array('workflowId' => $workflow->id)); $workflows = Workflow::model()->findAll('site_id=:site_id', array(':site_id' => $workflow->site_id)); if (count($workflows)) { $workflows = CHtml::listData($workflows, 'id', 'name'); } } $model = new SettingParam('search'); $model->unsetAttributes(); // clear any default values if (isset($_POST['SettingParam'])) { $model->attributes = $_POST['SettingParam']; } elseif (isset($_GET['module'])) { $model->module = $_GET['module']; if (in_array($model->module, array('Xpress', 'Admin'))) { $model->module = 'System'; } } else { $model->module = 'System'; } $model->visible = 1; $model->workflow_id = $workflowId; $dataProvider = $model->search(); $dataProvider->pagination = false; $modules = $model->getModules(); $data = $dataProvider->getData(); //override setting use user_setting $customizable = array(); if (count($data)) { foreach ($data as $i => $row) { /** var CActiveRecord $row */ if ($row->customizable) { //load data from user_setting $custom = UserSetting::model()->findByAttributes(array('param_name' => $row->name, 'user_id' => Yii::app()->user->id)); if (is_object($custom)) { $data[$i]->value = $custom->value; } else { $custom = new UserSetting(); $custom->user_id = Yii::app()->user->id; $custom->param_name = $row->name; } $customizable[] = $custom; } } } $paramForm = $this->createWidget('Admin.components.ParamForm', array('params' => $data, 'config' => null)); //TODO: load module param definitions into $config // save new values if (Yii::app()->request->IsPostRequest) { //save User Settings to user_setting if (is_array($customizable) && count($customizable)) { foreach ($customizable as $custom) { if ($custom instanceof UserSetting && isset($_POST[$custom->param_name])) { $custom->value = $_POST[$custom->param_name]; if (!$custom->save()) { Yii::log(CVarDumper::dumpAsString($custom->getErrors()), CLogger::LEVEL_ERROR, 'Admin.Setting'); } //force not save global setting unset($_POST[$custom->param_name]); } } } $paramForm->saveParams($_POST, ParamForm::TO_SETTING_TABLE); //update Settings Class if ($currentWorkflow->id == $workflowId && isset($_POST['SettingParam'], $_POST['SettingParam']['module'])) { $module = $_POST['SettingParam']['module']; if ($module == 'module_system') { $module = ''; } $this->api('Xpress.Settings.db2php', array('module' => $module)); } //update parameters to global and other workflows foreach ($paramForm->params as $param) { if (isset($_POST['sync_global'])) { $this->api('Xpress.SettingParam.syncValue', array('attrs' => $param->attributes)); //update cache file global $this->api('Xpress.Settings.db2php', array('module' => $param->module, 'path' => cachePath(true))); } if (isset($_POST['sync_other'])) { $this->api('Xpress.SettingParam.syncValueToOther', array('attrs' => $param->attributes)); } } //TODO: need fix validate in ParamForm //errorHandler()->getErrorMessages(); } $this->render('index', array('modules' => $modules, 'module' => $model->module, 'form' => $paramForm, 'workflowId' => $workflowId, 'workflows' => $workflows)); }