From c0bffebb2bbb4b1a674f7d27cdd686684e0e389e Mon Sep 17 00:00:00 2001 From: Yarik Date: Sat, 12 Mar 2016 12:29:30 +0200 Subject: [PATCH] test --- common/config/main.php | 1 + common/models/CustomerSearch.php | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------- frontend/controllers/SearchController.php | 7 ------- frontend/views/search/_customer_list_view.php | 9 ++++++++- frontend/views/search/customer.php | 36 +++++++++++++++++++++++------------- 5 files changed, 92 insertions(+), 80 deletions(-) diff --git a/common/config/main.php b/common/config/main.php index 071f0df..c3405c3 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -96,6 +96,7 @@ ], 'formatter' => [ 'booleanFormat' => ['Нет', 'Да'], + 'defaultTimeZone' => 'Europe/Kiev', ], 'urlManager' => [ 'enablePrettyUrl' => true, diff --git a/common/models/CustomerSearch.php b/common/models/CustomerSearch.php index 243402d..c8c60bb 100644 --- a/common/models/CustomerSearch.php +++ b/common/models/CustomerSearch.php @@ -37,13 +37,13 @@ 'integer', ], [ - ['rating'], + [ 'rating' ], 'number', 'min' => 0, 'max' => 5, ], [ - ['rating'], + [ 'rating' ], 'default', 'value' => 0, ], @@ -63,11 +63,11 @@ public function attributeLabels() { return [ - 'type' => Yii::t('app', 'Тип заказчика'), - 'rating' => Yii::t('app', 'Рейтинг'), - 'online' => Yii::t('app', 'Статус'), - 'city' => Yii::t('app', 'Город'), - 'info' => Yii::t('app', 'Любая информация о заказчике'), + 'type' => Yii::t('app', 'Тип заказчика'), + 'rating' => Yii::t('app', 'Рейтинг'), + 'online' => Yii::t('app', 'Статус'), + 'city' => Yii::t('app', 'Город'), + 'info' => Yii::t('app', 'Любая информация о заказчике'), ]; } @@ -133,61 +133,62 @@ } $query->andFilterWhere([ - '>=', 'user_info.rating', $this->rating, + '>=', + 'user_info.rating', + $this->rating, ]); $query->andFilterWhere([ - 'like', - 'user_info.city', - $this->city, - ])->andFilterWhere([ - 'or', - [ - 'like', - 'LOWER(username)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(lastname)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(firstname)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(middlename)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(company_info.name)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(company_info.street)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(user_info.country)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(user_info.city)', - mb_strtolower($this->info), - ], - [ - 'like', - 'LOWER(user_info.about)', - mb_strtolower($this->info), - ], - ]); + 'user_info.city' => $this->city, + ]) + ->andFilterWhere([ + 'or', + [ + 'like', + 'LOWER(username)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(lastname)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(firstname)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(middlename)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(company_info.name)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(company_info.street)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(user_info.country)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(user_info.city)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(user_info.about)', + mb_strtolower($this->info), + ], + ]); return $dataProvider; } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index 4c40602..6c386e7 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -124,16 +124,9 @@ ], ]); $model->load(Yii::$app->request->queryParams); - $cities = UserInfo::find() - ->select('city') - ->distinct() - ->asArray() - ->indexBy('city') - ->column(); return $this->render('customer', [ 'model' => $model, 'dataProvider' => $dataProvider, - 'cities' => $cities, ]); } diff --git a/frontend/views/search/_customer_list_view.php b/frontend/views/search/_customer_list_view.php index f6f86d2..4954370 100644 --- a/frontend/views/search/_customer_list_view.php +++ b/frontend/views/search/_customer_list_view.php @@ -52,7 +52,14 @@ } ?>
- Последний визит: formatter->asRelativeTime($model->userInfo->date_visit) ?> + Последний визит: + formatter->asTimestamp($model->userInfo->date_visit)) < 1800) { + echo 'Онлайн'; + } else { + echo \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit); + } + ?>
getProjects()->count()}", ['search/project', (new Project())->formName().'[user_id]' => $model->id]) ?> diff --git a/frontend/views/search/customer.php b/frontend/views/search/customer.php index 47d661e..c3f75c9 100644 --- a/frontend/views/search/customer.php +++ b/frontend/views/search/customer.php @@ -2,12 +2,13 @@ /** * @var CustomerSearch $model * @var ActiveDataProvider $dataProvider - * @var string[] $cities */ use common\models\CustomerSearch; + use kartik\select2\Select2; use yii\data\ActiveDataProvider; use yii\helpers\Html; use yii\jui\SliderInput; + use yii\web\JsExpression; use yii\widgets\ActiveForm; use yii\widgets\LinkSorter; use yii\widgets\ListView; @@ -31,13 +32,22 @@ 'action' => [ '' ], ]); - echo $form->field($model, 'city', [ - 'options' => [ - 'class' => 'blocks-check-list-wrapp', - ], - 'template' => "
{label}
\n{input}
\n{hint}\n{error}", - ]) - ->dropDownList($cities, [ '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; }'), + ], + ]); echo $form->field($model, 'type', [ 'options' => [ @@ -54,10 +64,10 @@
field($model, 'rating', [ - 'template' => "{label}
{$model->rating}

{input}\n{hint}\n{error}", - 'labelOptions' => [ - 'class' => 'blocks-check-title', - ], + 'template' => "{label}
{$model->rating}

{input}\n{hint}\n{error}", + 'labelOptions' => [ + 'class' => 'blocks-check-title', + ], ]) ->widget(SliderInput::className(), [ 'clientOptions' => [ @@ -66,7 +76,7 @@ 'step' => 0.5, ], 'clientEvents' => [ - 'slide' => "function( event, ui ) { + 'slide' => "function( event, ui ) { $( '#{$form->id}-rating' ).text(ui.value); $('input[name=\"{$model->formName()}[rating]\"]').val(ui.value); -- libgit2 0.21.4