Blame view

common/models/PortfolioSearch.php 3.79 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
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'portfolio_id',
989c83b0   Yarik   test
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
                          'user_add_id',
                          'view_count',
                          'gallery_id',
                      ],
                      'integer',
                  ],
                  [
                      [
                          'name',
                          'link',
                          'date_add',
                          'city',
                          'street',
                          'house',
                          'description',
                          'cover',
                          'specializationString',
                      ],
                      'safe',
                  ],
              ];
          }
588209fc   Yarik   test
47
  
989c83b0   Yarik   test
48
49
50
51
52
53
54
55
          /**
           * @inheritdoc
           */
          public function scenarios()
          {
              // bypass scenarios() implementation in the parent class
              return Model::scenarios();
          }
588209fc   Yarik   test
56
  
989c83b0   Yarik   test
57
58
59
60
61
62
63
64
65
66
          /**
           * Creates data provider instance with search query applied
           *
           * @param array $params
           *
           * @return ActiveDataProvider
           */
          public function search($params)
          {
              $query = Portfolio::find();
588209fc   Yarik   test
67
  
989c83b0   Yarik   test
68
              // add conditions that should always apply here
588209fc   Yarik   test
69
  
989c83b0   Yarik   test
70
71
72
              $dataProvider = new ActiveDataProvider([
                  'query' => $query,
              ]);
588209fc   Yarik   test
73
  
989c83b0   Yarik   test
74
              $this->load($params);
588209fc   Yarik   test
75
  
989c83b0   Yarik   test
76
77
78
79
80
              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
81
  
989c83b0   Yarik   test
82
              $query->joinWith('specializations');
588209fc   Yarik   test
83
  
a02e2fdb   Yarik   test
84
85
              $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
  
989c83b0   Yarik   test
86
87
88
              // grid filtering conditions
              $query->andFilterWhere([
                  'portfolio_id' => $this->portfolio_id,
989c83b0   Yarik   test
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
                  '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
      }