Blame view

common/models/PortfolioSearch.php 3.8 KB
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
  
989c83b0   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
43
44
45
46
47
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'portfolio_id',
                          'user_id',
                          'user_add_id',
                          'view_count',
                          'gallery_id',
                      ],
                      'integer',
                  ],
                  [
                      [
                          'name',
                          'link',
                          'date_add',
                          'city',
                          'street',
                          'house',
                          'description',
                          'cover',
                          'specializationString',
                      ],
                      'safe',
                  ],
              ];
          }
588209fc   Yarik   test
48
  
989c83b0   Yarik   test
49
50
51
52
53
54
55
56
          /**
           * @inheritdoc
           */
          public function scenarios()
          {
              // bypass scenarios() implementation in the parent class
              return Model::scenarios();
          }
588209fc   Yarik   test
57
  
989c83b0   Yarik   test
58
59
60
61
62
63
64
65
66
67
          /**
           * Creates data provider instance with search query applied
           *
           * @param array $params
           *
           * @return ActiveDataProvider
           */
          public function search($params)
          {
              $query = Portfolio::find();
588209fc   Yarik   test
68
  
989c83b0   Yarik   test
69
              // add conditions that should always apply here
588209fc   Yarik   test
70
  
989c83b0   Yarik   test
71
72
73
              $dataProvider = new ActiveDataProvider([
                  'query' => $query,
              ]);
588209fc   Yarik   test
74
  
989c83b0   Yarik   test
75
              $this->load($params);
588209fc   Yarik   test
76
  
989c83b0   Yarik   test
77
78
79
80
81
              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
82
  
989c83b0   Yarik   test
83
              $query->joinWith('specializations');
588209fc   Yarik   test
84
  
989c83b0   Yarik   test
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
              // grid filtering conditions
              $query->andFilterWhere([
                  'portfolio_id' => $this->portfolio_id,
                  'user_id'      => $this->user_id,
                  'date_add'     => $this->date_add,
                  'user_add_id'  => $this->user_add_id,
                  'view_count'   => $this->view_count,
                  'gallery_id'   => $this->gallery_id,
              ]);
  
              $query->andFilterWhere([
                  '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,
                    ])
                    ->andFilterWhere([
                        'like',
                        'specialization.specialization_name',
                        $this->specializationString,
                    ]);
  
              return $dataProvider;
          }
588209fc   Yarik   test
138
      }