/**
  * @return string
  * @since 1.0.0
  * @throws ExitException|InvalidParamException
  */
 public function actionIndex()
 {
     $searchModel = new PhraseSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if (Yii::$app->request->post('hasEditable')) {
         $post = Yii::$app->request->post();
         $out = Json::encode(['output' => '', 'message' => '']);
         $language_id = Language::getIdByCode($post['editableAttribute']);
         $phrase_id = $post['editableKey'];
         if ($language_id !== 0 && $phrase_id !== 0) {
             $model = PhraseTranslate::findOne(['phrase_id' => $phrase_id, 'language_id' => $language_id]);
             if ($model === null) {
                 $model = new PhraseTranslate();
                 $model->language_id = $language_id;
                 $model->phrase_id = $phrase_id;
             }
             $model->value = $post['Phrase'][$post['editableIndex']][$post['editableAttribute']];
             $model->save();
             $out = Json::encode(['output' => $model->value, 'message' => '']);
         }
         echo $out;
         Yii::$app->end();
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 /**
  * @param $name
  *
  * @return string
  * @since 1.0.2
  */
 public static function newPhrase($name)
 {
     $model = new Phrase();
     $model->name = $name;
     if ($model->save()) {
         $PhraseTranslate = new PhraseTranslate();
         $PhraseTranslate->phrase_id = $model->getPrimaryKey();
         $PhraseTranslate->language_id = Language::getIdByCode(Yii::$app->language);
         $PhraseTranslate->value = 'error: phrase [' . $name . '] not found';
         $PhraseTranslate->save();
     }
     return 'error: phrase [' . $name . '] not found';
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  * @since 1.0.0
  * @throws \yii\base\InvalidParamException
  */
 public function search($params)
 {
     $query = Phrase::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     foreach ($this->_dynamicData as $key => $value) {
         if ($this->{$key} !== '') {
             $language_id = Language::getIdByCode($key);
             if ($language_id !== 0) {
                 $query->join('LEFT JOIN', 'phrase_translate as lang_' . $key, 'lang_' . $key . '.phrase_id = {{%phrase}}.id AND lang_' . $key . '.language_id = ' . $language_id);
                 $query->andFilterWhere(['like', 'lang_' . $key . '.value', $this->{$key}]);
             }
         }
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }