Blame view

common/models/DeliverySearch.php 3.01 KB
e0205ce9   Alexey Boroda   -Delivery model p...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  <?php
      
      namespace common\models;
      
      use yii\base\Model;
      use yii\data\ActiveDataProvider;
      
      /**
       * DeliverySearch represents the model behind the search form about `common\models\Delivery`.
       */
      class DeliverySearch extends Delivery
      {
          
          /**
           * @var string
           */
          public $title;
          
          /**
           * @var string
           */
8af13427   Yarik   For leha commit.
22
          public $parentTitle;
e0205ce9   Alexey Boroda   -Delivery model p...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'id',
                          'parent_id',
                          'value',
                          'sort',
                      ],
                      'integer',
                  ],
                  [
                      [ 'title' ],
                      'safe',
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function scenarios()
          {
              // bypass scenarios() implementation in the parent class
              return Model::scenarios();
          }
          
          /**
           * Creates data provider instance with search query applied
           *
           * @param array $params
           *
           * @return ActiveDataProvider
           */
          public function search($params)
          {
              $query = Delivery::find()
                               ->joinWith('lang')
                               ->joinWith([ 'parent as parent' ]);
              
              // add conditions that should always apply here
              
c70f24ea   Yarik   For Leha commit.
70
71
72
73
74
75
76
77
78
79
80
              $dataProvider = new ActiveDataProvider(
                  [
                      'query' => $query,
                      'sort'  => [
                          'attributes' => [
                              'id',
                              'value',
                              'title' => [
                                  'asc'  => [ 'order_delivery_lang.title' => SORT_ASC ],
                                  'desc' => [ 'order_delivery_lang.title' => SORT_DESC ],
                              ],
e0205ce9   Alexey Boroda   -Delivery model p...
81
82
                          ],
                      ],
c70f24ea   Yarik   For Leha commit.
83
84
                  ]
              );
e0205ce9   Alexey Boroda   -Delivery model p...
85
86
87
              
              $this->load($params);
              
c70f24ea   Yarik   For Leha commit.
88
              if (!$this->validate()) {
e0205ce9   Alexey Boroda   -Delivery model p...
89
90
91
92
93
94
                  // uncomment the following line if you do not want to return any records when validation fails
                  // $query->where('0=1');
                  return $dataProvider;
              }
              
              // grid filtering conditions
c70f24ea   Yarik   For Leha commit.
95
96
97
98
99
100
101
102
103
104
105
106
107
108
              $query->andFilterWhere(
                  [
                      'id'    => $this->id,
                      'value' => $this->value,
                      'sort'  => $this->sort,
                  ]
              )
                    ->andFilterWhere(
                        [
                            'like',
                            'order_delivery_lang.title',
                            $this->title,
                        ]
                    );
e0205ce9   Alexey Boroda   -Delivery model p...
109
110
111
112
              
              return $dataProvider;
          }
      }