OSDN Git Service

Причёсывание кода. Исправлен QR-код при редактировании предмета/оборудования
[invent/invent.git] / models / RegionsSearch.php
1 <?php
2
3 namespace app\models;
4
5 use yii\base\Model;
6 use yii\data\ActiveDataProvider;
7 use app\models\Regions;
8
9 /**
10  * RegionsSearch represents the model behind the search form of `app\models\Regions`.
11  */
12 class RegionsSearch extends Regions
13 {
14     /**
15      * {@inheritdoc}
16      */
17     public function rules()
18     {
19         return [
20             [['id'], 'integer'],
21             [['name'], 'safe'],
22         ];
23     }
24
25     /**
26      * {@inheritdoc}
27      */
28     public function scenarios()
29     {
30         // bypass scenarios() implementation in the parent class
31         return Model::scenarios();
32     }
33
34     /**
35      * Creates data provider instance with search query applied
36      *
37      * @param array $params
38      *
39      * @return ActiveDataProvider
40      */
41     public function search($params)
42     {
43         $query = Regions::find();
44
45         // add conditions that should always apply here
46
47         $dataProvider = new ActiveDataProvider([
48             'query' => $query,
49         ]);
50
51         $dataProvider->setSort([
52             'defaultOrder' => [
53                 'name' => SORT_ASC,
54             ],
55         ]);
56
57         $this->load($params);
58
59         if (!$this->validate()) {
60             // uncomment the following line if you do not want to return any records when validation fails
61             // $query->where('0=1');
62             return $dataProvider;
63         }
64
65         // grid filtering conditions
66         $query->andFilterWhere([
67             'id' => $this->id,
68         ]);
69
70         $query->andFilterWhere([ 'ilike', 'name', $this->name ]);
71
72         return $dataProvider;
73     }
74 }