Commit 4ed1f78831ce6c4c5916123f79ea391ef4dcbe9e

Authored by Yarik
1 parent f94a00a6

test

common/models/User.php
1 <?php 1 <?php
2 namespace common\models; 2 namespace common\models;
3 3
  4 + use common\modules\comment\models\Comment;
  5 + use common\modules\comment\models\Rating;
4 use Yii; 6 use Yii;
  7 + use yii\base\InvalidConfigException;
5 use yii\base\NotSupportedException; 8 use yii\base\NotSupportedException;
6 use yii\behaviors\TimestampBehavior; 9 use yii\behaviors\TimestampBehavior;
7 use yii\db\ActiveQuery; 10 use yii\db\ActiveQuery;
@@ -13,17 +16,18 @@ @@ -13,17 +16,18 @@
13 16
14 /** 17 /**
15 * User model 18 * User model
16 - * @property integer $id  
17 - * @property string $username  
18 - * @property string $password_hash  
19 - * @property string $password_reset_token  
20 - * @property string $email  
21 - * @property string $auth_key  
22 - * @property integer $status  
23 - * @property integer $created_at  
24 - * @property integer $updated_at  
25 - * @property string $password write-only password  
26 - * @property string $type 19 + * @property integer $id
  20 + * @property string $username
  21 + * @property string $password_hash
  22 + * @property string $password_reset_token
  23 + * @property string $email
  24 + * @property string $auth_key
  25 + * @property integer $status
  26 + * @property integer $created_at
  27 + * @property integer $updated_at
  28 + * @property string $password write-only password
  29 + * @property string $type
  30 + * @property UserInfo $userInfo
27 */ 31 */
28 class User extends ActiveRecord implements IdentityInterface, UserRbacInterface 32 class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
29 { 33 {
@@ -57,9 +61,6 @@ @@ -57,9 +61,6 @@
57 ]; 61 ];
58 } 62 }
59 63
60 -  
61 -  
62 -  
63 /** 64 /**
64 * @inheritdoc 65 * @inheritdoc
65 */ 66 */
@@ -93,7 +94,7 @@ @@ -93,7 +94,7 @@
93 [ 94 [
94 'specializationInput', 95 'specializationInput',
95 'paymentInput', 96 'paymentInput',
96 - 'type' 97 + 'type',
97 ], 98 ],
98 'safe', 99 'safe',
99 ], 100 ],
@@ -101,7 +102,7 @@ @@ -101,7 +102,7 @@
101 'type', 102 'type',
102 'default', 103 'default',
103 'value' => 1, 104 'value' => 1,
104 - ] 105 + ],
105 ]; 106 ];
106 } 107 }
107 108
@@ -112,8 +113,8 @@ @@ -112,8 +113,8 @@
112 { 113 {
113 return [ 114 return [
114 'firstname' => Yii::t('app', 'Имя'), 115 'firstname' => Yii::t('app', 'Имя'),
115 - 'lastname' => Yii::t('app', 'Фамилия'),  
116 - 'email' => Yii::t('app', 'Email'), 116 + 'lastname' => Yii::t('app', 'Фамилия'),
  117 + 'email' => Yii::t('app', 'Email'),
117 ]; 118 ];
118 } 119 }
119 120
@@ -348,7 +349,8 @@ @@ -348,7 +349,8 @@
348 */ 349 */
349 public function getUserInfo() 350 public function getUserInfo()
350 { 351 {
351 - return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ])->inverseOf('user'); 352 + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ])
  353 + ->inverseOf('user');
352 } 354 }
353 355
354 /** 356 /**
@@ -408,11 +410,11 @@ @@ -408,11 +410,11 @@
408 $date1 = new \DateTime(date('Y-m-d H:i:s', $this->created_at)); 410 $date1 = new \DateTime(date('Y-m-d H:i:s', $this->created_at));
409 $result = explode(',', \Yii::$app->formatter->asDuration($date1->diff($now))); 411 $result = explode(',', \Yii::$app->formatter->asDuration($date1->diff($now)));
410 412
411 - if($result >= 4){ 413 + if($result >= 4) {
412 array_splice($result, 2); 414 array_splice($result, 2);
413 } 415 }
414 416
415 - return implode(',',$result); 417 + return implode(',', $result);
416 } 418 }
417 419
418 /** 420 /**
@@ -549,7 +551,8 @@ @@ -549,7 +551,8 @@
549 */ 551 */
550 public function getVacancies() 552 public function getVacancies()
551 { 553 {
552 - return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ])->inverseOf('user'); 554 + return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ])
  555 + ->inverseOf('user');
