Exemple #1
0
 /**
  * @return string
  */
 public function actionGetForm()
 {
     $post = \Yii::$app->request->post();
     $id = $post[(new Configuration())->formName()]['id'];
     $model = Configuration::findOne($id);
     if (!$model) {
         $model = new Configuration();
     }
     $model->load(\Yii::$app->request->post());
     $model->value = null;
     /** @var ConfigurationTranslation[] $translationModels */
     $translationModels = $model->getTranslationModels();
     foreach ($translationModels as $languageModel) {
         $languageModel->value = null;
     }
     //Save model for setting actual scenario in translation model
     if (!$model->isNewRecord) {
         $model->save(false);
     }
     return Json::encode(['replaces' => [['what' => '.menu-form', 'data' => $this->renderAjax('//templates/_form', ['model' => $model, 'action' => \Yii::$app->request->post('action', '')])]]]);
 }
Exemple #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Configuration::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     //if (!$this->validate()) {
     // uncomment the following line if you do not want to any records when validation fails
     // $query->where('0=1');
     //return $dataProvider;
     //}
     $query->andFilterWhere(['type' => $this->type, 'preload' => $this->preload, 'published' => $this->published]);
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemple #3
0
 /**
  * @return Configuration[]
  */
 public function getModels()
 {
     if (null === $this->models) {
         $models = [];
         foreach ($this->getKeys() as $key) {
             $model = Configuration::findOne($key);
             if (!$model) {
                 // create model if it is not created yet
                 $model = new Configuration();
                 $model->id = $key;
                 $model->type = Configuration::TYPE_STRING;
                 $model->preload = 0;
                 $model->published = 1;
             }
             $models[$key] = $model;
         }
         $this->models = $models;
     }
     return $this->models;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getModel()
 {
     return $this->hasOne(Configuration::className(), ['id' => 'model_id']);
 }