6 use yii\data\ActiveDataProvider;
10 use app\models\Locations;
11 use app\models\Regions;
14 * ItemsSearch represents the model behind the search form of `app\models\Items`.
16 class ItemsSearch extends Items
21 public function rules()
24 [['id', 'state_id', 'type_id'], 'integer'],
25 [['name', 'model', 'os', 'mac', 'serial', 'product', 'modelnumber', 'invent', 'date', 'comment', 'statusName', 'typeName', 'locationName', 'regionName'], 'safe'],
32 public function scenarios()
34 // bypass scenarios() implementation in the parent class
35 return Model::scenarios();
39 * Creates data provider instance with search query applied
41 * @param array $params
43 * @return ActiveDataProvider
45 public function search($params)
47 $query = Items::find();
48 $query->joinWith(['status']);
49 $query->joinWith(['types']);
52 $query->joinWith(['locations']);
53 // $query->joinWith(['regions']);
56 // add conditions that should always apply here
58 $dataProvider = new ActiveDataProvider([
62 $dataProvider->setSort([
70 if (!$this->validate()) {
71 // uncomment the following line if you do not want to return any records when validation fails
72 // $query->where('0=1');
76 // grid filtering conditions
77 $query->andFilterWhere([
79 'date' => $this->date,
81 'like', Status::tableName().'.name', $this->statusName
83 'like', Types::tableName().'.name', $this->typeName
85 'like', Locations::tableName().'.name', $this->locationName
86 // ])->andFilterWhere([
87 // 'like', Regions::tableName().'.name', $this->regionName
90 $query->andFilterWhere(['ilike', 'name', $this->name])
91 ->andFilterWhere(['ilike', 'model', $this->model])
92 ->andFilterWhere(['ilike', 'os', $this->os])
93 ->andFilterWhere(['ilike', 'mac', $this->mac])
94 ->andFilterWhere(['ilike', 'serial', $this->serial])
95 ->andFilterWhere(['ilike', 'product', $this->product])
96 ->andFilterWhere(['ilike', 'modelnumber', $this->modelnumber])
97 ->andFilterWhere(['ilike', 'invent', $this->invent])
98 ->andFilterWhere(['ilike', 'comment', $this->comment]);
100 $dataProvider->sort->attributes['statusName'] = [
101 'asc' => [Status::tableName().'.name' => SORT_ASC],
102 'desc' => [Status::tableName().'.name' => SORT_DESC],
104 $dataProvider->sort->attributes['typeName'] = [
105 'asc' => [Types::tableName().'.name' => SORT_ASC],
106 'desc' => [Types::tableName().'.name' => SORT_DESC],
108 $dataProvider->sort->attributes['locationName'] = [
109 'asc' => [Locations::tableName().'.name' => SORT_ASC],
110 'desc' => [Locations::tableName().'.name' => SORT_DESC],
112 // $dataProvider->sort->attributes['regionName'] = [
113 // 'asc' => [Regions::tableName().'.name' => SORT_ASC],
114 // 'desc' => [Regions::tableName().'.name' => SORT_DESC],
117 return $dataProvider;