diff --git a/common/models/User.php b/common/models/User.php index 5d036aa..67ba0b6 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -1,7 +1,10 @@ 1, - ] + ], ]; } @@ -112,8 +113,8 @@ { return [ 'firstname' => Yii::t('app', 'Имя'), - 'lastname' => Yii::t('app', 'Фамилия'), - 'email' => Yii::t('app', 'Email'), + 'lastname' => Yii::t('app', 'Фамилия'), + 'email' => Yii::t('app', 'Email'), ]; } @@ -348,7 +349,8 @@ */ public function getUserInfo() { - return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ])->inverseOf('user'); + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]) + ->inverseOf('user'); } /** @@ -408,11 +410,11 @@ $date1 = new \DateTime(date('Y-m-d H:i:s', $this->created_at)); $result = explode(',', \Yii::$app->formatter->asDuration($date1->diff($now))); - if($result >= 4){ + if($result >= 4) { array_splice($result, 2); } - return implode(',',$result); + return implode(',', $result); } /** @@ -549,7 +551,8 @@ */ public function getVacancies() { - return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ])->inverseOf('user'); + return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ]) + ->inverseOf('user'); } public function getGalleries() @@ -559,22 +562,44 @@ public function getOwner() { - if($this->type == 1){ - return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]); - } else if($this->type == 2) { + if($this->type == 2) { return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); + } else { + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]); } - } - public function getName(){ - if($this->type == 1){ - return $this->firstname. ' '.$this->lastname; - } else if($this->type == 2){ + public function getName() + { + if($this->type == 2) { return $this->companyInfo->name; + } else { + return $this->firstname . ' ' . $this->lastname; } + } + public function getComments() + { + $entity = 'user-' . $this->id; + $comments = (new Comment())->getComments($entity); + return $comments; } + public function getRatingPG() + { + if(\Yii::$app->db->driverName != 'pgsql') { + throw new InvalidConfigException('This method is available only in PostgreSQL'); + } + $entity = 'user-' . $this->id; + $rating = (new Comment())->getComments($entity) + ->select('ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::float) as rating') + ->leftJoin(Rating::tableName(), "CONCAT('Comment-', \"comment\".\"comment_id\") = \"rating\".\"entity\"") + ->andWhere([ + 'not', + [ 'rating.value' => NULL ], + ]) + ->one(); + return $rating; + } } diff --git a/common/modules/comment/models/Comment.php b/common/modules/comment/models/Comment.php index 4486e46..77d2533 100644 --- a/common/modules/comment/models/Comment.php +++ b/common/modules/comment/models/Comment.php @@ -1,6 +1,8 @@ guestComment = $value; } + /** + * @param string $entity + * + * @return ActiveQuery + */ public function getComments($entity) { return $this->find() ->where([ - 'entity' => $this->entity, - 'status' => 1, + 'comment.entity' => $entity, + 'comment.status' => 1, ]); } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index e70dd2e..f61d266 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -71,6 +71,9 @@ class SearchController extends Controller public function actionCustomer(){ $model = new CustomerSearch(); $dataProvider = $model->search(Yii::$app->request->queryParams); + $dataProvider->setPagination([ + 'pageSize' => 5 + ]); $dataProvider->setSort([ 'attributes' => [ 'name' => [ diff --git a/frontend/views/search/_customer_list_view.php b/frontend/views/search/_customer_list_view.php index 1aca034..6f9fffe 100644 --- a/frontend/views/search/_customer_list_view.php +++ b/frontend/views/search/_customer_list_view.php @@ -5,30 +5,37 @@ * @var integer $index * @var ListView $widget */ + use common\models\Project; use common\models\User; use frontend\helpers\TextHelper; use yii\bootstrap\Html; use yii\helpers\Url; use yii\widgets\ListView; - ?>