Пример #1
0
 /**
  * @inheritdoc
  */
 public function search($params)
 {
     $query = Message::find()->joinWith(['sourceMessage' => function ($query) {
         $query->from(['sourceMessage' => SourceMessage::tableName()]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->language) {
         $query->filterWhere(['language' => $this->language]);
     }
     if ($this->prefix) {
         $query->andFilterWhere(['or', ['like', 'sourceMessage.category', $this->prefix . '.'], ['like', 'sourceMessage.category', $this->prefix . '/']]);
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'translation', $this->translation])->andFilterWhere(['like', 'sourceMessage.message', $this->source]);
     if ($this->category) {
         if ($this->prefix) {
             $query->andFilterWhere(['or', ['like', 'sourceMessage.category', $this->prefix . '.' . $this->category], ['like', 'sourceMessage.category', $this->prefix . '/' . $this->category]]);
         } else {
             $query->andFilterWhere(['like', 'sourceMessage.category', $this->category]);
         }
     }
     if ($this->translationStatus === static::MESSAGE_TRANSLATED_YES) {
         $query->andWhere('translation IS NOT NULL AND translation <> ""');
     } elseif ($this->translationStatus === static::MESSAGE_TRANSLATED_NO) {
         $query->andWhere('translation IS NULL OR translation = ""');
     }
     return $dataProvider;
 }
 public function translated()
 {
     $messageTableName = Message::tableName();
     $query = Message::find()->select($messageTableName . '.id');
     $i = 0;
     foreach (Yii::$app->getI18n()->languages as $language) {
         if ($i === 0) {
             $query->andWhere($messageTableName . '.language = :language and ' . $messageTableName . '.translation is not null', [':language' => $language]);
         } else {
             $query->innerJoin($messageTableName . ' t' . $i, 't' . $i . '.id = ' . $messageTableName . '.id and t' . $i . '.language = :language and t' . $i . '.translation is not null', [':language' => $language]);
         }
         $i++;
     }
     $ids = $query->indexBy('id')->all();
     $this->andWhere(['in', 'id', array_keys($ids)]);
     return $this;
 }