Yii::t('app', 'Тип заказчика'), 'rating' => Yii::t('app', 'Рейтинг'), 'online' => Yii::t('app', 'Статус'), 'city' => Yii::t('app', 'Город'), 'info' => Yii::t('app', 'Любая информация о заказчике'), ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class 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') ->joinWith('companyInfo'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $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; } $query->andWhere([ 'is_customer' => 1, ]); if($this->type == 2) { $query->andWhere([ 'not', [ 'company_info.company_info_id' => NULL ], ]); $query->andWhere([ 'type' => 2, ]); } elseif($this->type == 1) { $query->andWhere([ 'type' => 1, ]); } if($this->online == 1) { $query->andWhere([ '>=', 'user_info.date_visit', date('Y-m-d H:i:s.u', time() - 1800), ]); } $query->andFilterWhere([ 'like', 'user_info.city', $this->city, ])->andFilterWhere([ 'or', [ 'like', 'LOWER(username)', mb_strtolower($this->info), ], [ 'like', 'LOWER(lastname)', mb_strtolower($this->info), ], [ 'like', 'LOWER(firstname)', mb_strtolower($this->info), ], [ 'like', 'LOWER(middlename)', mb_strtolower($this->info), ], [ 'like', 'LOWER(company_info.name)', mb_strtolower($this->info), ], [ 'like', 'LOWER(company_info.street)', mb_strtolower($this->info), ], [ 'like', 'LOWER(user_info.country)', mb_strtolower($this->info), ], [ 'like', 'LOWER(user_info.city)', mb_strtolower($this->info), ], [ 'like', 'LOWER(user_info.about)', mb_strtolower($this->info), ], ]); return $dataProvider; } }