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