OrganizationsSearch.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\models;
  3. use yii\base\Model;
  4. use yii\data\ActiveDataProvider;
  5. use app\models\Organizations;
  6. /**
  7. * OrganizationsSearch represents the model behind the search form of `app\models\Organizations`.
  8. */
  9. class OrganizationsSearch extends Organizations
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function rules()
  15. {
  16. return [
  17. [['id', 'vat', 'edrpou', 'bank_id', 'person_id', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
  18. [['name', 'short_name', 'address_1', 'address_2', 'address_3', 'comment'], '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 = Organizations::find();
  39. // add conditions that should always apply here
  40. $dataProvider = new ActiveDataProvider([
  41. 'query' => $query,
  42. ]);
  43. $this->load($params);
  44. if (!$this->validate()) {
  45. // uncomment the following line if you do not want to return any records when validation fails
  46. // $query->where('0=1');
  47. return $dataProvider;
  48. }
  49. // grid filtering conditions
  50. $query->andFilterWhere([
  51. 'id' => $this->id,
  52. 'vat' => $this->vat,
  53. 'edrpou' => $this->edrpou,
  54. 'bank_id' => $this->bank_id,
  55. 'person_id' => $this->person_id,
  56. 'created_at' => $this->created_at,
  57. 'updated_at' => $this->updated_at,
  58. 'deleted_at' => $this->deleted_at,
  59. ]);
  60. $query->andFilterWhere(['like', 'name', $this->name])
  61. ->andFilterWhere(['like', 'short_name', $this->short_name])
  62. ->andFilterWhere(['like', 'address_1', $this->address_1])
  63. ->andFilterWhere(['like', 'address_2', $this->address_2])
  64. ->andFilterWhere(['like', 'address_3', $this->address_3])
  65. ->andFilterWhere(['like', 'comment', $this->comment]);
  66. return $dataProvider;
  67. }
  68. }