public function save()
 {
     $model = Configuration::findOne($this->id);
     foreach ($this as $key => $value) {
         $model->{$key} = $value;
     }
     return $model->save();
 }
示例#2
0
 private static function getConfig()
 {
     if (\Yii::$app->cache->exists('configuration') && !\Yii::$app->request->get('disableConfigCache')) {
         return \Yii::$app->cache->get('configuration');
     }
     if (!self::$configuration) {
         self::$configuration = ArrayHelper::map(Configuration::find()->select(['key', 'value'])->asArray()->all(), 'key', 'value');
         \Yii::$app->cache->set('configuration', self::$configuration, 600);
     }
     return self::$configuration;
 }
示例#3
0
 public function edit($paramsForThisPage)
 {
     $params = Configuration::find()->where(['in', 'key', $paramsForThisPage])->all();
     $model = new ConfigurationModel();
     $model->loadFields($params);
     if (\Yii::$app->request->post('ConfigurationFieldModel')) {
         $model->load(\Yii::$app->request->post());
         if ($model->save()) {
             \Yii::$app->session->setFlash('success', 'Системные параметры успешно отредактированы!');
         } else {
             \Yii::$app->session->setFlash('error', 'Произошла ошибка при сохранении системных параметров!');
         }
     }
     return $this->render('edit', ['model' => $model]);
 }
示例#4
0
 /**
  * @param $key
  *
  * @return bool
  */
 public function set($key)
 {
     /** @var Configuration $config */
     $config = Configuration::find()->select(['id', 'value', 'type'])->with(['translations'])->where(['id' => $key, 'published' => 1])->asArray()->one();
     if (null === $config) {
         return false;
     }
     $this->configs[$key]['type'] = (int) $config['type'];
     $this->configs[$key][$this->defaultLanguage] = $config['value'];
     foreach ($config['translations'] as $item) {
         $this->configs[$key][$item['language']] = $item['value'];
     }
     return true;
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getModel()
 {
     return $this->hasOne(Configuration::className(), ['id' => 'model_id']);
 }
示例#6
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $this->setScenario($this->getTypeScenario());
         return true;
     }
     return false;
 }