public function search($params, $city_name = false) { $query = System::find(); if ($this->getScenario() === 'salon-cars') { $sort = ['defaultOrder' => ['sort_order' => SORT_ASC]]; } else { $sort = ['defaultOrder' => ['min_cost' => SORT_ASC]]; } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => $sort, 'pagination' => false]); $this->load($params); if (!$this->trans1 and !$this->trans2 or $this->trans1 and $this->trans2) { $this->trans = null; $this->trans1 = 1; $this->trans2 = 1; } elseif ($this->trans1) { $this->trans = 1; } else { $this->trans = 2; } if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category' => $this->category]); if (!empty($this->day)) { $query->select(['system_auto.*', 'rentact.day']); $query->leftJoin('rentact', 'rentact.system_id = system_auto.id AND rentact.day = "' . date('d.m.Y', strtotime($this->day)) . '" '); $query->having(' `rentact`.`day` is NULL '); $query->groupBy('`system_auto`.`id`'); } // $query->innerJoinWith(['account'])->where("account.balance > -1 and account.is_moderated = '2' and account.is_salon = '1' "); $query->innerJoinWith(['account'])->where("account.is_moderated = '" . Account::FLAG_MODERATE_COMPLET . "' AND account.is_salon = '1' "); if ($this->getScenario() !== 'salon-cars') { // if (Yii::$app->user->isGuest) { $query->innerJoinWith(['account'])->where('account.balance > -1'); $query->andWhere(['system_auto.is_moderated' => '2', 'account.is_moderated' => '2', 'is_display' => '1']); // } else { // $query->innerJoinWith(['account'])->where(['or', ['>', 'account.balance', -1], ['system_auto.account_id' => Yii::$app->user->id]]); // $query->andWhere(['or', ['system_auto.is_moderated' => '2'], ['system_auto.account_id' => Yii::$app->user->id]]); // $query->andWhere(['or', ['=', 'is_display', '1'], ['system_auto.account_id' => Yii::$app->user->id]]); // } } if ($city_name) { $query->andWhere(['=', 'account.city_name', $city_name]); } $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['=', 'category', $this->category])->andFilterWhere(['between', 'min_cost', $this->min_price, $this->max_price])->andFilterWhere(['=', 'account_id', $this->account_id])->andFilterWhere(['=', 'trans', $this->trans])->andFilterWhere(['=', 'conditioner', $this->conditioner])->andFilterWhere(['=', 'w_driver', $this->w_driver])->andFilterWhere(['like', 'fuel', $this->fuel]); // Create a command. You can get the actual SQL using $command->sql //$command = $query->createCommand(); return $dataProvider; }
protected function findModel($id) { if (($model = System::findOne($id)) !== null) { return $model; } else { $this->setNotFoundHttpException(); } }
public static function getAccountCountAutos($account_id) { return System::find()->where(['account_id' => $account_id])->count(); }