Commit 2fd40ee72b0966b28e051559cd3fd815da9b7ec7

Authored by Yarik
1 parent 4ed1f788

test

common/models/CustomerSearch.php
... ... @@ -123,6 +123,10 @@
123 123 }
124 124  
125 125 $query->andFilterWhere([
  126 + 'user_info.rating' => $this->rating,
  127 + ]);
  128 +
  129 + $query->andFilterWhere([
126 130 'like',
127 131 'user_info.city',
128 132 $this->city,
... ...
common/models/User.php
... ... @@ -578,11 +578,29 @@
578 578 }
579 579 }
580 580  
  581 + /**
  582 + * @return ActiveQuery
  583 + */
581 584 public function getComments()
582 585 {
583   - $entity = 'user-' . $this->id;
584   - $comments = (new Comment())->getComments($entity);
585   - return $comments;
  586 + return $this->hasMany(Comment::className(), [
  587 + 'model_id' => 'id',
  588 + ])
  589 + ->andWhere([
  590 + 'comment.model' => $this->className(),
  591 + ]);
  592 + }
  593 +
  594 + /**
  595 + * @return ActiveQuery
  596 + */
  597 + public function getCommentRating()
  598 + {
  599 + return $this->hasMany(Rating::className(), [ 'model_id' => 'comment_id' ])
  600 + ->via('comments')
  601 + ->andWhere([
  602 + 'rating.model' => Comment::className(),
  603 + ]);
586 604 }
587 605  
588 606 public function getRatingPG()
... ... @@ -590,16 +608,21 @@
590 608 if(\Yii::$app->db->driverName != 'pgsql') {
591 609 throw new InvalidConfigException('This method is available only in PostgreSQL');
592 610 }
593   - $entity = 'user-' . $this->id;
594   - $rating = (new Comment())->getComments($entity)
595   - ->select('ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::float) as rating')
596   - ->leftJoin(Rating::tableName(), "CONCAT('Comment-', \"comment\".\"comment_id\") = \"rating\".\"entity\"")
597   - ->andWhere([
598   - 'not',
599   - [ 'rating.value' => NULL ],
600   - ])
601   - ->one();
602   - return $rating;
  611 + return $this->getCommentRating()
  612 + ->select('ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::float) as rating')
  613 + ->andWhere([
  614 + 'not',
  615 + [ 'rating.value' => NULL ],
  616 + ])
  617 + ->scalar();
  618 + }
  619 +
  620 + public function updateRating()
  621 + {
  622 + if($rating = $this->getRatingPG()) {
  623 + $this->userInfo->rating = $rating;
  624 + $this->userInfo->save();
  625 + }
603 626 }
604 627  
605 628 }
... ...
common/modules/comment/interfaces/CommentInterface.php
... ... @@ -4,7 +4,7 @@
4 4 interface CommentInterface {
5 5 public function load($data, $formName = null);
6 6 public function formName();
7   - public function getComments($entity);
  7 + public function getComments($model, $model_id);
8 8 public function postComment();
9 9 public function deleteComment();
10 10 public function updateComment();
... ...
common/modules/comment/models/Comment.php
... ... @@ -7,6 +7,17 @@
7 7 * Class Comment
8 8 * @property bool $guestComment
9 9 * @property integer $comment_id
  10 + * @property string $text
  11 + * @property int $user_id
  12 + * @property string $user_name
  13 + * @property string $user_email
  14 + * @property int $comment_pid
  15 + * @property int $status
  16 + * @property string $date_add
  17 + * @property string $date_update
  18 + * @property string $date_delete
  19 + * @property string $model
  20 + * @property int $model_id
10 21 * @package common\modules\comment\models
11 22 */
12 23 class Comment extends \yii\db\ActiveRecord
... ... @@ -21,8 +32,6 @@
21 32 const SCENARIO_USER = 'user';
22 33 const SCENARIO_GUEST = 'guest';
23 34  
24   - public $rating;
25   -
26 35 /**
27 36 * @var bool
28 37 */
... ... @@ -70,7 +79,8 @@
70 79 'exist',
71 80 'targetAttribute' => 'comment_id',
72 81 'filter' => [
73   - 'entity' => $this->entity,
  82 + 'model' => $this->model,
  83 + 'model_id' => $this->model_id,
74 84 ],
75 85 ],
76 86 ];
... ... @@ -135,16 +145,18 @@
135 145 }
136 146  
137 147 /**
138   - * @param string $entity
  148 + * @param string $model
  149 + * @param integer $model_id
139 150 *
140 151 * @return ActiveQuery
141 152 */
142   - public function getComments($entity)
  153 + public function getComments($model, $model_id)
143 154 {
144 155 return $this->find()
145 156 ->where([
146   - 'comment.entity' => $entity,
147   - 'comment.status' => 1,
  157 + 'comment.model' => $model,
  158 + 'comment.model_id' => $model_id,
  159 + 'comment.status' => 1,
148 160 ]);
149 161 }
150 162  
... ... @@ -212,7 +224,10 @@
212 224 if($this->getGuestComment()) {
213 225 return true;
214 226 } else {
215   - return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [ 'entity' => $this->entity ]);
  227 + return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [
  228 + 'model' => $this->model,
  229 + 'model_id' => $this->model_id,
  230 + ]);
