/** * * @param type $query * @param type $params */ public function buildQuery($query, $params) { $tableAdvert = self::tableName(); if (!empty($this->category)) { $query->andWhere('category = :category', [':category' => $this->category]); } if (!empty($this->content)) { $ids = []; foreach ((new \yii\sphinx\Query())->from(self::tableName())->match($this->content)->all() as $row) { array_push($ids, $row['id']); } $query->andWhere([self::tableName() . '.id' => $ids]); } if (!empty($this->city_id)) { $query->andWhere('city_id = :city_id', [':city_id' => $this->city_id]); } /*if (!empty($this->city)) { $query->andWhere('city = :city', [':city' => $this->city]); }*/ if (!empty($this->created_at)) { } if (!empty($this->currency)) { $query->andWhere('currency = :currency', [':currency' => $this->currency]); } if (!empty($this->is_foreign) || $this->is_foreign === 0) { $query->andWhere('is_foreign = :is_foreign', [':is_foreign' => $this->is_foreign]); } if (!empty($this->is_templet) || $this->is_templet === 0) { $query->andWhere('is_templet = :is_templet', [':is_templet' => $this->is_templet]); } if (!empty($this->min_date) && ($minDate = DatepickerHelper::convertDateFrom($this->min_date))) { $query->andWhere(self::tableName() . '.created_at >= :minDate', [':minDate' => $minDate]); } if (!empty($this->min_price)) { $query->andWhere('min_price = :min_price', [':min_price' => $this->min_price]); } if (!empty($this->max_price)) { $query->andWhere('max_price = :max_price', [':max_price' => $this->max_price]); } if (!empty($this->max_date) && ($maxDate = DatepickerHelper::convertDateTo($this->max_date))) { $query->andWhere(self::tableName() . '.created_at <= :maxDate', [':maxDate' => $maxDate]); } if (!empty($this->published) || $this->published === 0) { $query->andWhere('published = :published', [':published' => $this->published]); } if (!empty($this->status)) { $query->andWhere('status = :status', [':status' => $this->status]); } if (!empty($this->type)) { $query->andWhere('type = :type', [':type' => $this->type]); } if (!empty($this->updated_at)) { } if (!empty($this->user_id)) { $query->andWhere("{$tableAdvert}.user_id = :user_id", [':user_id' => $this->user_id]); } $query->orderBy(self::tableName() . '.created_at desc'); }