/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Sale::find(); //$query->joinWith(['views', 'facilities']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]); $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->name)) { $query->leftJoin('sale_lang', 'sale_lang.id = sale.id'); $query->groupBy('sale.id'); } if ($this->view_ids) { $query->leftJoin('sale_view', 'sale_view.sale_id = sale.id'); $query->groupBy('sale.id'); } if ($this->facility_ids) { $query->leftJoin('sale_facilities', 'sale_facilities.sale_id = sale.id'); $query->groupBy('sale.id'); } $query->andFilterWhere(['sale.id' => $this->id, 'code' => $this->code, 'object_id' => $this->object_id, 'region_id' => $this->region_id, 'district_id' => $this->district_id, 'type_id' => $this->type_id, 'parking_id' => $this->parking_id, 'bathroom' => $this->bathroom, 'bedroom' => $this->bedroom, 'solarpanel' => $this->solarpanel, 'sauna' => $this->sauna, 'furniture' => $this->furniture, 'conditioner' => $this->conditioner, 'heating' => $this->heating, 'storage' => $this->storage, 'tennis' => $this->tennis, 'status' => $this->status, 'sold' => $this->sold, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'top' => $this->top]); $query->andFilterWhere(['like', 'sale_lang.name', $this->name])->andFilterWhere(['like', 'commission', $this->commission])->andFilterWhere(['like', 'gps', $this->gps])->andFilterWhere(['like', 'contacts', $this->contacts])->andFilterWhere(['like', 'owner', $this->owner])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['>=', 'price', $this->price_from])->andFilterWhere(['<=', 'price', $this->price_to])->andFilterWhere(['>=', 'year', $this->year_from])->andFilterWhere(['<=', 'year', $this->year_to])->andFilterWhere(['>=', 'covered', $this->covered_from])->andFilterWhere(['<=', 'covered', $this->covered_to])->andFilterWhere(['>=', 'uncovered', $this->uncovered_from])->andFilterWhere(['<=', 'uncovered', $this->uncovered_to])->andFilterWhere(['>=', 'plot', $this->plot_from])->andFilterWhere(['<=', 'plot', $this->plot_to])->andFilterWhere(['>=', 'bathroom', $this->bathroom_from])->andFilterWhere(['<=', 'bathroom', $this->bathroom_to])->andFilterWhere(['>=', 'bedroom', $this->bedroom_from])->andFilterWhere(['<=', 'bedroom', $this->bedroom_to])->andFilterWhere(['in', 'sale_view.view_id', $this->view_ids])->andFilterWhere(['in', 'sale_facilities.facility_id', $this->facility_ids]); //$command = $query->createCommand(); //echo $command->sql; return $dataProvider; }
public function actionDistrictList() { if (isset($_POST['depdrop_parents'])) { if ($parents = $_POST['depdrop_parents']) { $district_ids = Sale::find()->select('district_id')->where(['region_id' => $parents[0]])->groupBy(['district_id'])->column(); $out = District::getListByIds($district_ids); foreach ($out as $key => $value) { $result[] = ['id' => $key, 'name' => $value]; } print Json::encode(['output' => @$result, 'selected' => '']); return; } } }
/** * @return array */ public static function getList($id) { return ArrayHelper::map(Sale::find()->where(['district_id' => $id])->all(), 'object_id', function ($e) { return 'ID ' . $e['object_id'] . ' (' . $e['address'] . ')'; }); }
use common\models\Sale; use common\models\User; $this->title = 'Admin Panel'; ?> <div class="row"> <div class="col-xs-6 col-md-4"> <div class="info-box"> <span class="info-box-icon bg-red"><i class="fa fa-home"></i></span> <div class="info-box-content"> <span class="info-box-text"><?php echo Yii::t('app', 'Sales'); ?> </span> <span class="info-box-number"><?php echo Sale::find()->count(); ?> </span> </div> </div> </div> <div class="col-xs-6 col-md-4"> <div class="info-box"> <span class="info-box-icon bg-aqua"><i class="fa fa-user"></i></span> <div class="info-box-content"> <span class="info-box-text"><?php echo Yii::t('app', 'Users'); ?> </span> <span class="info-box-number"><?php echo User::find()->count();