Commit c0bffebb2bbb4b1a674f7d27cdd686684e0e389e

Authored by Yarik
1 parent 616c8534

test

common/config/main.php
... ... @@ -96,6 +96,7 @@
96 96 ],
97 97 'formatter' => [
98 98 'booleanFormat' => ['Нет', 'Да'],
  99 + 'defaultTimeZone' => 'Europe/Kiev',
99 100 ],
100 101 'urlManager' => [
101 102 'enablePrettyUrl' => true,
... ...
common/models/CustomerSearch.php
... ... @@ -37,13 +37,13 @@
37 37 'integer',
38 38 ],
39 39 [
40   - ['rating'],
  40 + [ 'rating' ],
41 41 'number',
42 42 'min' => 0,
43 43 'max' => 5,
44 44 ],
45 45 [
46   - ['rating'],
  46 + [ 'rating' ],
47 47 'default',
48 48 'value' => 0,
49 49 ],
... ... @@ -63,11 +63,11 @@
63 63 public function attributeLabels()
64 64 {
65 65 return [
66   - 'type' => Yii::t('app', 'Тип заказчика'),
67   - 'rating' => Yii::t('app', 'Рейтинг'),
68   - 'online' => Yii::t('app', 'Статус'),
69   - 'city' => Yii::t('app', 'Город'),
70   - 'info' => Yii::t('app', 'Любая информация о заказчике'),
  66 + 'type' => Yii::t('app', 'Тип заказчика'),
  67 + 'rating' => Yii::t('app', 'Рейтинг'),
  68 + 'online' => Yii::t('app', 'Статус'),
  69 + 'city' => Yii::t('app', 'Город'),
  70 + 'info' => Yii::t('app', 'Любая информация о заказчике'),
71 71 ];
72 72 }
73 73  
... ... @@ -133,61 +133,62 @@
133 133 }
134 134  
135 135 $query->andFilterWhere([
136   - '>=', 'user_info.rating', $this->rating,
  136 + '>=',
  137 + 'user_info.rating',
  138 + $this->rating,
137 139 ]);
138 140  
139 141 $query->andFilterWhere([
140   - 'like',
141   - 'user_info.city',
142   - $this->city,
143   - ])->andFilterWhere([
144   - 'or',
145   - [
146   - 'like',
147   - 'LOWER(username)',
148   - mb_strtolower($this->info),
149   - ],
150   - [
151   - 'like',
152   - 'LOWER(lastname)',
153   - mb_strtolower($this->info),
154   - ],
155   - [
156   - 'like',
157   - 'LOWER(firstname)',
158   - mb_strtolower($this->info),
159   - ],
160   - [
161   - 'like',
162   - 'LOWER(middlename)',
163   - mb_strtolower($this->info),
164   - ],
165   - [
166   - 'like',
167   - 'LOWER(company_info.name)',
168   - mb_strtolower($this->info),
169   - ],
170   - [
171   - 'like',
172   - 'LOWER(company_info.street)',
173   - mb_strtolower($this->info),
174   - ],
175   - [
176   - 'like',
177   - 'LOWER(user_info.country)',
178   - mb_strtolower($this->info),
179   - ],
180   - [
181   - 'like',
182   - 'LOWER(user_info.city)',
183   - mb_strtolower($this->info),
184   - ],
185   - [
186   - 'like',
187   - 'LOWER(user_info.about)',
188   - mb_strtolower($this->info),
189   - ],
190   - ]);
  142 + 'user_info.city' => $this->city,
  143 + ])
  144 + ->andFilterWhere([
  145 + 'or',
  146 + [
  147 + 'like',
  148 + 'LOWER(username)',
  149 + mb_strtolower($this->info),
  150 + ],
  151 + [
  152 + 'like',
  153 + 'LOWER(lastname)',
  154 + mb_strtolower($this->info),
  155 + ],
  156 + [
  157 + 'like',
  158 + 'LOWER(firstname)',
  159 + mb_strtolower($this->info),
  160 + ],
  161 + [
  162 + 'like',
  163 + 'LOWER(middlename)',
  164 + mb_strtolower($this->info),
  165 + ],
  166 + [
  167 + 'like',
  168 + 'LOWER(company_info.name)',
  169 + mb_strtolower($this->info),
  170 + ],
  171 + [
  172 + 'like',
  173 + 'LOWER(company_info.street)',
  174 + mb_strtolower($this->info),
  175 + ],
  176 + [
  177 + 'like',
  178 + 'LOWER(user_info.country)',
  179 + mb_strtolower($this->info),
  180 + ],
  181 + [
  182 + 'like',
  183 + 'LOWER(user_info.city)',
  184 + mb_strtolower($this->info),
  185 + ],
  186 + [
  187 + 'like',
  188 + 'LOWER(user_info.about)',
  189 + mb_strtolower($this->info),
  190 + ],
  191 + ]);
