Blame view

common/models/VacancySearch.php 3.03 KB
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
  
a02e2fdb   Yarik   test
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'vacancy_id',
                          'user_add_id',
                          'view_count',
                      ],
                      'integer',
                  ],
                  [
                      [
                          'name',
                          'link',
                          'date_add',
                          'user_name',
                          'city',
                          'description',
                      ],
                      'safe',
                  ],
              ];
          }
588209fc   Yarik   test
43
  
a02e2fdb   Yarik   test
44
45
46
47
48
49
50
51
          /**
           * @inheritdoc
           */
          public function scenarios()
          {
              // bypass scenarios() implementation in the parent class
              return Model::scenarios();
          }
588209fc   Yarik   test
52
  
a02e2fdb   Yarik   test
53
54
55
56
57
58
59
60
61
62
          /**
           * Creates data provider instance with search query applied
           *
           * @param array $params
           *
           * @return ActiveDataProvider
           */
          public function search($params)
          {
              $query = Vacancy::find();
588209fc   Yarik   test
63
  
a02e2fdb   Yarik   test
64
              // add conditions that should always apply here
588209fc   Yarik   test
65
  
a02e2fdb   Yarik   test
66
67
68
              $dataProvider = new ActiveDataProvider([
                  'query' => $query,
              ]);
588209fc   Yarik   test
69
  
a02e2fdb   Yarik   test
70
              $this->load($params);
588209fc   Yarik   test
71
  
a02e2fdb   Yarik   test
72
73
74
75
76
              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
77
  
a02e2fdb   Yarik   test
78
              $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
588209fc   Yarik   test
79
  
a02e2fdb   Yarik   test
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
              // 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([
                  '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
116
      }