1, ], [ [ 'name_search', 'surname_search', 'specialization', ], 'safe', ], ]; } /** * @inheritdoc */ public function scenarios() { return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find() ->joinWith('userInfo'); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => new Pagination([ 'pageSize' => 5, ]), 'sort' => new Sort([ 'defaultOrder' => [ 'id' => SORT_ASC, ], ]), ]); $this->load($params); if(!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } if(!empty( $this->specialization )) { $specialization_id = User::find() ->joinWith('specializations') ->select(['user.id'], 'DISTINCT') ->where([ 'like', 'LOWER(specialization.specialization_name)', mb_strtolower($this->specialization), ]) ->asArray() ->column(); $query->andWhere(['user.id' => $specialization_id]); } $query->andFilterWhere([ 'id' => $this->id, ]); $query->andFilterWhere([ 'like', 'LOWER(firstname)', mb_strtolower($this->name_search), ]) ->andFilterWhere([ 'like', 'LOWER(lastname)', mb_strtolower($this->surname_search), ]); return $dataProvider; } }