From 8f36efb77f1ca9dc27ae2ce875990b30dc7a37ed Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 5 Aug 2016 11:15:30 +0300 Subject: [PATCH] Added comments to prod. --- backend/views/layouts/main-sidebar.php | 6 ++++++ common/behaviors/NotifyBehavior.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/models/CommentModel.php | 4 ++++ common/widgets/views/comment_notify.php | 36 ++++++++++++++++++++++++++++++++++++ frontend/views/catalog/product.php | 56 +++++++++++++++++++++++++------------------------------- 5 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 common/behaviors/NotifyBehavior.php create mode 100644 common/widgets/views/comment_notify.php diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index 8c5449e..a8a5d83 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -156,6 +156,12 @@ use yii\widgets\Menu; 'options' => ['class'=>\Yii::$app->user->can('customer') ? '' :'hide'], ], [ + 'template'=>' {label}', + 'label' => 'Комментарии', + 'url' => ['/artbox-comments'], + 'options' => ['class'=>\Yii::$app->user->can('artbox-comments') ? '' :'hide'], + ], + [ 'label' => 'Настройка ролей', 'template'=>' {label}', 'active' => preg_match('/^user.*$/', $this->context->id) diff --git a/common/behaviors/NotifyBehavior.php b/common/behaviors/NotifyBehavior.php new file mode 100644 index 0000000..493b5bb --- /dev/null +++ b/common/behaviors/NotifyBehavior.php @@ -0,0 +1,72 @@ + 'afterUpdate', + ]; + } + + public function afterUpdate($event) + { + /** + * @var Event $event + * @var CommentModel $owner + */ + $owner = $this->owner; + if($owner->status == $owner::STATUS_ACTIVE) { + $entity = $owner->entity; + $model = $entity::findOne($owner->entity_id); + if($model != NULL) { + if(!empty( $owner->user )) { + $customer = $owner->user; + } + $url = ''; + if($model::className() == Product::className()) { + $url = Url::to([ + 'catalog/product', + 'product' => $model, + '#' => 'artbox-comment', + ], true); + } elseif($model::className() == Articles::className()) { + $url = Url::to([ + 'articles/show', + 'translit' => $model->translit, + 'id' => $model->id, + '#' => 'artbox-comment', + ], true); + } + $mailer = Mailer::widget([ + 'type' => 'comment_notify', + 'params' => [ + 'model' => $model, + 'url' => $url, + ], + 'subject' => 'Ваш комментарий опубликован', + 'email' => ( !empty( $customer ) ? $customer->email : $owner->email ), + ]); + return $mailer; + } + } + return false; + } + } \ No newline at end of file diff --git a/common/modules/comment/models/CommentModel.php b/common/modules/comment/models/CommentModel.php index c3b8b2e..d7ca4d6 100644 --- a/common/modules/comment/models/CommentModel.php +++ b/common/modules/comment/models/CommentModel.php @@ -1,6 +1,7 @@ RatingBehavior::className(), ], + [ + 'class' => NotifyBehavior::className(), + ], ]; } diff --git a/common/widgets/views/comment_notify.php b/common/widgets/views/comment_notify.php new file mode 100644 index 0000000..13c9cbc --- /dev/null +++ b/common/widgets/views/comment_notify.php @@ -0,0 +1,36 @@ + + + + + + Rukzachok.com.ua + + + +
+

Ваш коммертарий успешно опубликован.

+

Чтобы просмотреть комментарий перейдите по ссылке:

+
+ + \ No newline at end of file diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index 0872dd0..b741606 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -175,23 +175,23 @@
- averageRating ) && $product->averageRating->value) { - ?> -
- -

- comments); - if($comment_count) { - echo "Отзывов: " . $comment_count; - } else { - echo "Оставть отзыв"; - } - ?> -

+ averageRating ) && $product->averageRating->value) { + ?> +
+ +

+ comments); + if($comment_count) { + echo "Отзывов: " . $comment_count; + } else { + echo "Оставть отзыв"; + } + ?> +


- category->category_id == 130) { - ?> -
-
- -
-
- -
-
- +
+
+ +
+
+ +
+