I18nMessageSearch.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace common\modules\i18n\models\search;
  3. use common\modules\i18n\models\I18nMessage;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. /**
  7. * I18nMessageSearch represents the model behind the search form about `common\modules\i18n\models\I18nMessage`.
  8. */
  9. class I18nMessageSearch extends I18nMessage
  10. {
  11. /**
  12. * @inheritdoc
  13. */
  14. public function rules()
  15. {
  16. return [
  17. [['id'], 'integer'],
  18. [['language', 'translation', 'sourceMessage', 'category'], 'safe'],
  19. ];
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public function scenarios()
  25. {
  26. // bypass scenarios() implementation in the parent class
  27. return Model::scenarios();
  28. }
  29. /**
  30. * Creates data provider instance with search query applied
  31. *
  32. * @param array $params
  33. *
  34. * @return ActiveDataProvider
  35. */
  36. public function search($params)
  37. {
  38. $query = I18nMessage::find()->with('sourceMessageModel')->joinWith('sourceMessageModel');
  39. $dataProvider = new ActiveDataProvider([
  40. 'query' => $query
  41. ]);
  42. if (!($this->load($params) && $this->validate())) {
  43. return $dataProvider;
  44. }
  45. $query->andFilterWhere([
  46. '{{%i18n_source_message}}.id' => $this->id
  47. ]);
  48. $query->andFilterWhere(['like', '{{%i18n_message}}.language', $this->language])
  49. ->andFilterWhere(['like', '{{%i18n_message}}.translation', $this->translation])
  50. ->andFilterWhere(['like', '{{%i18n_source_message}}.message', $this->sourceMessage])
  51. ->andFilterWhere(['like', '{{%i18n_source_message}}.category', $this->category]);
  52. return $dataProvider;
  53. }
  54. }