OSDN Git Service

Исправление ошибки сохранения Git, после которой пропала часть изменений в обработке...
[invent/invent.git] / models / ItemsSearch.php
1 <?php
2
3 namespace app\models;
4
5 use yii\base\Model;
6 use yii\data\ActiveDataProvider;
7 use app\models\Items;
8
9 /**
10  * ItemsSearch represents the model behind the search form of `app\models\Items`.
11  */
12 class ItemsSearch extends Items
13 {
14     /**
15      * {@inheritdoc}
16      */
17     public function rules()
18     {
19         return [
20             [['id'], 'integer'],
21             [['name', 'model', 'os', 'mac', 'serial', 'product', 'modelnumber', 'invent', 'date', 'comment', 'statusName'], '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 = Items::find();
44         $query->joinWith(['status']);
45         $query->joinWith(['types']);
46
47         // add conditions that should always apply here
48
49         $dataProvider = new ActiveDataProvider([
50             'query' => $query,
51         ]);
52
53         $dataProvider->sort->attributes['statusName'] = [
54             'asc' => [Status::className().'.name' => SORT_ASC],
55             'desc' => [Status::className().'.name' => SORT_DESC],
56         ];
57         $dataProvider->sort->attributes['typeName'] = [
58             'asc' => [Types::className().'.name' => SORT_ASC],
59             'desc' => [Types::className().'.name' => SORT_DESC],
60         ];
61         
62         $dataProvider->setSort([
63             'defaultOrder' => [
64                 'id' => SORT_ASC,
65             ],
66         ]);
67         $this->load($params);
68
69         if (!$this->validate()) {
70             // uncomment the following line if you do not want to return any records when validation fails
71             // $query->where('0=1');
72             return $dataProvider;
73         }
74
75         // grid filtering conditions
76         $query->andFilterWhere([
77             'id' => $this->id,
78             'date' => $this->date,
79         ])->andFilterWhere([
80             'like', Status::tableName().'.name', $this->statusName
81         ])->andFilterWhere([
82             'like', Types::tableName().'.name', $this->typeName
83         ]);
84
85         $query->andFilterWhere(['ilike', 'name', $this->name])
86             ->andFilterWhere(['ilike', 'model', $this->model])
87             ->andFilterWhere(['ilike', 'os', $this->os])
88             ->andFilterWhere(['ilike', 'mac', $this->mac])
89             ->andFilterWhere(['ilike', 'serial', $this->serial])
90             ->andFilterWhere(['ilike', 'product', $this->product])
91             ->andFilterWhere(['ilike', 'modelnumber', $this->modelnumber])
92             ->andFilterWhere(['ilike', 'invent', $this->invent])
93             ->andFilterWhere(['ilike', 'comment', $this->comment]);
94
95         return $dataProvider;
96     }
97 }