216 231 }
217 232 }
218 233  
... ... @@ -221,7 +236,13 @@
221 236 if($this->scenario == self::SCENARIO_GUEST) {
222 237 return false;
223 238 } else {
224   - return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [ 'entity' => $this->entity ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [ 'entity' => $this->entity ]);
  239 + return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [
  240 + 'model' => $this->model,
  241 + 'model_id' => $this->model_id,
  242 + ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [
  243 + 'model' => $this->model,
  244 + 'model_id' => $this->model_id,
  245 + ]);
225 246 }
226 247 }
227 248  
... ... @@ -230,7 +251,13 @@
230 251 if($this->scenario == self::SCENARIO_GUEST) {
231 252 return false;
232 253 } else {
233   - return \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [ 'entity' => $this->entity ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [ 'entity' => $this->entity ]);
  254 + return \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [
  255 + 'model' => $this->model,
  256 + 'model_id' => $this->model_id,
  257 + ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [
  258 + 'model' => $this->model,
  259 + 'model_id' => $this->model_id,
  260 + ]);
234 261 }
235 262 }
236 263  
... ... @@ -260,12 +287,18 @@
260 287  
261 288 public function checkRating()
262 289 {
263   - $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ])
  290 + $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [
  291 + 'model_id' => 'comment_id',
  292 + ])
  293 + ->andWhere([
  294 + 'model' => $this->className(),
  295 + ])
264 296 ->one();
265 297 if(!$rating instanceof \common\modules\comment\models\Rating) {
266 298 $rating = new \common\modules\comment\models\Rating([
267   - 'entity' => $this->entityId,
268   - 'user_id' => $this->user_id,
  299 + 'model' => $this->className(),
  300 + 'model_id' => $this->comment_id,
  301 + 'user_id' => $this->user_id,
269 302 ]);
270 303 $rating->save();
271 304 }
... ... @@ -274,12 +307,18 @@
274 307 public function getRating()
275 308 {
276 309 $this->checkRating();
277   - return $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ]);
  310 + return $this->hasOne(\common\modules\comment\models\Rating::className(), [
  311 + 'model_id' => 'comment_id',
  312 + ])
  313 + ->andWhere([ 'model' => $this->className() ]);
278 314 }
279 315  
280 316 public function hasRating($return = true)
281 317 {
282   - $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ])
  318 + $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [
  319 + 'model_id' => 'comment_id',
  320 + ])
  321 + ->andWhere([ 'model' => $this->className() ])
283 322 ->andWhere([
284 323 'not',
285 324 [ 'value' => NULL ],
... ... @@ -292,8 +331,4 @@
292 331 }
293 332 }
294 333  
295   - public function getEntityId()
296   - {
297   - return $this->formName() . '-' . $this->getPrimaryKey();
298   - }
299 334 }
... ...
common/modules/comment/models/Rating.php
... ... @@ -11,13 +11,16 @@ use Yii;
11 11 * @property string $date_add
12 12 * @property string $date_update
13 13 * @property integer $user_id
14   - * @property string $entity
15 14 * @property integer $value
  15 + * @property string $model
  16 + * @property integer $model_id
