6 use yii\data\ActiveDataProvider;
10 use app\models\Locations;
11 use app\models\Regions;
12 use app\models\Models;
15 * MovingSearch represents the model behind the search form of `app\models\Moving`.
17 class MovingSearch extends Moving
22 public function rules()
25 [[ 'id', 'item_id', 'location_id', 'state_id' ], 'integer' ],
26 [[ 'date', 'comment', 'itemModel', 'statusName', 'locationName', 'regionName' ], 'safe' ],
33 public function scenarios()
35 // bypass scenarios() implementation in the parent class
36 return Model::scenarios();
40 * Creates data provider instance with search query applied
42 * @param array $params
44 * @return ActiveDataProvider
46 public function search($params)
48 $query = Moving::find()
49 ->select(Moving::tableName() . '.*, '
50 . Models::tableName() . '.name AS itemModel, '
51 . Status::tableName() . '.name AS statusName, '
52 . Locations::tableName() . '.name AS locationName, '
53 . Regions::tableName() . '.name AS regionName' )
54 ->joinWith([ 'items', 'status', 'locations', 'regions', 'models' ]);
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,
80 'item_id' => $this->item_id,
81 'location_id' => $this->location_id,
82 'state_id' => $this->state_id,
85 $query->andFilterWhere([ 'ilike', Models::tableName() . '.name', $this->itemModel ]);
86 $query->andFilterWhere([ 'ilike', Status::tableName() . '.name', $this->statusName ]);
87 $query->andFilterWhere([ 'OR', [ 'ilike', Locations::tableName() . '.name', $this->locationName ],
88 [ 'ilike', Regions::tableName() . '.name', $this->locationName ]]);
89 $query->andFilterWhere([ 'OR', [ 'ilike', Locations::tableName() . '.name', $this->regionName ],
90 [ 'ilike', Regions::tableName() . '.name', $this->regionName ]]);
92 $query->andFilterWhere(['ilike', 'comment', $this->comment]);
94 $dataProvider->sort->attributes[ 'itemModel' ] = [
95 'asc' => [ Models::tableName() . '.name' => SORT_ASC ],
96 'desc' => [ Models::tableName() . '.name' => SORT_DESC ],
99 $dataProvider->sort->attributes[ 'statusName' ] = [
100 'asc' => [ Status::tableName() . '.name' => SORT_ASC ],
101 'desc' => [ Status::tableName() . '.name' => SORT_DESC ],
103 $dataProvider->sort->attributes[ 'locationName' ] = [
104 'asc' => [ Locations::tableName() . '.name' => SORT_ASC ],
105 'desc' => [ Locations::tableName() . '.name' => SORT_DESC ],
107 $dataProvider->sort->attributes[ 'regionName' ] = [
108 'asc' => [ Regions::tableName() . '.name' => SORT_ASC ],
109 'desc' => [ Regions::tableName() . '.name' => SORT_DESC ],
112 return $dataProvider;