6 use yii\data\ActiveDataProvider;
10 * ItemsSearch represents the model behind the search form of `app\models\Items`.
12 class ItemsSearch extends Items
17 public function rules()
21 [['name', 'model', 'os', 'mac', 'serial', 'product', 'modelnumber', 'invent', 'date', 'comment', 'statusName'], 'safe'],
28 public function scenarios()
30 // bypass scenarios() implementation in the parent class
31 return Model::scenarios();
35 * Creates data provider instance with search query applied
37 * @param array $params
39 * @return ActiveDataProvider
41 public function search($params)
43 $query = Items::find();
44 $query->joinWith(['status']);
45 $query->joinWith(['types']);
47 // add conditions that should always apply here
49 $dataProvider = new ActiveDataProvider([
53 $dataProvider->sort->attributes['statusName'] = [
54 'asc' => [Status::className().'.name' => SORT_ASC],
55 'desc' => [Status::className().'.name' => SORT_DESC],
57 $dataProvider->sort->attributes['typeName'] = [
58 'asc' => [Types::className().'.name' => SORT_ASC],
59 'desc' => [Types::className().'.name' => SORT_DESC],
62 $dataProvider->setSort([
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');
75 // grid filtering conditions
76 $query->andFilterWhere([
78 'date' => $this->date,
80 'like', Status::tableName().'.name', $this->statusName
82 'like', Types::tableName().'.name', $this->typeName
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]);