a2cde075
Yarik
first commit
|
1
2
|
<?php
|
faff2c48
Yarik
Artbox comment cr...
|
3
|
namespace artbox\webcomment\models;
|
a2cde075
Yarik
first commit
|
4
5
6
7
8
9
|
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* CommentModelSearch represents the model behind the search form about
|
faff2c48
Yarik
Artbox comment cr...
|
10
|
* `artbox\webcomment\models\CommentModel`.
|
a2cde075
Yarik
first commit
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
*/
class CommentModelSearch extends CommentModel
{
public $ratingValue;
public $childrenCount;
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
|
faff2c48
Yarik
Artbox comment cr...
|
27
|
'id',
|
a2cde075
Yarik
first commit
|
28
29
30
31
|
'created_at',
'updated_at',
'deleted_at',
'status',
|
faff2c48
Yarik
Artbox comment cr...
|
32
|
'parent_id',
|
a2cde075
Yarik
first commit
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
'related_id',
'entity_id',
],
'integer',
],
[
[
'childrenCount',
],
'integer',
'min' => 0,
],
[
[
'ratingValue',
],
'number',
'min' => 1,
'max' => 5,
],
[
[
|
faff2c48
Yarik
Artbox comment cr...
|
55
|
'customer_id',
|
a2cde075
Yarik
first commit
|
56
57
58
59
60
61
62
63
64
65
66
|
'text',
'username',
'email',
'ip',
'entity',
'info',
],
'safe',
],
];
}
|
faff2c48
Yarik
Artbox comment cr...
|
67
68
69
70
|
/**
* @inheritdoc
*/
|
a2cde075
Yarik
first commit
|
71
72
73
74
75
|
public function attributeLabels()
{
return array_merge(
parent::attributeLabels(),
[
|
faff2c48
Yarik
Artbox comment cr...
|
76
77
|
'ratingValue' => \Yii::t('artbox-comment', 'Рейтинг'),
'childrenCount' => \Yii::t('artbox-comment', 'Количество ответов'),
|
a2cde075
Yarik
first commit
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
]
);
}
/**
* @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()
->joinWith(
[
'rating',
|
faff2c48
Yarik
Artbox comment cr...
|
104
|
'customer',
|
a2cde075
Yarik
first commit
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
]
);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
'sort' => [
'attributes' => [
'ratingValue' => [
'asc' => [ 'artbox_comment_rating.value' => SORT_ASC ],
'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ],
],
|
faff2c48
Yarik
Artbox comment cr...
|
119
|
'id',
|
a2cde075
Yarik
first commit
|
120
|
'text',
|
faff2c48
Yarik
Artbox comment cr...
|
121
|
'customer_id',
|
a2cde075
Yarik
first commit
|
122
123
124
|
'status',
'entity',
'entity_id',
|
920dd24d
Yarik
Comments
|
125
|
'created_at',
|
a2cde075
Yarik
first commit
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
],
'defaultOrder' => [
'created_at' => SORT_DESC,
],
],
]
);
$this->load($params);
if (!$this->validate()) {
// 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
$query->andFilterWhere(
[
|
faff2c48
Yarik
Artbox comment cr...
|
145
|
'id' => $this->id,
|
a2cde075
Yarik
first commit
|
146
147
148
149
|
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'deleted_at' => $this->deleted_at,
'artbox_comment.status' => $this->status,
|
faff2c48
Yarik
Artbox comment cr...
|
150
|
'parent_id' => $this->parent_id,
|
a2cde075
Yarik
first commit
|
151
152
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
200
201
202
|
'related_id' => $this->related_id,
'entity_id' => $this->entity_id,
]
);
$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,
]
);
|
faff2c48
Yarik
Artbox comment cr...
|
203
204
|
if (!empty($this->customer_id)) {
|
a2cde075
Yarik
first commit
|
205
206
207
|
$query->andWhere(
[
'or',
|
faff2c48
Yarik
Artbox comment cr...
|
208
|
[ 'artbox_comment.customer_id' => (int) $this->customer_id ],
|
a2cde075
Yarik
first commit
|
209
210
211
|
[
'like',
'user.username',
|
faff2c48
Yarik
Artbox comment cr...
|
212
|
$this->customer_id,
|
a2cde075
Yarik
first commit
|
213
214
215
216
|
],
[
'like',
'artbox_comment.username',
|
faff2c48
Yarik
Artbox comment cr...
|
217
|
$this->customer_id,
|
a2cde075
Yarik
first commit
|
218
219
220
221
|
],
[
'like',
'artbox_comment.email',
|
faff2c48
Yarik
Artbox comment cr...
|
222
|
$this->customer_id,
|
a2cde075
Yarik
first commit
|
223
224
225
226
227
228
229
230
|
],
]
);
}
return $dataProvider;
}
}
|