ad6304d6
Yarik
test
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* TenderSearch represents the model behind the search form about `common\models\UserInfo`.
*/
class TenderSearch extends Project
{
public $specialization;
public $city;
public $budget_from;
public $budget_to;
public $budget_currency;
public $contractual;
public $payment;
|
93a7a3c1
Yarik
test
|
29
30
|
public $info;
|
ad6304d6
Yarik
test
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'specialization',
'budget_currency',
'contractual',
],
'integer',
],
[
[
'city',
'payment',
|
93a7a3c1
Yarik
test
|
49
|
'info',
|
ad6304d6
Yarik
test
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
],
'safe',
],
[
[
'budget_from',
'budget_to',
],
'number',
'min' => 0,
],
[
[
'payment',
],
'default',
'value' => Payment::find()
->asArray()
->column(),
],
[
[
|
be662d1f
Yarik
test
|
72
73
74
75
76
77
78
|
'contractual',
],
'default',
'value' => 1,
],
[
[
|
ad6304d6
Yarik
test
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
'budget_currency',
],
'default',
'value' => 3,
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
|
93a7a3c1
Yarik
test
|
93
|
'specialization' => Yii::t('app', 'specialization'),
|
06ec2844
Administrator
28.03.16
|
94
|
'budget_currency' => Yii::t('app', 'budget_currency'),
|
93a7a3c1
Yarik
test
|
95
96
97
98
99
|
'contractual' => Yii::t('app', 'contractual'),
'city' => Yii::t('app', 'city'),
'payment' => Yii::t('app', 'payment'),
'budget_from' => Yii::t('app', 'budget_from'),
'budget_to' => Yii::t('app', 'budget_to'),
|
ad6304d6
Yarik
test
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
];
}
/**
* @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 = Project::find()
->joinWith('projectSpecializations')
|
2f324895
Yarik
test
|
123
|
->joinWith('projectPayments');
|
ad6304d6
Yarik
test
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
|
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
/*$dataProvider->setSort([
'defaultOrder' => [
'name' => SORT_ASC,
],
'attributes' => [
'name' => [
'asc' => [
'company_info.name' => SORT_ASC,
'firstname' => SORT_ASC,
'lastname' => SORT_ASC,
],
'desc' => [
'company_info.name' => SORT_DESC,
'firstname' => SORT_DESC,
'lastname' => SORT_DESC,
],
'default' => SORT_ASC,
'label' => 'Название',
],
'staff' => [
'asc' => [
'company_info.staff' => SORT_ASC,
],
'desc' => [
'company_info.staff' => SORT_DESC,
],
'default' => SORT_DESC,
'label' => 'Количество сотрудников',
],
'visit' => [
'asc' => [
'user_info.date_visit' => SORT_ASC,
],
'desc' => [
'user_info.date_visit' => SORT_DESC,
],
'default' => SORT_DESC,
'label' => 'Последний визит',
],
'city' => [
'asc' => [
'user_info.city' => SORT_ASC,
],
'desc' => [
'user_info.city' => SORT_DESC,
],
'default' => SORT_ASC,
'label' => 'Город',
],
],
]);*/
$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;
}
$query->distinct(true);
$query->andWhere([
'>=',
'date_end',
date('Y-m-d'),
]);
$query->andFilterWhere([
'project_specialization.specialization_id' => $this->specialization,
'project_payment.payment_id' => $this->payment,
'city' => $this->city,
])
|
93a7a3c1
Yarik
test
|
202
203
204
205
206
|
->andFilterWhere([
'like',
'LOWER(project.name)',
mb_strtolower($this->info),
])
|
ad6304d6
Yarik
test
|
207
208
209
210
|
->andWhere([
'project_payment.payment_id' => $this->payment,
]);
|
2261f70a
Yarik
test
|
211
212
213
214
215
216
217
218
219
220
|
$currencies = Currency::find()
->select([
'rate',
'currency_id',
])
->asArray()
->indexBy('currency_id')
->column();
if(empty( $this->contractual )) {
|
ad6304d6
Yarik
test
|
221
|
$query->andWhere([
|
2261f70a
Yarik
test
|
222
223
|
'not',
[ 'contractual' => 1 ],
|
ad6304d6
Yarik
test
|
224
|
]);
|
2261f70a
Yarik
test
|
225
|
if(!empty( $this->budget_from ) && !empty( $this->budget_to )) {
|
ad6304d6
Yarik
test
|
226
227
228
229
230
231
|
$query->andFilterWhere([
'between',
'total_budget',
$this->budget_from * $currencies[ $this->budget_currency ],
$this->budget_to * $currencies[ $this->budget_currency ],
]);
|
2261f70a
Yarik
test
|
232
|
} elseif(!empty( $this->budget_from )) {
|
ad6304d6
Yarik
test
|
233
234
235
236
237
|
$query->andFilterWhere([
'>=',
'total_budget',
$this->budget_from * $currencies[ $this->budget_currency ],
]);
|
2261f70a
Yarik
test
|
238
|
} elseif(!empty( $this->budget_to )) {
|
ad6304d6
Yarik
test
|
239
240
241
242
243
244
|
$query->andFilterWhere([
'<=',
'total_budget',
$this->budget_to * $currencies[ $this->budget_currency ],
]);
}
|
2261f70a
Yarik
test
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
} else {
if(!empty( $this->budget_from ) && !empty( $this->budget_to )) {
$query->andWhere([
'or',
[
'and',
[
'between',
'total_budget',
$this->budget_from * $currencies[ $this->budget_currency ],
$this->budget_to * $currencies[ $this->budget_currency ],
],
[
'not',
[
'contractual' => 1,
],
],
],
[
'contractual' => 1,
],
]);
} elseif(!empty( $this->budget_from )) {
$query->andWhere([
'or',
[
'and',
[
'>=',
'total_budget',
$this->budget_from * $currencies[ $this->budget_currency ],
],
[
'not',
[
'contractual' => 1,
],
],
],
[
'contractual' => 1,
],
]);
} elseif(!empty( $this->budget_to )) {
$query->andWhere([
'or',
[
'and',
[
'<=',
'total_budget',
$this->budget_to * $currencies[ $this->budget_currency ],
],
[
'not',
[
'contractual' => 1,
],
],
],
[
'contractual' => 1,
],
]);
} else {
$query->andWhere([
'or',
[
'and',
[
'>=',
'total_budget',
0,
],
[
'not',
[
'contractual' => 1,
],
],
],
[
'contractual' => 1,
],
]);
}
|
ad6304d6
Yarik
test
|
332
333
334
335
336
|
}
return $dataProvider;
}
}
|