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'; ?>
@@ -14,6 +24,82 @@ $this->title = 'My Yii Application';
+ 'get', + 'options' => [ 'class' => 'search-work-form' ], + 'action' => [ '' ], + ]); + echo $form->field($model, 'specialization') + ->dropDownList($specialization, [ 'prompt' => 'Любая' ]); + + echo $form->field($model, 'city') + ->widget(Select2::classname(), [ + 'options' => [ 'placeholder' => 'Выбор города ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'site/city' ]), + 'dataType' => 'json', + 'data' => new JsExpression('function(params) { return {q:params.term}; }'), + ], + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), + 'templateResult' => new JsExpression('function(city) { return city.text; }'), + 'templateSelection' => new JsExpression('function (city) { return city.text; }'), + ], + ]); + + ?> +
+
Бюджет
+
+ field($model, 'budget_from', [ + 'template' => "{input}\n{error}", + 'options' => [ 'tag' => 'span' ], + ]) + ->textInput([ 'placeholder' => $model->getAttributeLabel('budget_from') ]) ?> + field($model, 'budget_to', [ + 'template' => "{input}\n{error}", + 'options' => [ 'tag' => 'span' ], + ]) + ->textInput([ 'placeholder' => $model->getAttributeLabel('budget_to') ]) ?> + field($model, 'budget_currency', [ + 'template' => "{input}\n{error}", + 'options' => [ 'class' => 'blocks-check-list-wrapp check-valuta' ], + ]) + ->dropDownList($currencies) ?> +
+ field($model, 'contractual', [ 'template' => "{input}\n{error}", 'options' => ['class' => ''] ]) + ->checkboxList([1 => $model->getAttributeLabel('contractual')], [ + 'item' => function($index, $label, $name, $checked, $value) { + $return = '
'; + $return .= ''; + $return .= ''; + $return .= '
'; + return $return; + } + ]); ?> + field($model, 'payment', [ 'template' => "{input}\n{error}" ]) + ->checkboxList($payments, [ + 'item' => function($index, $label, $name, $checked, $value) { + $return = '
'; + $return .= ''; + $return .= ''; + $return .= '
'; + return $return; + } + ]); ?> +
+
+ +
+ end(); + /* + ?>
@@ -47,7 +133,7 @@ $this->title = 'My Yii Application';
Регион
@@ -98,17 +184,16 @@ $this->title = 'My Yii Application';
+ */?>
-
Сейчас totalCount ?> предложений
+
Сейчас totalCount ?> предложений
- $projects, - 'itemView'=>'_projects_list_view', - 'layout' => "{items}\n" - ] ); - ?> + $dataProvider, + 'itemView' => '_projects_list_view', + 'layout' => "{items}\n", + ]); ?>
@@ -122,191 +207,164 @@ $this->title = 'My Yii Application';
    -
  • Все

  • -
  • Жилые

  • -
  • Офисные

  • -
  • Торговые

  • -
  • Мосты

  • -
  • Дороги

  • -
  • Сооружения

  • -
  • Склады

  • -
  • Заводы

  • -
  • Разное

  • +
  • +

    Все

  • +
  • +

    Жилые

  • +
  • +

    Офисные

  • +
  • +

    Торговые

  • +
  • +

    Мосты

  • +
  • +

    Дороги

  • +
  • +

    Сооружения

  • +
  • +

    Склады

  • +
  • +

    Заводы

  • +
  • +

    Разное

    -
  • проекты

  • -
  • подряды

  • +
  • +

    проекты

  • +
  • +

    подряды

@@ -397,8 +455,8 @@ $this->title = 'My Yii Application';
- - + +
-- libgit2 0.21.4