553 } 556 }
554 557
555 public function getGalleries() 558 public function getGalleries()
@@ -559,22 +562,44 @@ @@ -559,22 +562,44 @@
559 562
560 public function getOwner() 563 public function getOwner()
561 { 564 {
562 - if($this->type == 1){  
563 - return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]);  
564 - } else if($this->type == 2) { 565 + if($this->type == 2) {
565 return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); 566 return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]);
  567 + } else {
  568 + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]);
566 } 569 }
567 -  
568 } 570 }
569 571
570 - public function getName(){  
571 - if($this->type == 1){  
572 - return $this->firstname. ' '.$this->lastname;  
573 - } else if($this->type == 2){ 572 + public function getName()
  573 + {
  574 + if($this->type == 2) {
574 return $this->companyInfo->name; 575 return $this->companyInfo->name;
  576 + } else {
  577 + return $this->firstname . ' ' . $this->lastname;
575 } 578 }
  579 + }
576 580
  581 + public function getComments()
  582 + {
  583 + $entity = 'user-' . $this->id;
  584 + $comments = (new Comment())->getComments($entity);
  585 + return $comments;
577 } 586 }
578 587
  588 + public function getRatingPG()
  589 + {
  590 + if(\Yii::$app->db->driverName != 'pgsql') {
  591 + throw new InvalidConfigException('This method is available only in PostgreSQL');
  592 + }
  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;
  603 + }
579 604
580 } 605 }
common/modules/comment/models/Comment.php
1 <?php 1 <?php
2 namespace common\modules\comment\models; 2 namespace common\modules\comment\models;
3 3
  4 + use yii\db\ActiveQuery;
  5 +
4 /** 6 /**
5 * Class Comment 7 * Class Comment
6 * @property bool $guestComment 8 * @property bool $guestComment
@@ -19,6 +21,8 @@ @@ -19,6 +21,8 @@
19 const SCENARIO_USER = 'user'; 21 const SCENARIO_USER = 'user';
20 const SCENARIO_GUEST = 'guest'; 22 const SCENARIO_GUEST = 'guest';
21 23
  24 + public $rating;
  25 +
22 /** 26 /**
23 * @var bool 27 * @var bool
24 */ 28 */
@@ -130,12 +134,17 @@ @@ -130,12 +134,17 @@
130 $this->guestComment = $value; 134 $this->guestComment = $value;
131 } 135 }
132 136
  137 + /**
  138 + * @param string $entity
  139 + *
  140 + * @return ActiveQuery
  141 + */
