Commit 4ed1f78831ce6c4c5916123f79ea391ef4dcbe9e
1 parent
f94a00a6
test
Showing
6 changed files
with
98 additions
and
39 deletions
Show diff stats
common/models/User.php
| 1 | 1 | <?php |
| 2 | 2 | namespace common\models; |
| 3 | 3 | |
| 4 | + use common\modules\comment\models\Comment; | |
| 5 | + use common\modules\comment\models\Rating; | |
| 4 | 6 | use Yii; |
| 7 | + use yii\base\InvalidConfigException; | |
| 5 | 8 | use yii\base\NotSupportedException; |
| 6 | 9 | use yii\behaviors\TimestampBehavior; |
| 7 | 10 | use yii\db\ActiveQuery; |
| ... | ... | @@ -13,17 +16,18 @@ |
| 13 | 16 | |
| 14 | 17 | /** |
| 15 | 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 | 32 | class User extends ActiveRecord implements IdentityInterface, UserRbacInterface |
| 29 | 33 | { |
| ... | ... | @@ -57,9 +61,6 @@ |
| 57 | 61 | ]; |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | - | |
| 61 | - | |
| 62 | - | |
| 63 | 64 | /** |
| 64 | 65 | * @inheritdoc |
| 65 | 66 | */ |
| ... | ... | @@ -93,7 +94,7 @@ |
| 93 | 94 | [ |
| 94 | 95 | 'specializationInput', |
| 95 | 96 | 'paymentInput', |
| 96 | - 'type' | |
| 97 | + 'type', | |
| 97 | 98 | ], |
| 98 | 99 | 'safe', |
| 99 | 100 | ], |
| ... | ... | @@ -101,7 +102,7 @@ |
| 101 | 102 | 'type', |
| 102 | 103 | 'default', |
| 103 | 104 | 'value' => 1, |
| 104 | - ] | |
| 105 | + ], | |
| 105 | 106 | ]; |
| 106 | 107 | } |
| 107 | 108 | |
| ... | ... | @@ -112,8 +113,8 @@ |
| 112 | 113 | { |
| 113 | 114 | return [ |
| 114 | 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 | 349 | */ |
| 349 | 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 | 410 | $date1 = new \DateTime(date('Y-m-d H:i:s', $this->created_at)); |
| 409 | 411 | $result = explode(',', \Yii::$app->formatter->asDuration($date1->diff($now))); |
| 410 | 412 | |
| 411 | - if($result >= 4){ | |
| 413 | + if($result >= 4) { | |
| 412 | 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 | 551 | */ |
| 550 | 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 | 558 | public function getGalleries() |
| ... | ... | @@ -559,22 +562,44 @@ |
| 559 | 562 | |
| 560 | 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 | 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 | 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 | 1 | <?php |
| 2 | 2 | namespace common\modules\comment\models; |
| 3 | 3 | |
| 4 | + use yii\db\ActiveQuery; | |
| 5 | + | |
| 4 | 6 | /** |
| 5 | 7 | * Class Comment |
| 6 | 8 | * @property bool $guestComment |
| ... | ... | @@ -19,6 +21,8 @@ |
| 19 | 21 | const SCENARIO_USER = 'user'; |
| 20 | 22 | const SCENARIO_GUEST = 'guest'; |
| 21 | 23 | |
| 24 | + public $rating; | |
| 25 | + | |
| 22 | 26 | /** |
| 23 | 27 | * @var bool |
| 24 | 28 | */ |
| ... | ... | @@ -130,12 +134,17 @@ |
| 130 | 134 | $this->guestComment = $value; |
| 131 | 135 | } |
| 132 | 136 | |
| 137 | + /** | |
| 138 | + * @param string $entity | |
| 139 | + * | |
| 140 | + * @return ActiveQuery | |
| 141 | + */ | |
| 133 | 142 | public function getComments($entity) |
| 134 | 143 | { |
| 135 | 144 | return $this->find() |
| 136 | 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 | 71 | public function actionCustomer(){ |
| 72 | 72 | $model = new CustomerSearch(); |
| 73 | 73 | $dataProvider = $model->search(Yii::$app->request->queryParams); |
| 74 | + $dataProvider->setPagination([ | |
| 75 | + 'pageSize' => 5 | |
| 76 | + ]); | |
| 74 | 77 | $dataProvider->setSort([ |
| 75 | 78 | 'attributes' => [ |
| 76 | 79 | 'name' => [ | ... | ... |
frontend/views/search/_customer_list_view.php
| ... | ... | @@ -5,30 +5,37 @@ |
| 5 | 5 | * @var integer $index |
| 6 | 6 | * @var ListView $widget |
| 7 | 7 | */ |
| 8 | + use common\models\Project; | |
| 8 | 9 | use common\models\User; |
| 9 | 10 | use frontend\helpers\TextHelper; |
| 10 | 11 | use yii\bootstrap\Html; |
| 11 | 12 | use yii\helpers\Url; |
| 12 | 13 | use yii\widgets\ListView; |
| 13 | - | |
| 14 | 14 | ?> |
| 15 | 15 | <div class="search_perform_txt-wr"> |
| 16 | 16 | <div class="search_perform_title"> |
| 17 | 17 | <?php |
| 18 | 18 | if($model->type == 2) { |
| 19 | - echo $model->companyInfo->name; | |
| 19 | + echo Html::a($model->companyInfo->name, ['company/common', 'company_id' => $model->id]); | |
| 20 | 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 | 24 | </div> |
| 25 | 25 | <div class="search_perform-stars-wr"> |
| 26 | 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 | 35 | <input type="hidden" class="val" value="4"/> |
| 29 | 36 | </div> |
| 30 | 37 | <div class="search_perform-stars-txt"> |
| 31 | - 30 отзывов | |
| 38 | + <?= $model->getComments()->count() ?> отзывов | |
| 32 | 39 | <?php |
| 33 | 40 | if(!empty( $model->userInfo->city )) { |
| 34 | 41 | echo ", {$model->userInfo->city}"; |
| ... | ... | @@ -49,12 +56,17 @@ |
| 49 | 56 | <span>Послелний визит:</span> <?= \Yii::$app->formatter->asRelativeTime($model->userInfo->date_visit) ?> |
| 50 | 57 | </div> |
| 51 | 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 | 61 | </div> |
| 54 | 62 | |
| 55 | 63 | <div class="right_search_perform_block-wr"> |
| 56 | 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 | 70 | </div> |
| 59 | 71 | <a class="get-list" href="#">Добавить в закладки</a> |
| 60 | 72 | </div> |
| 61 | 73 | \ No newline at end of file | ... | ... |
frontend/views/search/customer.php
| ... | ... | @@ -135,6 +135,9 @@ |
| 135 | 135 | 'itemView' => '_customer_list_view', |
| 136 | 136 | ]); |
| 137 | 137 | ?> |
| 138 | + <?php | |
| 139 | + /* == Layout == | |
| 140 | + ?> | |
| 138 | 141 | <div class="search-worker-blocks-wr style"> |
| 139 | 142 | |
| 140 | 143 | <div class="search-worker-blocks"> |
| ... | ... | @@ -259,6 +262,10 @@ |
| 259 | 262 | </ul> |
| 260 | 263 | </div> |
| 261 | 264 | |
| 265 | + <?php | |
| 266 | + == End of layout == */ | |
| 267 | + ?> | |
| 268 | + | |
| 262 | 269 | <script> |
| 263 | 270 | $('div.rating_search_performer').rating( |
| 264 | 271 | { | ... | ... |
frontend/web/css/style.css
| ... | ... | @@ -6677,4 +6677,7 @@ input[disabled], select[disabled] { |
| 6677 | 6677 | } |
| 6678 | 6678 | .form_site_logn-wr input.custom-check + label span {margin-top: 1px; margin-right: 6px} |
| 6679 | 6679 | .callback .input-blocks-wrapper {margin-top: 0} |
| 6680 | -.list_item.title {margin-top: 20px} | |
| 6681 | 6680 | \ No newline at end of file |
| 6681 | +.list_item.title {margin-top: 20px} | |
| 6682 | +.search_customer_image { | |
| 6683 | + height: 100%; | |
| 6684 | +} | |
| 6682 | 6685 | \ No newline at end of file | ... | ... |