From 877ea4b2b3619a86e31e7ff64b41cca143441cb4 Mon Sep 17 00:00:00 2001 From: Yarik Date: Wed, 27 Apr 2016 17:44:09 +0300 Subject: [PATCH] test --- common/models/Portfolio.php | 39 +++++++++++++++++++++++++++++++++++++++ common/modules/comment/widgets/views/form-comment.php | 24 +++++++++++++----------- common/modules/comment/widgets/views/project_comment_view.php | 17 ++++++++++++++++- frontend/views/performer/_portfolio_list_view.php | 6 +++--- frontend/views/performer/portfolio-view.php | 25 +++++++++++++++---------- frontend/views/performer/portfolio.php | 7 +++++++ frontend/web/css/style.css | 2 +- 7 files changed, 94 insertions(+), 26 deletions(-) diff --git a/common/models/Portfolio.php b/common/models/Portfolio.php index 1a04ee7..bc6520f 100644 --- a/common/models/Portfolio.php +++ b/common/models/Portfolio.php @@ -2,9 +2,12 @@ namespace common\models; + use common\modules\comment\models\Comment; + use common\modules\comment\models\Rating; use Yii; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; + use yii\db\ActiveQuery; use yii\db\Expression; /** @@ -26,6 +29,9 @@ * @property PortfolioSpecialization[] $portfolioSpecializations * @property Specialization[] $specializations * @property User $user + * @property Comment[] $comment + * @property Rating[] $rating + * @property string $ratingValue */ class Portfolio extends \yii\db\ActiveRecord { @@ -199,4 +205,37 @@ { return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); } + + /** + * @return ActiveQuery + */ + public function getComments() + { + return $this->hasMany(Comment::className(), [ 'model_id' => 'portfolio_id' ]) + ->andWhere([ 'comment.model' => $this->className(), 'comment.status' => Comment::STATUS_ACTIVE ]); + } + + /** + * @return ActiveQuery + */ + public function getRating() + { + return $this->hasMany(Rating::className(), [ 'model_id' => 'comment_id' ]) + ->via('comments') + ->andWhere([ + 'not', + [ 'rating.value' => NULL ], + ]); + } + + /** + * @return string + */ + public function getRatingValue() + { + return $this->getRating() + ->asArray() + ->select([ 'sum' => 'ROUND(SUM(rating.value)/COUNT(rating.value)::numeric, 1)' ]) + ->scalar(); + } } diff --git a/common/modules/comment/widgets/views/form-comment.php b/common/modules/comment/widgets/views/form-comment.php index 9262ebc..c14055e 100644 --- a/common/modules/comment/widgets/views/form-comment.php +++ b/common/modules/comment/widgets/views/form-comment.php @@ -5,6 +5,7 @@ * @var \yii\data\ActiveDataProvider $dataProvider * @var null|\common\modules\comment\models\Rating $rating */ + use kartik\rating\StarRating; use yii\widgets\ActiveForm; use yii\helpers\Html; @@ -15,16 +16,16 @@ field($rating, 'value') - ->label(false) - ->radioList([ - 1 => 1, - 2 => 2, - 3 => 3, - 4 => 4, - 5 => 5, - ]); + if($rating) { + echo $form->field(( !empty( $model->rating ) ? $model->rating : $rating ), 'value') + ->label(false) + ->widget(StarRating::className(), [ 'pluginOptions' => [ 'size' => 'xxs', + 'step' => 1, + 'value' => 2, + 'showCaption' => false, + ], + ]); + } if($model->scenario == $model::SCENARIO_GUEST) { echo $form->field($model, 'user_name', [ @@ -44,7 +45,8 @@ 'class' => 'custom-input-4', ], ]) - ->textInput(); + ->textInput() + ->hint('Ваш email не будет доступен к просмотру.'); } ?> diff --git a/common/modules/comment/widgets/views/project_comment_view.php b/common/modules/comment/widgets/views/project_comment_view.php index f17588c..c876f4d 100644 --- a/common/modules/comment/widgets/views/project_comment_view.php +++ b/common/modules/comment/widgets/views/project_comment_view.php @@ -1,5 +1,6 @@ with('userInfo') ->one(); } + $model->buildButtons(['delete']); ?> -
+
text) ?>
+
+ buttons[ 'delete' ] )) { + echo Html::a(($model->user_id != NULL && $model->user_id == \Yii::$app->user->id)?'Удалить':'Пожаловаться ', $model->buttons[ 'delete' ], [ 'class' => CommentWidget::$baseClass[ 'comment_delete' ] ]); + } + if(!empty( $model->buttons[ 'update' ] )) { + echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => CommentWidget::$baseClass[ 'comment_update' ] ]); + } + if(!empty( $model->buttons[ 'reply' ] )) { + echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] ]); + } + ?> +
diff --git a/frontend/views/performer/_portfolio_list_view.php b/frontend/views/performer/_portfolio_list_view.php index d4892b6..af2d31f 100644 --- a/frontend/views/performer/_portfolio_list_view.php +++ b/frontend/views/performer/_portfolio_list_view.php @@ -37,21 +37,21 @@
-
127
+
view_count?>
-
10.0
+
getRatingValue()?:'Нет')?>
-
14
+
comments)?>
specializations, 'specialization_name')) ?>
diff --git a/frontend/views/performer/portfolio-view.php b/frontend/views/performer/portfolio-view.php index deaa9b6..1ab9f59 100644 --- a/frontend/views/performer/portfolio-view.php +++ b/frontend/views/performer/portfolio-view.php @@ -2,6 +2,7 @@ use common\models\Portfolio; use common\models\User; + use kartik\rating\StarRating; use yii\helpers\Html; use yii\web\ViewAction; use yii\web\View; @@ -15,6 +16,7 @@ $this->params[ 'user' ] = $user; $this->title = 'My Yii Application'; + $rating = $portfolio->getRatingValue(); ?>
@@ -35,24 +37,25 @@
-
XX.X
+
-
+
comments)?>
-
- - - - -
+ 'rating_portfolio', + 'value' => $portfolio->getRatingValue(), + 'pluginOptions' => ['displayOnly' => true, 'size' => 'xxs'] + ]); + ?>
@@ -60,13 +63,15 @@
name ?>
gallery ) || !empty( $portfolio->gallery->photo )) { + $gallery = explode(',', $portfolio->gallery->photo); + array_pop($gallery); ?>
    gallery->photo) as $one_photo ) { + foreach($gallery as $one_photo) { ?>
  • $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' => (\Yii::$app->user->id?\common\modules\comment\models\Rating::className():false), '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(), diff --git a/frontend/views/performer/portfolio.php b/frontend/views/performer/portfolio.php index 10faf78..79a526b 100755 --- a/frontend/views/performer/portfolio.php +++ b/frontend/views/performer/portfolio.php @@ -4,6 +4,7 @@ use \yii\helpers\Html; use yii\helpers\Url; use yii\widgets\ListView; + use yii\widgets\Pjax; /* @var $this yii\web\View * @var $portfolio yii\data\ArrayDataProvider @@ -13,6 +14,9 @@ ?>
    +

    Проектов: totalCount ?>

    @@ -44,5 +48,8 @@
    +
    \ No newline at end of file diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index a25c551..fc40201 100755 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -6650,7 +6650,7 @@ input[disabled], select[disabled] { .admin-portfolio-foto .btn {margin-top: 0} .admin-portfolio-foto.success_download .btn {margin-top: 15px} .admin-portfolio-foto #cover_buttons_block { - top: 173px; + top: 188px; left: 116px; } .admin-portfolio-foto .admin-ava-wr { -- libgit2 0.21.4