diff --git a/common/models/CustomerSearch.php b/common/models/CustomerSearch.php
index fc2d72d..91fce55 100644
--- a/common/models/CustomerSearch.php
+++ b/common/models/CustomerSearch.php
@@ -123,6 +123,10 @@
}
$query->andFilterWhere([
+ 'user_info.rating' => $this->rating,
+ ]);
+
+ $query->andFilterWhere([
'like',
'user_info.city',
$this->city,
diff --git a/common/models/User.php b/common/models/User.php
index 67ba0b6..2f3b21d 100755
--- a/common/models/User.php
+++ b/common/models/User.php
@@ -578,11 +578,29 @@
}
}
+ /**
+ * @return ActiveQuery
+ */
public function getComments()
{
- $entity = 'user-' . $this->id;
- $comments = (new Comment())->getComments($entity);
- return $comments;
+ return $this->hasMany(Comment::className(), [
+ 'model_id' => 'id',
+ ])
+ ->andWhere([
+ 'comment.model' => $this->className(),
+ ]);
+ }
+
+ /**
+ * @return ActiveQuery
+ */
+ public function getCommentRating()
+ {
+ return $this->hasMany(Rating::className(), [ 'model_id' => 'comment_id' ])
+ ->via('comments')
+ ->andWhere([
+ 'rating.model' => Comment::className(),
+ ]);
}
public function getRatingPG()
@@ -590,16 +608,21 @@
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;
+ return $this->getCommentRating()
+ ->select('ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::float) as rating')
+ ->andWhere([
+ 'not',
+ [ 'rating.value' => NULL ],
+ ])
+ ->scalar();
+ }
+
+ public function updateRating()
+ {
+ if($rating = $this->getRatingPG()) {
+ $this->userInfo->rating = $rating;
+ $this->userInfo->save();
+ }
}
}
diff --git a/common/modules/comment/interfaces/CommentInterface.php b/common/modules/comment/interfaces/CommentInterface.php
index 746cd9c..471dddf 100644
--- a/common/modules/comment/interfaces/CommentInterface.php
+++ b/common/modules/comment/interfaces/CommentInterface.php
@@ -4,7 +4,7 @@
interface CommentInterface {
public function load($data, $formName = null);
public function formName();
- public function getComments($entity);
+ public function getComments($model, $model_id);
public function postComment();
public function deleteComment();
public function updateComment();
diff --git a/common/modules/comment/models/Comment.php b/common/modules/comment/models/Comment.php
index 77d2533..8796389 100644
--- a/common/modules/comment/models/Comment.php
+++ b/common/modules/comment/models/Comment.php
@@ -7,6 +7,17 @@
* Class Comment
* @property bool $guestComment
* @property integer $comment_id
+ * @property string $text
+ * @property int $user_id
+ * @property string $user_name
+ * @property string $user_email
+ * @property int $comment_pid
+ * @property int $status
+ * @property string $date_add
+ * @property string $date_update
+ * @property string $date_delete
+ * @property string $model
+ * @property int $model_id
* @package common\modules\comment\models
*/
class Comment extends \yii\db\ActiveRecord
@@ -21,8 +32,6 @@
const SCENARIO_USER = 'user';
const SCENARIO_GUEST = 'guest';
- public $rating;
-
/**
* @var bool
*/
@@ -70,7 +79,8 @@
'exist',
'targetAttribute' => 'comment_id',
'filter' => [
- 'entity' => $this->entity,
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
],
],
];
@@ -135,16 +145,18 @@
}
/**
- * @param string $entity
+ * @param string $model
+ * @param integer $model_id
*
* @return ActiveQuery
*/
- public function getComments($entity)
+ public function getComments($model, $model_id)
{
return $this->find()
->where([
- 'comment.entity' => $entity,
- 'comment.status' => 1,
+ 'comment.model' => $model,
+ 'comment.model_id' => $model_id,
+ 'comment.status' => 1,
]);
}
@@ -212,7 +224,10 @@
if($this->getGuestComment()) {
return true;
} else {
- return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [ 'entity' => $this->entity ]);
+ return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
+ ]);
}
}
@@ -221,7 +236,13 @@
if($this->scenario == self::SCENARIO_GUEST) {
return false;
} else {
- 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 ]);
+ return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
+ ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
+ ]);
}
}
@@ -230,7 +251,13 @@
if($this->scenario == self::SCENARIO_GUEST) {
return false;
} else {
- 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 ]);
+ return \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
+ ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [
+ 'model' => $this->model,
+ 'model_id' => $this->model_id,
+ ]);
}
}
@@ -260,12 +287,18 @@
public function checkRating()
{
- $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ])
+ $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [
+ 'model_id' => 'comment_id',
+ ])
+ ->andWhere([
+ 'model' => $this->className(),
+ ])
->one();
if(!$rating instanceof \common\modules\comment\models\Rating) {
$rating = new \common\modules\comment\models\Rating([
- 'entity' => $this->entityId,
- 'user_id' => $this->user_id,
+ 'model' => $this->className(),
+ 'model_id' => $this->comment_id,
+ 'user_id' => $this->user_id,
]);
$rating->save();
}
@@ -274,12 +307,18 @@
public function getRating()
{
$this->checkRating();
- return $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ]);
+ return $this->hasOne(\common\modules\comment\models\Rating::className(), [
+ 'model_id' => 'comment_id',
+ ])
+ ->andWhere([ 'model' => $this->className() ]);
}
public function hasRating($return = true)
{
- $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [ 'entity' => 'entityId' ])
+ $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [
+ 'model_id' => 'comment_id',
+ ])
+ ->andWhere([ 'model' => $this->className() ])
->andWhere([
'not',
[ 'value' => NULL ],
@@ -292,8 +331,4 @@
}
}
- public function getEntityId()
- {
- return $this->formName() . '-' . $this->getPrimaryKey();
- }
}
diff --git a/common/modules/comment/models/Rating.php b/common/modules/comment/models/Rating.php
index cfda4e1..3222732 100644
--- a/common/modules/comment/models/Rating.php
+++ b/common/modules/comment/models/Rating.php
@@ -11,13 +11,16 @@ use Yii;
* @property string $date_add
* @property string $date_update
* @property integer $user_id
- * @property string $entity
* @property integer $value
+ * @property string $model
+ * @property integer $model_id
*
* @property \common\models\User $user
*/
class Rating extends \yii\db\ActiveRecord
{
+
+ public $rating;
/**
* @inheritdoc
*/
diff --git a/common/modules/comment/widgets/CommentWidget.php b/common/modules/comment/widgets/CommentWidget.php
index dfe128e..52c316f 100644
--- a/common/modules/comment/widgets/CommentWidget.php
+++ b/common/modules/comment/widgets/CommentWidget.php
@@ -86,9 +86,14 @@
public $success_text = 'Comment successfully added';
/**
- * @var string Entity, to which comments attached
+ * @var string $model Model, to which comments attached
*/
- public $entity;
+ public $model;
+
+ /**
+ * @var integer $model_id Model id, to which comments attached
+ */
+ public $model_id;
/**
* @var string Template of the widget. You may use {success}, {form}, {list}
@@ -123,7 +128,8 @@
} elseif(!empty( $this->rating_class )) {
throw new \yii\base\InvalidConfigException(__CLASS__ . '->rating_class must be defined as object full class name string.');
}
- $this->comment_class->entity = $this->entity;
+ $this->comment_class->model = $this->model;
+ $this->comment_class->model_id = $this->model_id;
$this->createDataProvider();
$this->process();
ob_start();
@@ -171,7 +177,7 @@
public function createDataProvider()
{
$this->dataProvider = new \yii\data\ActiveDataProvider([
- 'query' => $this->comment_class->getComments($this->entity),
+ 'query' => $this->comment_class->getComments($this->model, $this->model_id),
'pagination' => [
'pageSize' => 10,
],
diff --git a/console/migrations/m160311_132124_rating_comment_restyle.php b/console/migrations/m160311_132124_rating_comment_restyle.php
new file mode 100644
index 0000000..7cd0df5
--- /dev/null
+++ b/console/migrations/m160311_132124_rating_comment_restyle.php
@@ -0,0 +1,31 @@
+truncateTable('{{%comment}}');
+ $this->truncateTable('{{%rating}}');
+ $this->dropColumn('{{%comment}}', 'entity');
+ $this->dropColumn('{{%rating}}', 'entity');
+ $this->addColumn('{{%comment}}', 'model', $this->string()->notNull());
+ $this->addColumn('{{%comment}}', 'model_id', $this->integer()->notNull());
+ $this->addColumn('{{%rating}}', 'model', $this->string()->notNull());
+ $this->addColumn('{{%rating}}', 'model_id', $this->integer()->notNull());
+ }
+
+ public function down()
+ {
+ $this->truncateTable('{{%comment}}');
+ $this->truncateTable('{{%rating}}');
+ $this->dropColumn('{{%comment}}', 'model');
+ $this->dropColumn('{{%rating}}', 'model');
+ $this->dropColumn('{{%comment}}', 'model_id');
+ $this->dropColumn('{{%rating}}', 'model_id');
+ $this->addColumn('{{%comment}}', 'entity', $this->string()->notNull());
+ $this->addColumn('{{%rating}}', 'entity', $this->string()->notNull());
+ }
+
+}
diff --git a/console/migrations/m160311_151257_user_project_rating.php b/console/migrations/m160311_151257_user_project_rating.php
new file mode 100644
index 0000000..8351d78
--- /dev/null
+++ b/console/migrations/m160311_151257_user_project_rating.php
@@ -0,0 +1,19 @@
+addColumn('{{%user_info}}', 'rating', $this->float()->defaultValue(0));
+ $this->addColumn('{{%project}}', 'rating', $this->float()->defaultValue(0));
+ }
+
+ public function down()
+ {
+ $this->dropColumn('{{%user_info}}', 'rating');
+ $this->dropColumn('{{%project}}', 'rating');
+ }
+
+}
diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php
index f61d266..4c40602 100755
--- a/frontend/controllers/SearchController.php
+++ b/frontend/controllers/SearchController.php
@@ -1,206 +1,214 @@
[
- 'class' => 'yii\web\ErrorAction',
- ],
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
-
- public function actionProject()
+ class SearchController extends Controller
{
- $projects = new ActiveDataProvider([
- 'query' => Project::find(),
- 'pagination' => [
- 'pageSize' => 9,
- ],
- ]);
-
- return $this->render('project',[
- 'projects' => $projects
- ]);
- }
+ public $defaultAction = 'common';
-
- public function actionCustomer(){
- $model = new CustomerSearch();
- $dataProvider = $model->search(Yii::$app->request->queryParams);
- $dataProvider->setPagination([
- 'pageSize' => 5
- ]);
- $dataProvider->setSort([
- 'attributes' => [
- 'name' => [
- 'asc' => [
- 'company_info.name' => SORT_ASC,
- 'firstname' => SORT_ASC,
- 'lastname' => SORT_ASC,
- ],
- 'desc' => [
- 'company_info.name' => SORT_DESC,
- 'firstname' => SORT_DESC,
- 'lastname' => SORT_DESC,
- ],
- 'default' => SORT_ASC,
- 'label' => 'Название',
+ /**
+ * @inheritdoc
+ */
+ public function actions()
+ {
+ return [
+ 'error' => [
+ 'class' => 'yii\web\ErrorAction',
],
- 'staff' => [
- 'asc' => [
- 'company_info.staff' => SORT_ASC,
- ],
- 'desc' => [
- 'company_info.staff' => SORT_DESC,
- ],
- 'default' => SORT_DESC,
- 'label' => 'Количество сотрудников',
+ 'captcha' => [
+ 'class' => 'yii\captcha\CaptchaAction',
+ 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
+ ],
+ ];
+ }
+
+ public function actionProject()
+ {
+ $projects = new ActiveDataProvider([
+ 'query' => Project::find(),
+ 'pagination' => [
+ 'pageSize' => 9,
+ ],
+ ]);
+ return $this->render('project', [
+ 'projects' => $projects,
+ ]);
+ }
+
+ public function actionCustomer()
+ {
+ $model = new CustomerSearch();
+ $dataProvider = $model->search(Yii::$app->request->queryParams);
+ $dataProvider->setPagination([
+ 'pageSize' => 5,
+ ]);
+ $dataProvider->setSort([
+ 'defaultOrder' => [
+ 'name' => SORT_ASC,
],
- 'visit' => [
- 'asc' => [
- 'user_info.date_visit' => SORT_ASC,
+ 'attributes' => [
+ 'name' => [
+ 'asc' => [
+ 'company_info.name' => SORT_ASC,
+ 'firstname' => SORT_ASC,
+ 'lastname' => SORT_ASC,
+ ],
+ 'desc' => [
+ 'company_info.name' => SORT_DESC,
+ 'firstname' => SORT_DESC,
+ 'lastname' => SORT_DESC,
+ ],
+ 'default' => SORT_ASC,
+ 'label' => 'Название',
],
- 'desc' => [
- 'user_info.date_visit' => SORT_DESC,
+ 'staff' => [
+ 'asc' => [
+ 'company_info.staff' => SORT_ASC,
+ ],
+ 'desc' => [
+ 'company_info.staff' => SORT_DESC,
+ ],
+ 'default' => SORT_DESC,
+ 'label' => 'Количество сотрудников',
],
- 'default' => SORT_DESC,
- 'label' => 'Последний визит',
- ],
- 'city' => [
- 'asc' => [
- 'user_info.city' => SORT_ASC,
+ 'visit' => [
+ 'asc' => [
+ 'user_info.date_visit' => SORT_ASC,
+ ],
+ 'desc' => [
+ 'user_info.date_visit' => SORT_DESC,
+ ],
+ 'default' => SORT_DESC,
+ 'label' => 'Последний визит',
],
- 'desc' => [
- 'user_info.city' => SORT_DESC,
+ 'city' => [
+ 'asc' => [
+ 'user_info.city' => SORT_ASC,
+ ],
+ 'desc' => [
+ 'user_info.city' => SORT_DESC,
+ ],
+ 'default' => SORT_ASC,
+ 'label' => 'Город',
],
- 'default' => SORT_ASC,
- 'label' => 'Город',
],
- ],
- ]);
- $model->load(Yii::$app->request->queryParams);
- $cities = UserInfo::find()->select('city')->distinct()->asArray()->indexBy('city')->column();
- return $this->render('customer',[
- 'model' => $model,
- 'dataProvider' => $dataProvider,
- 'cities' => $cities,
- ]);
- }
-
- public function actionCompany()
- {
- $query = UserInfo::find()
- ->joinWith([ 'user' ])
- ->where(['is_customer' => 1,'user.type'=>2]);
-
- $companies = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => [
- 'pageSize' => 3,
- ],
- ]);
-
- return $this->render('company',[
- 'companies' => $companies
- ]);
- }
-
- public function actionPerformer()
- {
- $query = UserInfo::find()
- ->joinWith([ 'user' ])
- ->where(['is_customer' => 1,'user.type'=>1]);
-
-
- $performer = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => [
- 'pageSize' => 3,
- ],
- ]);
-
- return $this->render('performer',[
- 'performer' => $performer
- ]);
- }
-
- public function actionVacancy()
- {
-
+ ]);
+ $model->load(Yii::$app->request->queryParams);
+ $cities = UserInfo::find()
+ ->select('city')
+ ->distinct()
+ ->asArray()
+ ->indexBy('city')
+ ->column();
+ return $this->render('customer', [
+ 'model' => $model,
+ 'dataProvider' => $dataProvider,
+ 'cities' => $cities,
+ ]);
+ }
+
+ public function actionCompany()
+ {
+ $query = UserInfo::find()
+ ->joinWith([ 'user' ])
+ ->where([
+ 'is_customer' => 1,
+ 'user.type' => 2,
+ ]);
+
+ $companies = new ActiveDataProvider([
+ 'query' => $query,
+ 'pagination' => [
+ 'pageSize' => 3,
+ ],
+ ]);
+
+ return $this->render('company', [
+ 'companies' => $companies,
+ ]);
+ }
+
+ public function actionPerformer()
+ {
+ $query = UserInfo::find()
+ ->joinWith([ 'user' ])
+ ->where([
+ 'is_customer' => 1,
+ 'user.type' => 1,
+ ]);
+
+ $performer = new ActiveDataProvider([
+ 'query' => $query,
+ 'pagination' => [
+ 'pageSize' => 3,
+ ],
+ ]);
- $query = Vacancy::find();
+ return $this->render('performer', [
+ 'performer' => $performer,
+ ]);
+ }
- $countQuery = clone $query;
+ public function actionVacancy()
+ {
- $pagination = new Pagination(['totalCount' => $countQuery->count(),
- 'pageSize' => 15,
- ]);
+ $query = Vacancy::find();
- $vacancy = $query->offset($pagination->offset)
- ->limit($pagination->limit);
+ $countQuery = clone $query;
+ $pagination = new Pagination([
+ 'totalCount' => $countQuery->count(),
+ 'pageSize' => 15,
+ ]);
- $provider = new ActiveDataProvider([
- 'query' => $vacancy,
- 'pagination' => false,
- 'sort' => [
- 'defaultOrder' => [
- 'date_add' => SORT_DESC,
- 'name' => SORT_ASC,
- ]
- ],
- ]);
+ $vacancy = $query->offset($pagination->offset)
+ ->limit($pagination->limit);
+ $provider = new ActiveDataProvider([
+ 'query' => $vacancy,
+ 'pagination' => false,
+ 'sort' => [
+ 'defaultOrder' => [
+ 'date_add' => SORT_DESC,
+ 'name' => SORT_ASC,
+ ],
+ ],
+ ]);
+ return $this->render('vacancy', [
+ 'provider' => $provider,
+ 'pagination' => $pagination,
+ ]);
+ }
- return $this->render('vacancy',[
- 'provider' => $provider,
- 'pagination' => $pagination
- ]);
}
-
-}
diff --git a/frontend/views/performer/portfolio-view.php b/frontend/views/performer/portfolio-view.php
index 290d242..68231de 100644
--- a/frontend/views/performer/portfolio-view.php
+++ b/frontend/views/performer/portfolio-view.php
@@ -114,21 +114,22 @@
$this,
- 'entity' => $portfolio::tableName() . '-' . $portfolio->portfolio_id,
+ 'model' => $portfolio::className(),
+ 'model_id' => $portfolio->portfolio_id,
'comment_class' => \common\modules\comment\models\Comment::className(),
- 'rating_class' => \common\modules\comment\models\Rating::className(),
+ 'rating_class' => \common\modules\comment\models\Rating::className(),
'class_options' => [
- 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST,
- 'user_id' => \Yii::$app->user->getId(),
+ 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST,
+ 'user_id' => \Yii::$app->user->getId(),
'guestComment' => true,
- 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE,
+ 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE,
],
'list_options' => [
'view' => 'list-comment',
],
'form_options' => [
- 'view' => 'form-comment',
- 'tag' => 'div',
+ 'view' => 'form-comment',
+ 'tag' => 'div',
'class' => 'artbox_comment_form',
],
'options' => [
diff --git a/frontend/views/search/_customer_list_view.php b/frontend/views/search/_customer_list_view.php
index 6f9fffe..783d37f 100644
--- a/frontend/views/search/_customer_list_view.php
+++ b/frontend/views/search/_customer_list_view.php
@@ -26,13 +26,12 @@