Blame view

common/modules/comment/models/CommentModelSearch.php 6.98 KB
d8c1a2e0   Yarik   Big commit artbox
1
2
3
4
  <?php
      
      namespace common\modules\comment\models;
      
d8c1a2e0   Yarik   Big commit artbox
5
6
      use yii\base\Model;
      use yii\data\ActiveDataProvider;
d8c1a2e0   Yarik   Big commit artbox
7
8
9
10
11
12
13
14
      
      /**
       * CommentModelSearch represents the model behind the search form about
       * `common\modules\comment\models\CommentModel`.
       */
      class CommentModelSearch extends CommentModel
      {
          
8af13427   Yarik   For leha commit.
15
          public $ratingValue;
d8c1a2e0   Yarik   Big commit artbox
16
          
8af13427   Yarik   For leha commit.
17
          public $childrenCount;
d8c1a2e0   Yarik   Big commit artbox
18
19
20
21
22
23
24
25
26
27
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'artbox_comment_id',
8af13427   Yarik   For leha commit.
28
29
30
                          'created_at',
                          'updated_at',
                          'deleted_at',
d8c1a2e0   Yarik   Big commit artbox
31
32
33
34
35
36
37
38
39
                          'status',
                          'artbox_comment_pid',
                          'related_id',
                          'entity_id',
                      ],
                      'integer',
                  ],
                  [
                      [
8af13427   Yarik   For leha commit.
40
                          'childrenCount',
d8c1a2e0   Yarik   Big commit artbox
41
42
43
44
45
46
                      ],
                      'integer',
                      'min' => 0,
                  ],
                  [
                      [
8af13427   Yarik   For leha commit.
47
                          'ratingValue',
d8c1a2e0   Yarik   Big commit artbox
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
                      ],
                      'number',
                      'min' => 1,
                      'max' => 5,
                  ],
                  [
                      [
                          'user_id',
                          'text',
                          'username',
                          'email',
                          'ip',
                          'entity',
                          'info',
                      ],
                      'safe',
                  ],
              ];
          }
          
          public function attributeLabels()
          {
8af13427   Yarik   For leha commit.
70
71
72
73
74
75
76
              return array_merge(
                  parent::attributeLabels(),
                  [
                      'ratingValue'   => 'Рейтинг',
                      'childrenCount' => 'Количество ответов',
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
          }
          
          /**
           * @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 = CommentModel::find()
8af13427   Yarik   For leha commit.
98
99
100
101
102
103
                                   ->joinWith(
                                       [
                                           'rating',
                                           'user',
                                       ]
                                   );
d8c1a2e0   Yarik   Big commit artbox
104
105
106
              
              // add conditions that should always apply here
              
8af13427   Yarik   For leha commit.
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
              $dataProvider = new ActiveDataProvider(
                  [
                      'query' => $query,
                      'sort'  => [
                          'attributes'   => [
                              'ratingValue' => [
                                  'asc'  => [ 'artbox_comment_rating.value' => SORT_ASC ],
                                  'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ],
                              ],
                              'artbox_comment_id',
                              'date_add',
                              'text',
                              'user_id',
                              'status',
                              'entity',
                              'entity_id',
                          ],
                          'defaultOrder' => [
                              'created_at' => SORT_DESC,
d8c1a2e0   Yarik   Big commit artbox
126
                          ],
d8c1a2e0   Yarik   Big commit artbox
127
                      ],
8af13427   Yarik   For leha commit.
128
129
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
130
131
132
              
              $this->load($params);
              
8af13427   Yarik   For leha commit.
133
              if (!$this->validate()) {
d8c1a2e0   Yarik   Big commit artbox
134
135
136
137
138
139
                  // 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
8af13427   Yarik   For leha commit.
140
141
142
143
144
145
146
147
148
149
150
151
              $query->andFilterWhere(
                  [
                      'artbox_comment_id'     => $this->artbox_comment_id,
                      'created_at'            => $this->created_at,
                      'updated_at'            => $this->updated_at,
                      'deleted_at'            => $this->deleted_at,
                      'artbox_comment.status' => $this->status,
                      'artbox_comment_pid'    => $this->artbox_comment_pid,
                      'related_id'            => $this->related_id,
                      'entity_id'             => $this->entity_id,
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
152
              
8af13427   Yarik   For leha commit.
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
              $query->andFilterWhere(
                  [
                      'like',
                      'text',
                      $this->text,
                  ]
              )
                    ->andFilterWhere(
                        [
                            'like',
                            'username',
                            $this->username,
                        ]
                    )
                    ->andFilterWhere(
                        [
                            'like',
                            'email',
                            $this->email,
                        ]
                    )
                    ->andFilterWhere(
                        [
                            'like',
                            'ip',
                            $this->ip,
                        ]
                    )
                    ->andFilterWhere(
                        [
                            'like',
                            'entity',
                            $this->entity,
                        ]
                    )
                    ->andFilterWhere(
                        [
                            'like',
                            'info',
                            $this->info,
                        ]
                    )
                    ->andFilterWhere(
                        [
                            'artbox_comment_rating.value' => $this->ratingValue,
                        ]
                    );
d8c1a2e0   Yarik   Big commit artbox
200
              
8af13427   Yarik   For leha commit.
201
202
              if (!empty( $this->user_id )) {
                  $query->andWhere(
d8c1a2e0   Yarik   Big commit artbox
203
                      [
8af13427   Yarik   For leha commit.
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
                          'or',
                          [ 'artbox_comment.user_id' => (int) $this->user_id ],
                          [
                              'like',
                              'user.username',
                              $this->user_id,
                          ],
                          [
                              'like',
                              'artbox_comment.username',
                              $this->user_id,
                          ],
                          [
                              'like',
                              'artbox_comment.email',
                              $this->user_id,
                          ],
                      ]
                  );
d8c1a2e0   Yarik   Big commit artbox
223
224
225
226
227
              }
              
              return $dataProvider;
          }
      }