Example #1
0
 /**
  * Creating model search query.
  * @return ActiveDataProvider|\yii\data\DataProviderInterface
  */
 public function search($params = [])
 {
     $query = Advert::find()->with('owner.profile');
     $dataProvider = new \roman444uk\yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => \roman444uk\yii\widgets\WidgetPageSize::getPageSize()]]);
     if ($params && !($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->buildQuery($query, $params);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Advert::find();
     $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->andFilterWhere(['idadvert' => $this->idadvert, 'price' => $this->price, 'fk_agent_detail' => $this->fk_agent_detail, 'badroom' => $this->badroom, 'livingroom' => $this->livingroom, 'parking' => $this->parking, 'kitchen' => $this->kitchen, 'hot' => $this->hot, 'sold' => $this->sold, 'recommend' => $this->recommend, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'general_image', $this->general_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'type', $this->type]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Creating model search query.
  * @return ActiveDataProvider|\yii\data\DataProviderInterface
  */
 public function search($params = [])
 {
     $query = Advert::find()->with('owner.profile', 'files');
     // query city, bookmarks and likes
     $tableAdvert = self::tableName();
     $tableBookmark = Yii::$app->getModule('bookmarks')->tableBookmark;
     $query->select("{$tableAdvert}.*, ({$tableAdvert}.id = {$tableBookmark}.target_id) as bookmarked, city.name as cityName");
     $query->join('left join', $tableBookmark, "{$tableBookmark}.target_id = {$tableAdvert}.id");
     $query->join('left join', 'city', 'advert.city_id = city.id');
     // creating data provider
     $dataProvider = new \roman444uk\yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => \roman444uk\yii\widgets\WidgetPageSize::getPageSize('advert-list')]]);
     if ($params && !($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->buildQuery($query, $params);
     if ($this->search_bookmarks) {
         $query->andWhere(["{$tableAdvert}.id" => Yii::$app->getModule('bookmarks')->manager->getIdList($this->bookmark_user_id, ['Advert'], true)]);
     }
     return $dataProvider;
 }
Example #4
0
 public function actionFind($propert = '', $price = '', $apartment = '')
 {
     $this->layout = 'sell';
     $query = Advert::find();
     $query->filterWhere(['like', 'address', $propert])->orFilterWhere(['like', 'description', $propert])->andFilterWhere(['type' => $apartment]);
     if ($price) {
         $prices = explode("-", $price);
         if (isset($prices[0]) && isset($prices[1])) {
             $query->andWhere(['between', 'price', $prices[0], $prices[1]]);
         } else {
             $query->andWhere(['>=', 'price', $prices[0]]);
         }
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->setPageSize(10);
     $model = $query->offset($pages->offset)->limit($pages->limit)->all();
     $request = \Yii::$app->request;
     return $this->render("find", ['model' => $model, 'pages' => $pages, 'request' => $request]);
 }