Ejemplo n.º 1
0
 /**
  * Default index search method
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Message::find();
     $query->joinWith('source');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->getSort()->attributes['sourceMessage'] = ['asc' => ['source.message' => SORT_ASC], 'desc' => ['source.message' => SORT_DESC]];
     $dataProvider->getSort()->attributes['sourceCategory'] = ['asc' => ['source.category' => SORT_ASC], 'desc' => ['source.category' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     if ($this->translation) {
         $t = addslashes($this->translation);
         $query->where("translation like '%{$t}%'");
     }
     if ($this->translationUpdate === 'is null') {
         $query->where('translation is null');
     }
     if ($this->translationUpdate === 'is not null') {
         $query->where('translation is not null');
     }
     if ($this->translation) {
         $query->andWhere(['like', 'translation', '%' . $this->translation . '%', false]);
     }
     if ($this->sourceMessage) {
         $query->andFilterWhere(['like', 'source.message', $this->sourceMessage]);
     }
     if ($this->language) {
         $query->andWhere(['language' => $this->language]);
     }
     if ($this->sourceCategory) {
         $query->andFilterWhere(['like', 'source.category', $this->sourceCategory]);
     }
     return $dataProvider;
 }
 public function down()
 {
     $this->dropForeignKey('fk_message_source_message', Message::tableName());
     $this->dropTable(Message::tableName());
     $this->dropTable(SourceMessage::tableName());
     return true;
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMessage()
 {
     return $this->hasOne(Message::className(), ['id' => 'id'])->from(['message' => Message::tableName()]);
 }
 /**
  * Fast translation update.
  *
  * @param int $id
  * @return string
  */
 public function actionFastUpdate($id)
 {
     Message::updateAll(['translation' => Yii::$app->request->post('translation')], ['id' => $id, 'language' => Yii::$app->request->post('language')]);
 }