133 public function getComments($entity) 142 public function getComments($entity)
134 { 143 {
135 return $this->find() 144 return $this->find()
136 ->where([ 145 ->where([
137 - 'entity' => $this->entity,  
138 - 'status' => 1, 146 + 'comment.entity' => $entity,
  147 + 'comment.status' => 1,
139 ]); 148 ]);
140 } 149 }
141 150
frontend/controllers/SearchController.php
@@ -71,6 +71,9 @@ class SearchController extends Controller @@ -71,6 +71,9 @@ class SearchController extends Controller
71 public function actionCustomer(){ 71 public function actionCustomer(){
72 $model = new CustomerSearch(); 72 $model = new CustomerSearch();
73 $dataProvider = $model->search(Yii::$app->request->queryParams); 73 $dataProvider = $model->search(Yii::$app->request->queryParams);
  74 + $dataProvider->setPagination([
  75 + 'pageSize' => 5
  76 + ]);
74 $dataProvider->setSort([ 77 $dataProvider->setSort([
75 'attributes' => [ 78 'attributes' => [
76 'name' => [ 79 'name' => [
frontend/views/search/_customer_list_view.php
@@ -5,30 +5,37 @@ @@ -5,30 +5,37 @@
5 * @var integer $index 5 * @var integer $index
6 * @var ListView $widget 6 * @var ListView $widget
7 */ 7 */
  8 + use common\models\Project;
8 use common\models\User; 9 use common\models\User;
9 use frontend\helpers\TextHelper; 10 use frontend\helpers\TextHelper;
10 use yii\bootstrap\Html; 11 use yii\bootstrap\Html;
11 use yii\helpers\Url; 12 use yii\helpers\Url;
12 use yii\widgets\ListView; 13 use yii\widgets\ListView;
13 -  
14 ?> 14 ?>
15 <div class="search_perform_txt-wr"> 15 <div class="search_perform_txt-wr">
16 <div class="search_perform_title"> 16 <div class="search_perform_title">
17 <?php 17 <?php
18 if($model->type == 2) { 18 if($model->type == 2) {
19 - echo $model->companyInfo->name; 19 + echo Html::a($model->companyInfo->name, ['company/common', 'company_id' => $model->id]);
20 } else { 20 } else {
21 - echo $model->firstname . $model->lastname; 21 + echo Html::a($model->firstname . $model->lastname, ['performer/common', 'performer_id' => $model->id]);
22 } 22 }
23 ?> 23 ?>
24 </div> 24 </div>
25 <div class="search_perform-stars-wr"> 25 <div class="search_perform-stars-wr">
26 <div class="rating_search_performer"> 26 <div class="rating_search_performer">
27 <!--оценка--> 27 <!--оценка-->
  28 + <?php
  29 + if($rating = $model->getRatingPG()->rating) {
  30 + echo "<input type='hidden' class='val' value='{$rating}'/>";
  31 + } else {
  32 + echo "<input type='hidden' class='val' value='0'/>";
  33 + }
  34 + ?>
28 <input type="hidden" class="val" value="4"/> 35 <input type="hidden" class="val" value="4"/>
29 </div> 36 </div>
30 <div class="search_perform-stars-txt"> 37 <div class="search_perform-stars-txt">
31 - 30 отзывов 38 + <?= $model->getComments()->count() ?> отзывов
32 <?php 39 <?php
33 if(!empty( $model->userInfo->city )) { 40 if(!empty( $model->userInfo->city )) {
34 echo ", {$model->userInfo->city}"; 41 echo ", {$model->userInfo->city}";
@@ -49,12 +56,17 @@ @@ -49,12 +56,17 @@
49 <span>Послелний визит:</span> <?= \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit) ?> 56 <span>Послелний визит:</span> <?= \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit) ?>
50 </div> 57 </div>
51 <div class="search_perform_projets_nam"> 58 <div class="search_perform_projets_nam">
52 - <a href="#">Заказано проектов: 21</a></div> 59 + <?= Html::a("Заказано проектов {$model->getProjects()->count()}", ['search/project', (new Project())->formName().'[user_id]' => $model->id]) ?>
  60 + </div>
53 </div> 61 </div>
54 62
55 <div class="right_search_perform_block-wr"> 63 <div class="right_search_perform_block-wr">
56 <div class="right_search_perform_foto-wr"> 64 <div class="right_search_perform_foto-wr">
57 - <div><img src="/images/search_performer_img-1.jpg" alt=""/></div> 65 + <div>
  66 + <?php
  67 + echo Html::img($model->userInfo->image?:"/images/search_performer_img-1.jpg", ['class' => 'search_customer_image']);
  68 + ?>
  69 + </div>
58 </div> 70 </div>
59 <a class="get-list" href="#">Добавить в закладки</a> 71 <a class="get-list" href="#">Добавить в закладки</a>
60 </div> 72 </div>
61 \ No newline at end of file 73 \ No newline at end of file
frontend/views/search/customer.php
@@ -135,6 +135,9 @@ @@ -135,6 +135,9 @@
135 'itemView' => '_customer_list_view', 135 'itemView' => '_customer_list_view',
136 ]); 136 ]);
137 ?> 137 ?>
  138 + <?php
  139 + /* == Layout ==
  140 + ?>
138 <div class="search-worker-blocks-wr style"> 141 <div class="search-worker-blocks-wr style">
139 142
140 <div class="search-worker-blocks"> 143 <div class="search-worker-blocks">
@@ -259,6 +262,10 @@ @@ -259,6 +262,10 @@
259 </ul> 262 </ul>
260 </div> 263 </div>
261 264
  265 + <?php
  266 + == End of layout == */
  267 + ?>
  268 +
262 <script> 269 <script>
263 $('div.rating_search_performer').rating( 270 $('div.rating_search_performer').rating(
264 { 271 {
frontend/web/css/style.css
@@ -6677,4 +6677,7 @@ input[disabled], select[disabled] { @@ -6677,4 +6677,7 @@ input[disabled], select[disabled] {
6677 } 6677 }
6678 .form_site_logn-wr input.custom-check + label span {margin-top: 1px; margin-right: 6px} 6678 .form_site_logn-wr input.custom-check + label span {margin-top: 1px; margin-right: 6px}
6679 .callback .input-blocks-wrapper {margin-top: 0} 6679 .callback .input-blocks-wrapper {margin-top: 0}
6680 -.list_item.title {margin-top: 20px}  
6681 \ No newline at end of file 6680 \ No newline at end of file
  6681 +.list_item.title {margin-top: 20px}
  6682 +.search_customer_image {
  6683 + height: 100%;
  6684 +}
6682 \ No newline at end of file 6685 \ No newline at end of file