588209fc
Yarik
test
|
1
2
|
<?php
|
989c83b0
Yarik
test
|
3
|
namespace common\models;
|
588209fc
Yarik
test
|
4
|
|
989c83b0
Yarik
test
|
5
6
7
8
|
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Portfolio;
|
588209fc
Yarik
test
|
9
|
|
588209fc
Yarik
test
|
10
|
/**
|
989c83b0
Yarik
test
|
11
|
* PortfolioSearch represents the model behind the search form about `common\models\Portfolio`.
|
588209fc
Yarik
test
|
12
|
*/
|
989c83b0
Yarik
test
|
13
|
class PortfolioSearch extends Portfolio
|
588209fc
Yarik
test
|
14
|
{
|
588209fc
Yarik
test
|
15
|
|
4c9663e0
Yarik
test
|
16
17
|
public $date_add_from;
public $date_add_to;
|
989c83b0
Yarik
test
|
18
19
20
21
22
23
24
25
26
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'portfolio_id',
|
989c83b0
Yarik
test
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
'user_add_id',
'view_count',
'gallery_id',
],
'integer',
],
[
[
'name',
'link',
'date_add',
'city',
'street',
'house',
'description',
'cover',
'specializationString',
|
4c9663e0
Yarik
test
|
44
45
|
'date_add_from',
'date_add_to',
|
989c83b0
Yarik
test
|
46
47
48
|
],
'safe',
],
|
4c9663e0
Yarik
test
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
[
[
'date_add_from',
],
'default',
'value' => date('Y-m-d', 0),
],
[
[
'date_add_to',
],
'default',
'value' => date('Y-m-d'),
],
|
989c83b0
Yarik
test
|
63
64
|
];
}
|
588209fc
Yarik
test
|
65
|
|
989c83b0
Yarik
test
|
66
67
68
69
70
71
72
73
|
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
|
588209fc
Yarik
test
|
74
|
|
989c83b0
Yarik
test
|
75
76
77
78
79
80
81
82
83
84
|
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Portfolio::find();
|
588209fc
Yarik
test
|
85
|
|
989c83b0
Yarik
test
|
86
|
// add conditions that should always apply here
|
588209fc
Yarik
test
|
87
|
|
989c83b0
Yarik
test
|
88
89
90
|
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
|
588209fc
Yarik
test
|
91
|
|
989c83b0
Yarik
test
|
92
|
$this->load($params);
|
588209fc
Yarik
test
|
93
|
|
989c83b0
Yarik
test
|
94
95
96
97
98
|
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;
}
|
588209fc
Yarik
test
|
99
|
|
4c9663e0
Yarik
test
|
100
101
102
103
104
105
106
107
108
109
110
111
112
|
$query2 = [ ];
if(!empty( $this->specializationString )) {
$query2 = Portfolio::find()
->select([ 'portfolio.portfolio_id' ], 'DISTINCT')
->joinWith([ 'specializations' ])
->where([
'like',
'specialization_name',
$this->specializationString,
])
->asArray()
->column();
}
|
588209fc
Yarik
test
|
113
|
|
a02e2fdb
Yarik
test
|
114
115
|
$query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
|
989c83b0
Yarik
test
|
116
117
118
|
// grid filtering conditions
$query->andFilterWhere([
'portfolio_id' => $this->portfolio_id,
|
989c83b0
Yarik
test
|
119
120
121
122
123
124
125
|
'date_add' => $this->date_add,
'user_add_id' => $this->user_add_id,
'view_count' => $this->view_count,
'gallery_id' => $this->gallery_id,
]);
$query->andFilterWhere([
|
4c9663e0
Yarik
test
|
126
127
128
129
130
131
132
133
134
135
136
137
138
|
'between',
'date_add',
$this->date_add_from,
$this->date_add_to,
]);
$query->andFilterWhere(
[
'portfolio_id' => $query2,
]
);
$query->andFilterWhere([
|
989c83b0
Yarik
test
|
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
|
'like',
'name',
$this->name,
])
->andFilterWhere([
'like',
'link',
$this->link,
])
->andFilterWhere([
'like',
'city',
$this->city,
])
->andFilterWhere([
'like',
'street',
$this->street,
])
->andFilterWhere([
'like',
'house',
$this->house,
])
->andFilterWhere([
'like',
'description',
$this->description,
])
->andFilterWhere([
'like',
'cover',
$this->cover,
|
989c83b0
Yarik
test
|
172
173
174
175
|
]);
return $dataProvider;
}
|
588209fc
Yarik
test
|
176
|
}
|