16 17 *
17 18 * @property \common\models\User $user
18 19 */
19 20 class Rating extends \yii\db\ActiveRecord
20 21 {
  22 +
  23 + public $rating;
21 24 /**
22 25 * @inheritdoc
23 26 */
... ...
common/modules/comment/widgets/CommentWidget.php
... ... @@ -86,9 +86,14 @@
86 86 public $success_text = 'Comment successfully added';
87 87  
88 88 /**
89   - * @var string Entity, to which comments attached
  89 + * @var string $model Model, to which comments attached
90 90 */
91   - public $entity;
  91 + public $model;
  92 +
  93 + /**
  94 + * @var integer $model_id Model id, to which comments attached
  95 + */
  96 + public $model_id;
92 97  
93 98 /**
94 99 * @var string Template of the widget. You may use <code>{success}, {form}, {list}</code>
... ... @@ -123,7 +128,8 @@
123 128 } elseif(!empty( $this->rating_class )) {
124 129 throw new \yii\base\InvalidConfigException(__CLASS__ . '->rating_class must be defined as object full class name string.');
125 130 }
126   - $this->comment_class->entity = $this->entity;
  131 + $this->comment_class->model = $this->model;
  132 + $this->comment_class->model_id = $this->model_id;
127 133 $this->createDataProvider();
128 134 $this->process();
129 135 ob_start();
... ... @@ -171,7 +177,7 @@
171 177 public function createDataProvider()
172 178 {
173 179 $this->dataProvider = new \yii\data\ActiveDataProvider([
174   - 'query' => $this->comment_class->getComments($this->entity),
  180 + 'query' => $this->comment_class->getComments($this->model, $this->model_id),
175 181 'pagination' => [
176 182 'pageSize' => 10,
177 183 ],
... ...
console/migrations/m160311_132124_rating_comment_restyle.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m160311_132124_rating_comment_restyle extends Migration
  6 +{
  7 + public function up()
  8 + {
  9 + $this->truncateTable('{{%comment}}');
  10 + $this->truncateTable('{{%rating}}');
  11 + $this->dropColumn('{{%comment}}', 'entity');
  12 + $this->dropColumn('{{%rating}}', 'entity');
  13 + $this->addColumn('{{%comment}}', 'model', $this->string()->notNull());
  14 + $this->addColumn('{{%comment}}', 'model_id', $this->integer()->notNull());
  15 + $this->addColumn('{{%rating}}', 'model', $this->string()->notNull());
  16 + $this->addColumn('{{%rating}}', 'model_id', $this->integer()->notNull());
  17 + }
  18 +
  19 + public function down()
  20 + {
  21 + $this->truncateTable('{{%comment}}');
  22 + $this->truncateTable('{{%rating}}');
  23 + $this->dropColumn('{{%comment}}', 'model');
  24 + $this->dropColumn('{{%rating}}', 'model');
  25 + $this->dropColumn('{{%comment}}', 'model_id');
  26 + $this->dropColumn('{{%rating}}', 'model_id');
  27 + $this->addColumn('{{%comment}}', 'entity', $this->string()->notNull());
  28 + $this->addColumn('{{%rating}}', 'entity', $this->string()->notNull());
  29 + }
  30 +
  31 +}
... ...
console/migrations/m160311_151257_user_project_rating.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m160311_151257_user_project_rating extends Migration
  6 +{
  7 + public function up()
  8 + {
  9 + $this->addColumn('{{%user_info}}', 'rating', $this->float()->defaultValue(0));
  10 + $this->addColumn('{{%project}}', 'rating', $this->float()->defaultValue(0));
  11 + }
  12 +
  13 + public function down()
  14 + {
  15 + $this->dropColumn('{{%user_info}}', 'rating');
  16 + $this->dropColumn('{{%project}}', 'rating');
  17 + }
  18 +
  19 +}
... ...
frontend/controllers/SearchController.php
1 1 <?php
2   -namespace frontend\controllers;
3   -
4   -use common\models\CustomerSearch;
5   -use common\models\Project;
6   -use common\models\UserInfo;
7   -use common\models\Vacancy;
8   -use Yii;
9   -use common\models\LoginForm;
10   -use frontend\models\PasswordResetRequestForm;
11   -use frontend\models\ResetPasswordForm;
12   -use frontend\models\SignupForm;
13   -use frontend\models\ContactForm;
14   -use frontend\models\Options;
15   -use frontend\models\OptionValues;
16   -use yii\base\InvalidParamException;
17   -use yii\data\ActiveDataProvider;
18   -use yii\data\Pagination;
19   -use yii\web\BadRequestHttpException;
20   -use yii\web\Controller;
21   -use yii\filters\VerbFilter;
22   -use yii\filters\AccessControl;
23   -use frontend\models\OptionsToValues;
24   -use yii\validators\EmailValidator;
25   -use common\models\User;
26   -use yii\helpers\VarDumper;
27   -use common\models\Page;
28   -use frontend\models\Option;
29   -use common\models\Social;
30   -
31   -
32   -/**
33   - * Site controller
34   - */
35   -class SearchController extends Controller
36   -{
37   - public $defaultAction = 'common';
  2 + namespace frontend\controllers;
  3 +
  4 + use common\models\CustomerSearch;
  5 + use common\models\Project;
  6 + use common\models\UserInfo;
  7 + use common\models\Vacancy;
  8 + use Yii;
  9 + use common\models\LoginForm;
  10 + use frontend\models\PasswordResetRequestForm;
  11 + use frontend\models\ResetPasswordForm;
  12 + use frontend\models\SignupForm;
  13 + use frontend\models\ContactForm;
  14 + use frontend\models\Options;
  15 + use frontend\models\OptionValues;
  16 + use yii\base\InvalidParamException;
  17 + use yii\data\ActiveDataProvider;
  18 + use yii\data\Pagination;
  19 + use yii\web\BadRequestHttpException;
  20 + use yii\web\Controller;
  21 + use yii\filters\VerbFilter;
  22 + use yii\filters\AccessControl;
  23 + use frontend\models\OptionsToValues;
  24 + use yii\validators\EmailValidator;
  25 + use common\models\User;
  26 + use yii\helpers\VarDumper;
  27 + use common\models\Page;
  28 + use frontend\models\Option;
  29 + use common\models\Social;
38 30  
39 31 /**
40   - * @inheritdoc
  32 + * Site controller
41 33 */
42   - public function actions()
43   - {
44   - return [
45   - 'error' => [
46   - 'class' => 'yii\web\ErrorAction',
47   - ],
48   - 'captcha' => [
49   - 'class' => 'yii\captcha\CaptchaAction',
50   - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
51   - ],
52   - ];
53   - }
54   -
55   - public function actionProject()
  34 + class SearchController extends Controller
56 35 {
57 36  
58   - $projects = new ActiveDataProvider([
59   - 'query' => Project::find(),
60   - 'pagination' => [
61   - 'pageSize' => 9,
62   - ],
63   - ]);
64   -
65   - return $this->render('project',[
66   - 'projects' => $projects
67   - ]);
68   - }
  37 + public $defaultAction = 'common';
69 38  
70   -
71   - public function actionCustomer(){
72   - $model = new CustomerSearch();
73   - $dataProvider = $model->search(Yii::$app->request->queryParams);
74   - $dataProvider->setPagination([
75   - 'pageSize' => 5
76   - ]);
77   - $dataProvider->setSort([
78   - 'attributes' => [
79   - 'name' => [
80   - 'asc' => [
81   - 'company_info.name' => SORT_ASC,
82   - 'firstname' => SORT_ASC,
83   - 'lastname' => SORT_ASC,
84   - ],
85   - 'desc' => [
86   - 'company_info.name' => SORT_DESC,
87   - 'firstname' => SORT_DESC,
88   - 'lastname' => SORT_DESC,
89   - ],
90   - 'default' => SORT_ASC,
91   - 'label' => 'Название',
  39 + /**
  40 + * @inheritdoc
  41 + */
  42 + public function actions()
  43 + {
  44 + return [
  45 + 'error' => [
  46 + 'class' => 'yii\web\ErrorAction',
92 47 ],
93   - 'staff' => [
94   - 'asc' => [
95   - 'company_info.staff' => SORT_ASC,
96   - ],
97   - 'desc' => [
98   - 'company_info.staff' => SORT_DESC,
99   - ],
100   - 'default' => SORT_DESC,
101   - 'label' => 'Количество сотрудников',
  48 + 'captcha' => [
  49 + 'class' => 'yii\captcha\CaptchaAction',
  50 + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
  51 + ],
  52 + ];
  53 + }
  54 +
  55 + public function actionProject()
  56 + {
  57 + $projects = new ActiveDataProvider([
  58 + 'query' => Project::find(),
  59 + 'pagination' => [
  60 + 'pageSize' => 9,
  61 + ],
  62 + ]);
  63 + return $this->render('project', [
  64 + 'projects' => $projects,
  65 + ]);
  66 + }
  67 +
  68 + public function actionCustomer()
  69 + {
  70 + $model = new CustomerSearch();
  71 + $dataProvider = $model->search(Yii::$app->request->queryParams);
  72 + $dataProvider->setPagination([
  73 + 'pageSize' => 5,
  74 + ]);
  75 + $dataProvider->setSort([
  76 + 'defaultOrder' => [
  77 + 'name' => SORT_ASC,
102 78 ],
103   - 'visit' => [
104   - 'asc' => [
105   - 'user_info.date_visit' => SORT_ASC,
  79 + 'attributes' => [
  80 + 'name' => [
  81 + 'asc' => [
  82 + 'company_info.name' => SORT_ASC,
  83 + 'firstname' => SORT_ASC,
  84 + 'lastname' => SORT_ASC,
  85 + ],
  86 + 'desc' => [
  87 + 'company_info.name' => SORT_DESC,
  88 + 'firstname' => SORT_DESC,
  89 + 'lastname' => SORT_DESC,
  90 + ],
  91 + 'default' => SORT_ASC,
  92 + 'label' => 'Название',
106 93 ],
107   - 'desc' => [
108   - 'user_info.date_visit' => SORT_DESC,
  94 + 'staff' => [
  95 + 'asc' => [
  96 + 'company_info.staff' => SORT_ASC,
  97 + ],
  98 + 'desc' => [
  99 + 'company_info.staff' => SORT_DESC,
  100 + ],
  101 + 'default' => SORT_DESC,
  102 + 'label' => 'Количество сотрудников',
109 103 ],
110   - 'default' => SORT_DESC,
111   - 'label' => 'Последний визит',
112   - ],
113   - 'city' => [
114   - 'asc' => [
115   - 'user_info.city' => SORT_ASC,
  104 + 'visit' => [
  105 + 'asc' => [
  106 + 'user_info.date_visit' => SORT_ASC,
  107 + ],
  108 + 'desc' => [
  109 + 'user_info.date_visit' => SORT_DESC,
  110 + ],
  111 + 'default' => SORT_DESC,
  112 + 'label' => 'Последний визит',
116 113 ],
117   - 'desc' => [
118   - 'user_info.city' => SORT_DESC,
  114 + 'city' => [
  115 + 'asc' => [
  116 + 'user_info.city' => SORT_ASC,
  117 + ],
  118 + 'desc' => [
  119 + 'user_info.city' => SORT_DESC,
  120 + ],
  121 + 'default' => SORT_ASC,
  122 + 'label' => 'Город',
119 123 ],
120   - 'default' => SORT_ASC,
121   - 'label' => 'Город',
122 124 ],
123   - ],
124   - ]);
125   - $model->load(Yii::$app->request->queryParams);
126   - $cities = UserInfo::find()->select('city')->distinct()->asArray()->indexBy('city')->column();
127   - return $this->render('customer',[
128   - 'model' => $model,
129   - 'dataProvider' => $dataProvider,
130   - 'cities' => $cities,
131   - ]);
132   - }
133   -
134   - public function actionCompany()
135   - {
136   - $query = UserInfo::find()
137   - ->joinWith([ 'user' ])
138   - ->where(['is_customer' => 1,'user.type'=>2]);
139   -
140   - $companies = new ActiveDataProvider([
141   - 'query' => $query,
142   - 'pagination' => [
143   - 'pageSize' => 3,
144   - ],
145   - ]);
146   -
147   - return $this->render('company',[
148   - 'companies' => $companies
149   - ]);
150   - }
151   -
152   - public function actionPerformer()
153   - {
154   - $query = UserInfo::find()
155   - ->joinWith([ 'user' ])
156   - ->where(['is_customer' => 1,'user.type'=>1]);
157   -
158   -
159   - $performer = new ActiveDataProvider([
160   - 'query' => $query,
161   - 'pagination' => [
162   - 'pageSize' => 3,
163   - ],
164   - ]);
165   -
166   - return $this->render('performer',[
167   - 'performer' => $performer
168   - ]);
169   - }
170   -
171   - public function actionVacancy()
172   - {
173   -
  125 + ]);
  126 + $model->load(Yii::$app->request->queryParams);
  127 + $cities = UserInfo::find()
  128 + ->select('city')
  129 + ->distinct()
  130 + ->asArray()
  131 + ->indexBy('city')
  132 + ->column();
  133 + return $this->render('customer', [
  134 + 'model' => $model,
  135 + 'dataProvider' => $dataProvider,
  136 + 'cities' => $cities,
  137 + ]);
  138 + }
  139 +
  140 + public function actionCompany()
  141 + {
  142 + $query = UserInfo::find()
  143 + ->joinWith([ 'user' ])
  144 + ->where([
  145 + 'is_customer' => 1,
  146 + 'user.type' => 2,
  147 + ]);
  148 +
  149 + $companies = new ActiveDataProvider([
  150 + 'query' => $query,
  151 + 'pagination' => [
  152 + 'pageSize' => 3,
  153 + ],
  154 + ]);
  155 +
  156 + return $this->render('company', [
  157 + 'companies' => $companies,
  158 + ]);
  159 + }
  160 +
  161 + public function actionPerformer()
  162 + {
  163 + $query = UserInfo::find()
  164 + ->joinWith([ 'user' ])
  165 + ->where([
  166 + 'is_customer' => 1,
  167 + 'user.type' => 1,
  168 + ]);
  169 +
  170 + $performer = new ActiveDataProvider([
  171 + 'query' => $query,
  172 + 'pagination' => [
  173 + 'pageSize' => 3,
  174 + ],
  175 + ]);
174 176  
175   - $query = Vacancy::find();
  177 + return $this->render('performer', [
  178 + 'performer' => $performer,
  179 + ]);
  180 + }
176 181  
177   - $countQuery = clone $query;
  182 + public function actionVacancy()
  183 + {
178 184  
179   - $pagination = new Pagination(['totalCount' => $countQuery->count(),
180   - 'pageSize' => 15,
181   - ]);
  185 + $query = Vacancy::find();
182 186  
183   - $vacancy = $query->offset($pagination->offset)
184   - ->limit($pagination->limit);
  187 + $countQuery = clone $query;
185 188  
  189 + $pagination = new Pagination([
  190 + 'totalCount' => $countQuery->count(),
  191 + 'pageSize' => 15,
  192 + ]);
186 193  
187   - $provider = new ActiveDataProvider([
188   - 'query' => $vacancy,
189   - 'pagination' => false,
190   - 'sort' => [
191   - 'defaultOrder' => [
192   - 'date_add' => SORT_DESC,
193   - 'name' => SORT_ASC,
194   - ]
195   - ],
196   - ]);
  194 + $vacancy = $query->offset($pagination->offset)
  195 + ->limit($pagination->limit);
197 196  
  197 + $provider = new ActiveDataProvider([
  198 + 'query' => $vacancy,
  199 + 'pagination' => false,
  200 + 'sort' => [
  201 + 'defaultOrder' => [
  202 + 'date_add' => SORT_DESC,
  203 + 'name' => SORT_ASC,
  204 + ],
  205 + ],
  206 + ]);
198 207  
  208 + return $this->render('vacancy', [
  209 + 'provider' => $provider,
  210 + 'pagination' => $pagination,
  211 + ]);
  212 + }
199 213  
200   - return $this->render('vacancy',[
201   - 'provider' => $provider,
202   - 'pagination' => $pagination
203   - ]);
204 214 }
205   -
206   -}
... ...
frontend/views/performer/portfolio-view.php
... ... @@ -114,21 +114,22 @@
114 114 <?php
115 115 echo \common\modules\comment\widgets\CommentWidget::widget([
116 116 'context' => $this,
117   - 'entity' => $portfolio::tableName() . '-' . $portfolio->portfolio_id,
  117 + 'model' => $portfolio::className(),
  118 + 'model_id' => $portfolio->portfolio_id,
118 119 'comment_class' => \common\modules\comment\models\Comment::className(),
119   - 'rating_class' => \common\modules\comment\models\Rating::className(),
  120 + 'rating_class' => \common\modules\comment\models\Rating::className(),
120 121 'class_options' => [
121   - 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST,
122   - 'user_id' => \Yii::$app->user->getId(),
  122 + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST,
  123 + 'user_id' => \Yii::$app->user->getId(),
123 124 'guestComment' => true,
124   - 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE,
  125 + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE,
125 126 ],
126 127 'list_options' => [
127 128 'view' => 'list-comment',
128 129 ],
129 130 'form_options' => [
130   - 'view' => 'form-comment',
131   - 'tag' => 'div',
  131 + 'view' => 'form-comment',
  132 + 'tag' => 'div',
132 133 'class' => 'artbox_comment_form',
133 134 ],
134 135 'options' => [
... ...
frontend/views/search/_customer_list_view.php
... ... @@ -26,13 +26,12 @@
26 26 <div class="rating_search_performer">
27 27 <!--оценка-->
28 28 <?php
29   - if($rating = $model->getRatingPG()->rating) {
  29 + if($rating = $model->userInfo->rating) {
30 30 echo "<input type='hidden' class='val' value='{$rating}'/>";
31 31 } else {
32 32 echo "<input type='hidden' class='val' value='0'/>";
33 33 }
34 34 ?>
35   - <input type="hidden" class="val" value="4"/>
36 35 </div>
37 36 <div class="search_perform-stars-txt">
38 37 <?= $model->getComments()->count() ?> отзывов
... ...
frontend/views/search/customer.php
... ... @@ -11,16 +11,24 @@
11 11 use yii\widgets\LinkSorter;
12 12 use yii\widgets\ListView;
13 13  
  14 + $sort_array = $dataProvider->sort->getAttributeOrders();
  15 + $active_key = array_keys($sort_array)[ 0 ];
  16 + $active_value = $sort_array[ $active_key ];
  17 + $sort_name = ( ( $active_value == 4 ) ? '-' : '' ) . $active_key;
14 18 ?>
15 19 <div class="section-box-22 section-box-customer">
16 20 <div class="box-wr">
17 21 <div class="box-all">
18 22 <?php
19   - // == Left filter ==
  23 + // == Left filter ==
20 24 ?>
21 25 <div class="left-search-work">
22 26 <?php
23   - $form = ActiveForm::begin(['method' => 'get', 'options' => [ 'class' => 'search-work-form' ], 'action' => [''] ]);
  27 + $form = ActiveForm::begin([
  28 + 'method' => 'get',
  29 + 'options' => [ 'class' => 'search-work-form' ],
  30 + 'action' => [ '' ],
  31 + ]);
24 32  
25 33 echo $form->field($model, 'city', [
26 34 'options' => [
... ... @@ -41,20 +49,24 @@
41 49 2 => 'Компания',
42 50 ], [ 'prompt' => 'Любой' ]);
43 51 ?>
44   -
45   - <?php
46   - /* Рейтинг
47   - ?>
48   - <div class="blocks-check-list-wrapp">
49   - <div class="blocks-check-title">Рейтинг</div>
50   - <div class="rating">
51   - <!--оценка-->
52   - <input type="hidden" class="val" value="0">
53   - </div>
  52 + <div class="blocks-check-list-wrapp">
  53 + <div class="blocks-check-title">Рейтинг</div>
  54 + <div class="">
  55 + <?php
  56 + echo $form->field($model, 'rating')
  57 + ->label(false)
  58 + ->radioList([
  59 + '' => 'Все',
  60 + 0 => 0,
  61 + 1 => 1,
  62 + 2 => 2,
  63 + 3 => 3,
  64 + 4 => 4,
  65 + 5 => 5,
  66 + ]);
  67 + ?>
54 68 </div>
55   - <?php
56   - */
57   - ?>
  69 + </div>
58 70  
59 71 <?php
60 72 echo $form->field($model, 'online', [
... ... @@ -68,31 +80,31 @@
68 80 1 => 'Онлайн',
69 81 ], [
70 82 'item' => function($index, $label, $name, $checked, $value) use ($model) {
71   - $checked = ($model->online == $value);
72   - return "<div class='blocks-check-list'><input type='radio' id='{$model->formName()}-{$index}' name='{$name}' class='check-search' value='{$value}' " . ($checked?'checked':'') . "><label for='{$model->formName()}-{$index}'><span></span>{$label}</label></div>";
  83 + $checked = ( $model->online == $value );
  84 + return "<div class='blocks-check-list'><input type='radio' id='{$model->formName()}-{$index}' name='{$name}' class='check-search' value='{$value}' " . ( $checked ? 'checked' : '' ) . "><label for='{$model->formName()}-{$index}'><span></span>{$label}</label></div>";
73 85 },
74 86 'unselect' => NULL,
75 87 ]);
76 88  
77   - echo '<div class="blocks-check-list-submit">'.Html::submitInput('Найти').'</div>';
  89 + echo '<div class="blocks-check-list-submit">' . Html::submitInput('Найти') . '</div>';
78 90  
79 91 $form->end();
80 92 ?>
81 93 <script>
82 94 $('div.rating').rating(
83 95 {
84   - fx : 'full', url : 'rating.php'
  96 + fx : 'full',
85 97 }
86 98 );
87 99 </script>
88 100 </div>
89 101  
90 102 <?php
91   - // == End of left filter ==
  103 + // == End of left filter ==
92 104 ?>
93 105  
94 106 <?php
95   - // == Page content ==
  107 + // == Page content ==
96 108 ?>
97 109 <div class="right-search-work">
98 110 <div class="search-worker-title style">Найти заказчика</div>
... ... @@ -100,17 +112,23 @@
100 112 <span><?= $dataProvider->totalCount ?></span></div>
101 113 <div class="search-worker-search-wr style">
102 114 <?php
103   - $form2 = ActiveForm::begin(['method' => 'get', 'action' => [''], 'options' => ['class' => 'search-worker-form']]);
104   - echo $form2->field($model, 'info', ['options' => ['tag' => false]])->label(false)->textInput(['placeholder' => $model->getAttributeLabel('info')]);
  115 + $form2 = ActiveForm::begin([
  116 + 'method' => 'get',
  117 + 'action' => [ '' ],
  118 + 'options' => [ 'class' => 'search-worker-form' ],
  119 + ]);
  120 + echo $form2->field($model, 'info', [ 'options' => [ 'tag' => false ] ])
  121 + ->label(false)
  122 + ->textInput([ 'placeholder' => $model->getAttributeLabel('info') ]);
105 123 echo Html::submitInput('Найти');
106   - $form2->end();
  124 + $form2->end();
107 125 ?>
108 126 <a href="#" class="add-to-catalog-search-worker">Добавить себя в каталог</a>
109 127 <div class="search-worker-sort-wr style">
110 128 <div class="search-worker-sort">Сортировать:&nbsp;</div>
111 129 <ul>
112 130 <li class="activejob">
113   - <a href="#"></a>
  131 + <a href="#" data-sort-name="<?= $sort_name ?>"></a>
114 132 <div class="sidebar-droped-wr style">
115 133 <?php
116 134 echo LinkSorter::widget([
... ... @@ -123,147 +141,147 @@
123 141 </div>
124 142 </div>
125 143 <?php
126   - echo ListView::widget([
127   - 'dataProvider' => $dataProvider,
128   - 'layout' => "{items}\n{pager}",
129   - 'options' => [
130   - 'class' => 'search-worker-blocks-wr style',
131   - ],
132   - 'itemOptions' => [
133   - 'class' => 'search-worker-blocks',
134   - ],
135   - 'itemView' => '_customer_list_view',
136   - ]);
  144 + echo ListView::widget([
  145 + 'dataProvider' => $dataProvider,
  146 + 'layout' => "{items}\n{pager}",
  147 + 'options' => [
  148 + 'class' => 'search-worker-blocks-wr style',
  149 + ],
  150 + 'itemOptions' => [
  151 + 'class' => 'search-worker-blocks',
  152 + ],
  153 + 'itemView' => '_customer_list_view',
  154 + ]);
137 155 ?>
138 156 <?php
139   - /* == Layout ==
140   - ?>
141   - <div class="search-worker-blocks-wr style">
  157 + /* == Layout ==
  158 + ?>
  159 + <div class="search-worker-blocks-wr style">
142 160  
143   - <div class="search-worker-blocks">
144   - <div class="search_perform_txt-wr">
145   - <div class="search_perform_title">ООО «Ортекс»</div>
146   - <div class="search_perform-stars-wr">
147   - <div class="rating_search_performer">
148   - <!--оценка-->
149   - <input type="hidden" class="val" value="4"/>
  161 + <div class="search-worker-blocks">
  162 + <div class="search_perform_txt-wr">
  163 + <div class="search_perform_title">ООО «Ортекс»</div>
  164 + <div class="search_perform-stars-wr">
  165 + <div class="rating_search_performer">
  166 + <!--оценка-->
  167 + <input type="hidden" class="val" value="4"/>
  168 + </div>
  169 + <div class="search_perform-stars-txt">30 отзывов, Киев</div>
150 170 </div>
151   - <div class="search_perform-stars-txt">30 отзывов, Киев</div>
152   - </div>
153   - <div class="search_perform_leng">
154   - <div>Сотрудники: более 40</div>
155   - </div>
156   - <div class="search_perform_visit">
157   - <span>Послелний визит:</span> 2 дня назад
  171 + <div class="search_perform_leng">
  172 + <div>Сотрудники: более 40</div>
  173 + </div>
  174 + <div class="search_perform_visit">
  175 + <span>Послелний визит:</span> 2 дня назад
  176 + </div>
  177 + <div class="search_perform_projets_nam">
  178 + <a href="#">Заказано проектов: 21</a></div>
158 179 </div>
159   - <div class="search_perform_projets_nam">
160   - <a href="#">Заказано проектов: 21</a></div>
161   - </div>
162 180  
163   - <div class="right_search_perform_block-wr">
164   - <div class="right_search_perform_foto-wr">
165   - <div><img src="/images/search_performer_img-1.jpg" alt=""/></div>
  181 + <div class="right_search_perform_block-wr">
  182 + <div class="right_search_perform_foto-wr">
  183 + <div><img src="/images/search_performer_img-1.jpg" alt=""/></div>
  184 + </div>
  185 + <a class="get-list" href="#">Добавить в закладки</a>
166 186 </div>
167   - <a class="get-list" href="#">Добавить в закладки</a>
168 187 </div>
169   - </div>
170 188  
171   - <div class="search-worker-blocks">
172   - <div class="search_perform_txt-wr">
173   - <div class="search_perform_title">Петер Цумтор</div>
174   - <div class="search_perform-stars-wr">
175   - <div class="rating_search_performer">
176   - <!--оценка-->
177   - <input type="hidden" class="val" value="2"/>
  189 + <div class="search-worker-blocks">
  190 + <div class="search_perform_txt-wr">
  191 + <div class="search_perform_title">Петер Цумтор</div>
  192 + <div class="search_perform-stars-wr">
  193 + <div class="rating_search_performer">
  194 + <!--оценка-->
  195 + <input type="hidden" class="val" value="2"/>
  196 + </div>
  197 + <div class="search_perform-stars-txt">30 отзывов, Киев</div>
178 198 </div>
179   - <div class="search_perform-stars-txt">30 отзывов, Киев</div>
180   - </div>
181   - <div class="search_perform_leng">
182   - <!--<div>Сотрудники: более 40</div>-->
183   - </div>
184   - <div class="search_perform_visit">
185   - <span>Послелний визит:</span> 2 дня назад
  199 + <div class="search_perform_leng">
  200 + <!--<div>Сотрудники: более 40</div>-->
  201 + </div>
  202 + <div class="search_perform_visit">
  203 + <span>Послелний визит:</span> 2 дня назад
  204 + </div>
  205 + <div class="search_perform_projets_nam">
  206 + <a href="#">Заказано проектов: 21</a></div>
186 207 </div>
187   - <div class="search_perform_projets_nam">
188   - <a href="#">Заказано проектов: 21</a></div>
189   - </div>
190 208  
191   - <div class="right_search_perform_block-wr">
192   - <div class="right_search_perform_foto-wr">
193   - <div><a href="#"><img src="/images/ded-ico.png" alt=""/></a></div>
  209 + <div class="right_search_perform_block-wr">
  210 + <div class="right_search_perform_foto-wr">
  211 + <div><a href="#"><img src="/images/ded-ico.png" alt=""/></a></div>
  212 + </div>
  213 + <a class="get-list" href="#">Добавить в закладки</a>
194 214 </div>
195   - <a class="get-list" href="#">Добавить в закладки</a>
196 215 </div>
197   - </div>
198 216  
199   - <div class="search-worker-blocks">
200   - <div class="search_perform_txt-wr">
201   - <div class="search_perform_title">ООО «Ортекс»</div>
202   - <div class="search_perform-stars-wr">
203   - <div class="rating_search_performer">
204   - <!--оценка-->
205   - <input type="hidden" class="val" value="1"/>
  217 + <div class="search-worker-blocks">
  218 + <div class="search_perform_txt-wr">
  219 + <div class="search_perform_title">ООО «Ортекс»</div>
  220 + <div class="search_perform-stars-wr">
  221 + <div class="rating_search_performer">
  222 + <!--оценка-->
  223 + <input type="hidden" class="val" value="1"/>
  224 + </div>
  225 + <div class="search_perform-stars-txt">30 отзывов, Киев</div>
206 226 </div>
207   - <div class="search_perform-stars-txt">30 отзывов, Киев</div>
208   - </div>
209   - <div class="search_perform_leng">
210   - <div>Сотрудники: более 40</div>
211   - </div>
212   - <div class="search_perform_visit">
213   - <span>Послелний визит:</span> 2 дня назад
  227 + <div class="search_perform_leng">
  228 + <div>Сотрудники: более 40</div>
  229 + </div>
  230 + <div class="search_perform_visit">
  231 + <span>Послелний визит:</span> 2 дня назад
  232 + </div>
  233 + <div class="search_perform_projets_nam">
  234 + <a href="#">Заказано проектов: 21</a></div>
214 235 </div>
215   - <div class="search_perform_projets_nam">
216   - <a href="#">Заказано проектов: 21</a></div>
217   - </div>
218 236  
219   - <div class="right_search_perform_block-wr">
220   - <div class="right_search_perform_foto-wr">
221   - <div><img src="/images/search_performer_img-1.jpg" alt=""/></div>
  237 + <div class="right_search_perform_block-wr">
  238 + <div class="right_search_perform_foto-wr">
  239 + <div><img src="/images/search_performer_img-1.jpg" alt=""/></div>
  240 + </div>
  241 + <a class="get-list" href="#">Добавить в закладки</a>
222 242 </div>
223   - <a class="get-list" href="#">Добавить в закладки</a>
224 243 </div>
225   - </div>
226 244  
227   - <div class="search-worker-blocks">
228   - <div class="search_perform_txt-wr">
229   - <div class="search_perform_title">Петер Цумтор</div>
230   - <div class="search_perform-stars-wr">
231   - <div class="rating_search_performer">
232   - <!--оценка-->
233   - <input type="hidden" class="val" value="5"/>
  245 + <div class="search-worker-blocks">
  246 + <div class="search_perform_txt-wr">
  247 + <div class="search_perform_title">Петер Цумтор</div>
  248 + <div class="search_perform-stars-wr">
  249 + <div class="rating_search_performer">
  250 + <!--оценка-->
  251 + <input type="hidden" class="val" value="5"/>
  252 + </div>
  253 + <div class="search_perform-stars-txt">30 отзывов, Киев</div>
234 254 </div>
235   - <div class="search_perform-stars-txt">30 отзывов, Киев</div>
236   - </div>
237   - <div class="search_perform_leng">
238   - <!--<div>Сотрудники: более 40</div>-->
239   - </div>
240   - <div class="search_perform_visit">
241   - <span>Послелний визит:</span> 2 дня назад
  255 + <div class="search_perform_leng">
  256 + <!--<div>Сотрудники: более 40</div>-->
  257 + </div>
  258 + <div class="search_perform_visit">
  259 + <span>Послелний визит:</span> 2 дня назад
  260 + </div>
  261 + <div class="search_perform_projets_nam">
  262 + <a href="#">Заказано проектов: 21</a></div>
242 263 </div>
243   - <div class="search_perform_projets_nam">
244   - <a href="#">Заказано проектов: 21</a></div>
245   - </div>
246 264  
247   - <div class="right_search_perform_block-wr">
248   - <div class="right_search_perform_foto-wr">
249   - <div><img src="/images/ded-ico.png" alt=""/></div>
  265 + <div class="right_search_perform_block-wr">
  266 + <div class="right_search_perform_foto-wr">
  267 + <div><img src="/images/ded-ico.png" alt=""/></div>
  268 + </div>
  269 + <a class="get-list" href="#">Добавить в закладки</a>
250 270 </div>
251   - <a class="get-list" href="#">Добавить в закладки</a>
252 271 </div>
253 272 </div>
254   - </div>
255 273  
256   - <div class="navi-buttons-wr style">
257   - <ul class="pagination">
258   - <li class="prev disabled"><span>«</span></li>
259   - <li class="active"><a href="#">1</a></li>
260   - <li><a href="#">2</a></li>
261   - <li class="next"><a href="#">»</a></li>
262   - </ul>
263   - </div>
  274 + <div class="navi-buttons-wr style">
  275 + <ul class="pagination">
  276 + <li class="prev disabled"><span>«</span></li>
  277 + <li class="active"><a href="#">1</a></li>
  278 + <li><a href="#">2</a></li>
  279 + <li class="next"><a href="#">»</a></li>
  280 + </ul>
  281 + </div>
264 282  
265   - <?php
266   - == End of layout == */
  283 + <?php
  284 + == End of layout == */
267 285 ?>
268 286  
269 287 <script>
... ... @@ -275,7 +293,7 @@
275 293 </script>
276 294 </div>
277 295 <?php
278   - // == End of page content ==
  296 + // == End of page content ==
279 297 ?>
280 298 </div>
281 299 </div>
... ...
frontend/web/css/style.css
... ... @@ -6594,7 +6594,6 @@ input[disabled], select[disabled] {
6594 6594 }
6595 6595  
6596 6596 /***/
6597   -.sidebar-droped-wr ul li:first-child {display: none;}
6598 6597 .right_search_perform_foto-wr {width: 140px;height: 93px;float: left;margin-left: 16px;}
6599 6598 .right_search_perform_foto-wr>div{width: 140px;height: 93px; display: table-cell; vertical-align: middle; text-align: center}
6600 6599 .right_search_perform_foto-wr>div{max-width: 140px;max-height: 93px; vertical-align: middle}
... ...
frontend/web/js/script.js
... ... @@ -490,8 +490,17 @@ $(document).ready(function(){
490 490 //}
491 491  
492 492 function jobClick(){
493   - $('.activejob a').click(function(e){
  493 +
  494 + var container = $('.search-worker-sort-wr');
  495 + var sort = $(container).find('.activejob a[data-sort-name]').data('sort-name');
  496 + var active = $(container).find('ul.sorter a[data-sort='+sort+']').clone();
  497 + $(container).find('.activejob a[data-sort-name]').replaceWith(active);
  498 +
  499 + $('.activejob>a').click(function(e) {
494 500 e.preventDefault();
  501 + });
  502 +
  503 + $('.activejob a').click(function(e){
495 504 $('.sidebar-droped-wr').toggleClass('act')
496 505 $('.performance-vacancy-sidebar-company-job>ul').addClass('active-dropped-ul')
497 506 if( !($('.sidebar-droped-wr').hasClass('act')) ) {
... ...