diff --git a/common/models/Project.php b/common/models/Project.php index 9390d4d..e7999ad 100644 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -41,8 +41,6 @@ return 'project'; } - - /** * @inheritdoc */ diff --git a/common/models/TenderSearch.php b/common/models/TenderSearch.php new file mode 100644 index 0000000..1971337 --- /dev/null +++ b/common/models/TenderSearch.php @@ -0,0 +1,235 @@ + 0, + ], + [ + [ + 'payment', + ], + 'default', + 'value' => Payment::find() + ->asArray() + ->column(), + ], + [ + [ + 'budget_currency', + ], + 'default', + 'value' => 3, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'specialization' => Yii::t('app', 'Специализация'), + 'budget_currency' => Yii::t('app', 'Валюта'), + 'contractual' => Yii::t('app', 'Договорной'), + 'city' => Yii::t('app', 'Город'), + 'payment' => Yii::t('app', 'Способ оплаты'), + 'budget_from' => Yii::t('app', 'от'), + 'budget_to' => 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 = Project::find() + ->joinWith('projectSpecializations') + ->joinWith('projectPayments'); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + /*$dataProvider->setSort([ + 'defaultOrder' => [ + 'name' => SORT_ASC, + ], + 'attributes' => [ + 'name' => [ + 'asc' => [ + 'company_info.name' => SORT_ASC, + 'firstname' => SORT_ASC, + 'lastname' => SORT_ASC, + ], + 'desc' => [ + 'company_info.name' => SORT_DESC, + 'firstname' => SORT_DESC, + 'lastname' => SORT_DESC, + ], + 'default' => SORT_ASC, + 'label' => 'Название', + ], + 'staff' => [ + 'asc' => [ + 'company_info.staff' => SORT_ASC, + ], + 'desc' => [ + 'company_info.staff' => SORT_DESC, + ], + 'default' => SORT_DESC, + 'label' => 'Количество сотрудников', + ], + 'visit' => [ + 'asc' => [ + 'user_info.date_visit' => SORT_ASC, + ], + 'desc' => [ + 'user_info.date_visit' => SORT_DESC, + ], + 'default' => SORT_DESC, + 'label' => 'Последний визит', + ], + 'city' => [ + 'asc' => [ + 'user_info.city' => SORT_ASC, + ], + 'desc' => [ + 'user_info.city' => SORT_DESC, + ], + 'default' => SORT_ASC, + 'label' => 'Город', + ], + ], + ]);*/ + + $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->distinct(true); + + $query->andWhere([ + '>=', + 'date_end', + date('Y-m-d'), + ]); + + $query->andFilterWhere([ + 'project_specialization.specialization_id' => $this->specialization, + 'project_payment.payment_id' => $this->payment, + 'city' => $this->city, + ]) + ->andWhere([ + 'project_payment.payment_id' => $this->payment, + ]); + + if(!empty( $this->contractual )) { + $query->andWhere([ + 'contractual' => $this->contractual, + ]); + } else { + $currencies = Currency::find() + ->select([ + 'rate', + 'currency_id', + ]) + ->asArray() + ->indexBy('currency_id') + ->column(); + + if(!empty($this->budget_from) && !empty($this->budget_to)) { + $query->andFilterWhere([ + 'between', + 'total_budget', + $this->budget_from * $currencies[ $this->budget_currency ], + $this->budget_to * $currencies[ $this->budget_currency ], + ]); + } elseif(!empty($this->budget_from)) { + $query->andFilterWhere([ + '>=', + 'total_budget', + $this->budget_from * $currencies[ $this->budget_currency ], + ]); + } elseif(!empty($this->budget_to)) { + $query->andFilterWhere([ + '<=', + 'total_budget', + $this->budget_to * $currencies[ $this->budget_currency ], + ]); + } + + } + + return $dataProvider; + } + } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index 7cba02a..c39cfde 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -1,9 +1,12 @@ Project::find(), - 'pagination' => [ - 'pageSize' => 9, - ], + $model = new TenderSearch(); + $dataProvider = $model->search(Yii::$app->request->queryParams); + $dataProvider->setPagination([ + 'pageSize' => 10, ]); + $specialization = Specialization::specializationsList(); + $currencies = Currency::getCurrencyDropdown(); + $payments = Payment::find()->select(['name', 'payment_id'])->asArray()->indexBy('payment_id')->column(); return $this->render('project', [ - 'projects' => $projects, + 'model' => $model, + 'dataProvider' => $dataProvider, + 'specialization' => $specialization, + 'currencies' => $currencies, + 'payments' => $payments, ]); } diff --git a/frontend/views/search/project.php b/frontend/views/search/project.php index 3588d0e..e2c5130 100755 --- a/frontend/views/search/project.php +++ b/frontend/views/search/project.php @@ -1,12 +1,22 @@ title = 'My Yii Application'; + $this->title = 'My Yii Application'; ?>
Все
Жилые
Офисные
Торговые
Мосты
Дороги
Сооружения
Склады
Заводы
Разное
Все
Жилые
Офисные
Торговые
Мосты
Дороги
Сооружения
Склады
Заводы
Разное
проекты
подряды
проекты
подряды