191 192  
192 193 return $dataProvider;
193 194 }
... ...
frontend/controllers/SearchController.php
... ... @@ -124,16 +124,9 @@
124 124 ],
125 125 ]);
126 126 $model->load(Yii::$app->request->queryParams);
127   - $cities = UserInfo::find()
128   - ->select('city')
129   - ->distinct()
130   - ->asArray()
131   - ->indexBy('city')
132   - ->column();
133 127 return $this->render('customer', [
134 128 'model' => $model,
135 129 'dataProvider' => $dataProvider,
136   - 'cities' => $cities,
137 130 ]);
138 131 }
139 132  
... ...
frontend/views/search/_customer_list_view.php
... ... @@ -52,7 +52,14 @@
52 52 }
53 53 ?>
54 54 <div class="search_perform_visit">
55   - <span>Последний визит:</span> <?= \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit) ?>
  55 + <span>Последний визит:</span>
  56 + <?php
  57 + if((time() - \Yii::$app->formatter->asTimestamp($model->userInfo->date_visit)) < 1800) {
  58 + echo 'Онлайн';
  59 + } else {
  60 + echo \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit);
  61 + }
  62 + ?>
56 63 </div>
57 64 <div class="search_perform_projets_nam">
58 65 <?= Html::a("Заказано проектов {$model->getProjects()->count()}", ['search/project', (new Project())->formName().'[user_id]' => $model->id]) ?>
... ...
frontend/views/search/customer.php
... ... @@ -2,12 +2,13 @@
2 2 /**
3 3 * @var CustomerSearch $model
4 4 * @var ActiveDataProvider $dataProvider
5   - * @var string[] $cities
6 5 */
7 6 use common\models\CustomerSearch;
  7 + use kartik\select2\Select2;
8 8 use yii\data\ActiveDataProvider;
9 9 use yii\helpers\Html;
10 10 use yii\jui\SliderInput;
  11 + use yii\web\JsExpression;
11 12 use yii\widgets\ActiveForm;
12 13 use yii\widgets\LinkSorter;
13 14 use yii\widgets\ListView;
... ... @@ -31,13 +32,22 @@
31 32 'action' => [ '' ],
32 33 ]);
33 34  
34   - echo $form->field($model, 'city', [
35   - 'options' => [
36   - 'class' => 'blocks-check-list-wrapp',
37   - ],
38   - 'template' => "<div class='blocks-check-title'>{label}</div>\n{input}<div class='select-after'></div>\n{hint}\n{error}",
39   - ])
40   - ->dropDownList($cities, [ 'prompt' => 'Любой' ]);
  35 + echo $form->field($model, 'city')
  36 + ->widget(Select2::classname(), [
  37 + 'options' => [ 'placeholder' => 'Выбор города ...' ],
  38 + 'pluginOptions' => [
  39 + 'allowClear' => true,
  40 + 'minimumInputLength' => 3,
  41 + 'ajax' => [
  42 + 'url' => \yii\helpers\Url::to([ 'site/city' ]),
  43 + 'dataType' => 'json',
  44 + 'data' => new JsExpression('function(params) { return {q:params.term}; }'),
  45 + ],
  46 + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
  47 + 'templateResult' => new JsExpression('function(city) { return city.text; }'),
  48 + 'templateSelection' => new JsExpression('function (city) { return city.text; }'),
  49 + ],
  50 + ]);
41 51  
42 52 echo $form->field($model, 'type', [
43 53 'options' => [
... ... @@ -54,10 +64,10 @@
54 64 <div id="slider-value"></div>
55 65 <?php
56 66 echo $form->field($model, 'rating', [
57   - 'template' => "{label}<br><div id='{$form->id}-rating'>{$model->rating}</div><br>{input}\n{hint}\n{error}",
58   - 'labelOptions' => [
59   - 'class' => 'blocks-check-title',
60   - ],
  67 + 'template' => "{label}<br><div id='{$form->id}-rating'>{$model->rating}</div><br>{input}\n{hint}\n{error}",
  68 + 'labelOptions' => [
  69 + 'class' => 'blocks-check-title',
  70 + ],
61 71 ])
62 72 ->widget(SliderInput::className(), [
63 73 'clientOptions' => [
... ... @@ -66,7 +76,7 @@
66 76 'step' => 0.5,
67 77 ],
68 78 'clientEvents' => [
69   - 'slide' => "function( event, ui ) {
  79 + 'slide' => "function( event, ui ) {
70 80 $( '#{$form->id}-rating' ).text(ui.value);
71 81 $('input[name=\"{$model->formName()}[rating]\"]').val(ui.value);
72 82  
... ...