Commit 17ca60dd553e779a2180d3fc0394fab1177e298c

Authored by Yarik
1 parent 34587997

Added comments to prod.

.gitignore
... ... @@ -46,4 +46,6 @@ phpunit.phar
46 46 /frontend/views/вертска
47 47 composer.lock
48 48  
49   -tests/_output/*
50 49 \ No newline at end of file
  50 +tests/_output/*
  51 +/common/modules/_comment/
  52 +Будет удалено common/modules/comment/
... ...
common/behaviors/RatingBehavior.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\behaviors;
  4 +
  5 + use common\modules\comment\models\CommentModel;
  6 + use common\modules\product\models\Product;
  7 + use yii\base\Behavior;
  8 + use yii\base\Event;
  9 + use yii\db\ActiveRecord;
  10 +
  11 + /**
  12 + * Class RatingBehavior
  13 + * @property CommentModel $owner
  14 + * @package common\behaviors
  15 + */
  16 + class RatingBehavior extends Behavior
  17 + {
  18 +
  19 + public function events()
  20 + {
  21 + return [
  22 + ActiveRecord::EVENT_AFTER_UPDATE => 'afterUpdate',
  23 + ];
  24 + }
  25 +
  26 + public function afterUpdate($event)
  27 + {
  28 + /**
  29 + * @var Event $event
  30 + * @var CommentModel $owner
  31 + */
  32 + $owner = $this->owner;
  33 + if($owner->status == $owner::STATUS_ACTIVE && $owner->entity == Product::className()) {
  34 + $model = Product::findOne($owner->entity_id);
  35 + if($model != NULL) {
  36 + $model->recalculateRating();
  37 + }
  38 + }
  39 + }
  40 + }
0 41 \ No newline at end of file
... ...
common/modules/comment/controllers/DefaultController.php
... ... @@ -61,17 +61,19 @@
61 61 /**
62 62 * @var CommentModel $model
63 63 */
64   - $model = new $commentModelClass;
  64 + $model = new $commentModelClass([
  65 + 'scenario' => \Yii::$app->user->getIsGuest() ? $commentModelClass::SCENARIO_GUEST : $commentModelClass::SCENARIO_USER,
  66 + ]);
65 67 if($model->load(\Yii::$app->request->post())) {
66 68 $model->setAttributes($entity_data);
67 69 if($model->save()) {
68   - if(empty($model->artbox_comment_pid) && $module::$enableRating) {
  70 + if(empty( $model->artbox_comment_pid ) && $module::$enableRating) {
69 71 $ratingModelClass = $module->ratingModelClass;
70 72 /**
71 73 * @var RatingModel $rating
72 74 */
73 75 $rating = new $ratingModelClass([
74   - 'model' => $model::className(),
  76 + 'model' => $model::className(),
75 77 'model_id' => $model->primaryKey,
76 78 ]);
77 79 if($rating->load(\Yii::$app->request->post())) {
... ... @@ -90,8 +92,7 @@
90 92 }
91 93 return [
92 94 'status' => 'error',
93   - 'message' => /*Yii::t('yii2mod.comments', 'Oops, something went wrong. Please try again later.'*/
94   - "Oops, something went wrong. Please try again later.",
  95 + 'message' => \Yii::t('artbox-comment', 'Oops, something went wrong. Please try again later.'),
95 96 ];
96 97 }
97 98  
... ... @@ -107,9 +108,9 @@
107 108 \Yii::$app->response->format = Response::FORMAT_JSON;
108 109 $model = $this->findModel($id);
109 110 if($model->deleteComment()) {
110   - return [ 'status' => 'success',
111   - 'message' => /*\Yii::t('yii2mod.comments', 'Comment has been deleted.');*/
112   - "Comment has been deleted.",
  111 + return [
  112 + 'status' => 'success',
  113 + 'message' => \Yii::t('yii2mod.comments', 'Comment has been deleted.'),
113 114 ];
114 115 } else {
115 116 \Yii::$app->response->setStatusCode(500);
... ... @@ -132,8 +133,7 @@
132 133 if(( $model = $commentModelClass::findOne($id) ) !== NULL) {
133 134 return $model;
134 135 } else {
135   - throw new NotFoundHttpException(/*\Yii::t('yii2mod.comments', 'The requested page does not exist.')*/
136   - "Comment not found.");
  136 + throw new NotFoundHttpException(\Yii::t('yii2mod.comments', 'The requested page does not exist.'));
137 137 }
138 138 }
139 139 }
140 140 \ No newline at end of file
... ...
common/modules/comment/messages/ru/artbox-comment.php
... ... @@ -53,4 +53,7 @@
53 53 'Active' => 'Включён',
54 54 'Deleted' => 'Удален',
55 55 'Comment posted' => 'Комментарий успешно добавлен и появится после проверки администрацией.',
  56 + 'Submit' => 'Добавить комментарий',
  57 + 'Cancel' => 'Отменить',
  58 + 'Guest' => 'Гость',
56 59 ];
... ...
common/modules/comment/models/CommentModel.php
1 1 <?php
2 2 namespace common\modules\comment\models;
3 3  
  4 + use common\behaviors\RatingBehavior;
4 5 use common\modules\comment\behaviors\ParentBehavior;
5 6 use common\modules\comment\models\interfaces\CommentInterface;
6 7 use common\modules\comment\Module;
... ... @@ -38,8 +39,19 @@
38 39 const STATUS_HIDDEN = 0;
39 40 const STATUS_DELETED = 2;
40 41  
  42 + const SCENARIO_USER = 'user';
  43 + const SCENARIO_GUEST = 'guest';
  44 +
41 45 public $encryptedEntity;
42 46  
  47 + public function scenarios()
  48 + {
  49 + $scenarios = parent::scenarios();
  50 + $scenarios[self::SCENARIO_USER] = ['text', 'entity', 'entity_id', 'artbox_comment_pid', 'status'];
  51 + $scenarios[self::SCENARIO_GUEST] = ['text', 'entity', 'entity_id', 'username', 'email', 'status'];
  52 + return $scenarios;
  53 + }
  54 +
43 55 public static function tableName()
44 56 {
45 57 return '{{%artbox_comment}}';
... ... @@ -58,12 +70,27 @@
58 70 ],
59 71 [
60 72 [
  73 + 'username',
  74 + 'email',
  75 + ],
  76 + 'required',
  77 + 'on' => self::SCENARIO_GUEST,
  78 + ],
  79 + [
  80 + [
61 81 'text',
62 82 'entity',
  83 + 'username',
63 84 ],
64 85 'string',
65 86 ],
66 87 [
  88 + [
  89 + 'email',
  90 + ],
  91 + 'email',
  92 + ],
  93 + [
67 94 [ 'entity_id', 'artbox_comment_pid' ],
68 95 'integer',
69 96 ],
... ... @@ -106,6 +133,9 @@
106 133 [
107 134 'class' => ParentBehavior::className(),
108 135 ],
  136 + [
  137 + 'class' => RatingBehavior::className(),
  138 + ],
109 139 ];
110 140 }
111 141  
... ...
common/modules/comment/resources/artbox_comment.css
  1 +@import "https://fonts.googleapis.com/css?family=Roboto:400,700,500&subset=cyrillic-ext,latin,cyrillic,latin-ext";
  2 +
  3 +.input_bl, .area_bl, .form-comm-wr, .user_name, .user_txt, .comment-panel, .answer-form, .comments-start input, .comments-start textarea, .submit_btn button, .input_bl label {
  4 + box-sizing: border-box
  5 +}
  6 +
  7 +.comments-border {
  8 + width: 100%;
  9 + margin-top: 25px;
  10 + margin-bottom: 27px;
  11 + height: 1px;
  12 + background: #d2d2d2
  13 +}
  14 +
  15 +.comments-start {
  16 + width: 730px;
  17 + margin: 0 auto;
  18 + font-family: 'Roboto', sans-serif;
  19 + font-weight: 400;
  20 + color: #333
  21 +}
  22 +
  23 +.form-comm-wr {
  24 + width: 100%;
  25 + background: #f5f5f5;
  26 + padding: 20px;
  27 + float: left
  28 +}
  29 +
  30 +.input_bl {
  31 + margin-top: 15px;
  32 + float: left
  33 +}
  34 +
  35 +.area_bl, .input_bl {
  36 + position: relative
  37 +}
  38 +
  39 +.input_bl input, .input_bl textarea, .answer-form textarea {
  40 + width: 258px;
  41 + height: 30px;
  42 + border: 1px solid #d2d2d2;
  43 + background: #fff;
  44 + outline: none !important;
  45 + border-radius: 4px;
  46 + padding-left: 10px
  47 +}
  48 +
  49 +.area_bl textarea, .answer-form textarea {
  50 + resize: none !important;
  51 + height: 140px;
  52 + width: 585px;
  53 + padding-top: 7px
  54 +}
  55 +.stars-wr_ {
  56 + width: 100%;
  57 +}
  58 +.input_bl input:focus, .input_bl textarea:focus, .answer-form textarea:focus {
  59 + box-shadow: 1px 2px 2px 0 rgba(215, 215, 215, 0.75) inset;
  60 + transition: .1s;
  61 + border: 1px solid #d2d2d2 !important;
  62 +}
  63 +
  64 +.input_bl label {
  65 + font-size: 12px;
  66 + color: #7d7d7d;
  67 + font-weight: 400;
  68 + text-transform: uppercase;
  69 + position: relative;
  70 + width: 105px;
  71 + float: left;
  72 + text-align: right;
  73 + padding-right: 10px;
  74 + margin: 9px 0 0 0;
  75 +}
  76 +
  77 +.field-commentmodel-email label {
  78 + width: 69px
  79 +}
  80 +
  81 +.submit_btn {
  82 + float: right;
  83 + margin-top: 27px
  84 +}
  85 +
  86 +.submit_btn button, .answer-form button {
  87 + padding: 0 17px;
  88 + height: 32px;
  89 + font-weight: 500;
  90 + font-size: 15px;
  91 + color: #fff;
  92 + border-top: 0;
  93 + border-left: 0;
  94 + border-right: 0;
  95 + border-bottom: 2px solid #799920;
  96 + background: #95ba2f;
  97 + border-radius: 4px;
  98 + cursor: pointer;
  99 + outline: none !important
  100 +}
  101 +
  102 +.submit_btn button:hover, .answer-form button:hover {
  103 + border-bottom: 2px solid #95ba2f
  104 +}
  105 +
  106 +.submit_btn button:active, .answer-form button:active {
  107 + border-bottom: 2px solid #799920;
  108 + background: #799920
  109 +}
  110 +
  111 +.answer-form button {
  112 + float: right;
  113 + margin-top: 27px;
  114 + margin-left: 10px;
  115 +}
  116 +
  117 +.comments-wr, .comment-answer {
  118 + min-height: 64px;
  119 + position: relative;
  120 + float: left;
  121 + width: 100%
  122 +}
  123 +
  124 +.answer-form {
  125 + float: left;
  126 + width: 100%
  127 +}
  128 +
  129 +.answer-form label {
  130 + position: relative;
  131 +}
  132 +
  133 +.answer-form .required label:before {
  134 + right: -7px;
  135 +}
  136 +
  137 +.user-ico {
  138 + width: 80px;
  139 + height: 80px;
  140 + float: left;
  141 + overflow: hidden;
  142 + border-radius: 50%;
  143 + position: absolute;
  144 + top: 0;
  145 + left: 0
  146 +}
  147 +
  148 +.user-ico img {
  149 + width: 100%;
  150 + height: 100%
  151 +}
  152 +
  153 +.comments-start .user_data {
  154 + margin-top: -2px;
  155 + font-size: 12px;
  156 + color: #636363;
  157 + border-right: none;
  158 +}
  159 +
  160 +.user_name {
  161 + margin-top: 6px;
  162 + font-weight: 700;
  163 + font-size: 15px
  164 +}
  165 +
  166 +.comments-start .user_name, .comments-start .user_txt, .comments-start .comment-panel, .comments-start .user_data, .comments-start .user_rating {
  167 + width: 100%;
  168 + float: left;
  169 + padding-left: 100px
  170 +}
  171 +
  172 +.user_txt {
  173 + margin-top: 8px;
  174 + font-size: 13px;
  175 + line-height: 18px
  176 +}
  177 +
  178 +.comment-panel {
  179 + width: 100%;
  180 + float: left;
  181 + margin-top: 11px
  182 +}
  183 +
  184 +.comment-panel a:first-child {
  185 + margin-left: 0
  186 +}
  187 +
  188 +.btn-comm-answer, .btn-comm-delete {
  189 + font-size: 13px;
  190 + color: #799920;
  191 + border-bottom: 1px dotted #799920
  192 +}
  193 +
  194 +.btn-comm-answer, .btn-comm-delete, .btn-comm-like, .btn-comm-dislike {
  195 + float: left;
  196 + margin-left: 10px;
  197 + text-decoration: none;
  198 + margin-top: 11px;
  199 +}
  200 +
  201 +.btn-comm-answer, .btn-comm-delete {
  202 + height: 16px;
  203 + line-height: 16px
  204 +}
  205 +
  206 +.btn-comm-answer:hover, .btn-comm-delete:hover {
  207 + text-decoration: none;
  208 + border-bottom: 0
  209 +}
  210 +
  211 +.btn-comm-like, .btn-comm-dislike {
  212 + width: 14px;
  213 + height: 16px;
  214 + background-image: url(../images/like_dislike.png);
  215 + background-repeat: no-repeat
  216 +}
  217 +
  218 +.btn-comm-like {
  219 + background-position: 0 0
  220 +}
  221 +
  222 +.btn-comm-like:hover {
  223 + background-position: 0 -16px
  224 +}
  225 +
  226 +.btn-comm-dislike:hover {
  227 + background-position: -14px -16px
  228 +}
  229 +
  230 +.btn-comm-dislike {
  231 + background-position: -14px 0
  232 +}
  233 +
  234 +.btn-comm-like:active, .btn-comm-dislike:active {
  235 + opacity: .7
  236 +}
  237 +
  238 +.comment-answer {
  239 + margin-top: 40px
  240 +}
  241 +
  242 +.comment-answer .user-ico {
  243 + left: 100px
  244 +}
  245 +
  246 +.comment-answer .user_name, .comment-answer .user_txt, .comment-answer .comment-panel, .comment-answer .user_data {
  247 + padding-left: 200px
  248 +}
  249 +
  250 +.comments-wr {
  251 + margin-top: 40px
  252 +}
  253 +
  254 +.answer-form {
  255 + margin-top: 20px
  256 +}
  257 +
  258 +.answer-form textarea {
  259 + width: 100%;
  260 + height: 90px
  261 +}
  262 +
  263 +.input_bl.has-error input, .input_bl.has-error textarea, .answer-form .has-error textarea {
  264 + box-shadow: 1px 2px 2px 0 rgba(212, 0, 0, 0.2) inset;
  265 + border: 1px solid #d2d2d2;
  266 +}
  267 +
  268 +.required.has-error label {
  269 + color: #d40000 !important;
  270 +}
  271 +
  272 +.input_bl .help-block, .answer-form .help-block {
  273 + display: none
  274 +}
  275 +
  276 +.comments-start .required label:before {
  277 + display: block;
  278 + content: "*";
  279 + color: #d40000;
  280 + position: absolute;
  281 + top: 0;
  282 + right: 3px
  283 +}
  284 +
  285 +.comments-start ul.pagination {
  286 + list-style: none;
  287 + text-align: center;
  288 + margin-top: 40px;
  289 + width: 100%;
  290 + float: left
  291 +}
  292 +
  293 +.comments-start ul.pagination li {
  294 + display: inline
  295 +}
  296 +
  297 +.comments-start ul.pagination li.prev.disabled span {
  298 + display: none
  299 +}
  300 +
  301 +.comments-start ul.pagination li.next.disabled span {
  302 + display: none
  303 +}
  304 +
  305 +.comments-start ul.pagination li a {
  306 + padding: 3px;
  307 + color: #82a02f;
  308 + font-size: 15px;
  309 + margin: 0;
  310 + text-decoration: none;
  311 + float: none;
  312 + border: none;
  313 + backgroun-color: inherit;
  314 +}
  315 +
  316 +.comments-start ul.pagination li.active a {
  317 + color: #333;
  318 + background-color: inherit;
  319 +}
0 320 \ No newline at end of file
... ...
common/modules/comment/resources/artbox_comment.js
1 1 /**
2 2 * Artbox comment plugin
  3 + *
  4 + * @todo Translate Submit and Loading texts
3 5 */
4 6 (function($)
5 7 {
... ... @@ -89,7 +91,7 @@
89 91 var $replyForm = $(this);
90 92 var $commentForm = event.data.commentForm;
91 93 settings = $commentForm.data('artbox_comment');
92   - $replyForm.find(':submit').prop('disabled', true).text('Loading...');
  94 + $replyForm.find(':submit').prop('disabled', true).text('Загрузка...');
93 95 $.post(
94 96 $replyForm.attr("action"), $replyForm.serialize(), function(data)
95 97 {
... ... @@ -99,7 +101,7 @@
99 101 $(settings.listSelector).load(
100 102 ' ' + settings.listSelector, function(data)
101 103 {
102   - $replyForm.find(':submit').prop('disabled', false).text('Submit');
  104 + $replyForm.find(':submit').prop('disabled', false).text('Добавить комментарий');
103 105 $replyForm.trigger("reset");
104 106 }
105 107 );
... ... @@ -113,7 +115,7 @@
113 115 {
114 116 $replyForm.yiiActiveForm('updateAttribute', 'commentmodel-text-reply', [data.message]);
115 117 }
116   - $replyForm.find(':submit').prop('disabled', false).text('Submit');
  118 + $replyForm.find(':submit').prop('disabled', false).text('Добавить комментарий');
117 119 }
118 120 }
119 121 );
... ... @@ -129,7 +131,7 @@
129 131 {
130 132 event.preventDefault();
131 133 var $commentForm = $(this), settings = $commentForm.data('artbox_comment');
132   - $commentForm.find(':submit').prop('disabled', true).text('Loading...');
  134 + $commentForm.find(':submit').prop('disabled', true).text('Загрузка...');
133 135 $.post(
134 136 $commentForm.attr("action"), $commentForm.serialize(), function(data)
135 137 {
... ... @@ -139,7 +141,7 @@
139 141 $(settings.listSelector).load(
140 142 ' ' + settings.listSelector, function(data)
141 143 {
142   - $commentForm.find(':submit').prop('disabled', false).text('Submit');
  144 + $commentForm.find(':submit').prop('disabled', false).text('Добавить комментарий');
143 145 $commentForm.trigger("reset");
144 146 }
145 147 );
... ... @@ -153,7 +155,7 @@
153 155 {
154 156 $commentForm.yiiActiveForm('updateAttribute', 'commentmodel-text', [data.message]);
155 157 }
156   - $commentForm.find(':submit').prop('disabled', false).text('Submit');
  158 + $commentForm.find(':submit').prop('disabled', false).text('Добавить комментарий');
157 159 }
158 160 }
159 161 );
... ...
common/modules/comment/views/artbox_comment_form.php
... ... @@ -22,23 +22,35 @@
22 22 'entity' => $comment_model->encryptedEntity,
23 23 ]),
24 24 ]);
25   - if(!empty( $rating_model )) {
26   - echo $form->field($rating_model, 'value', [ 'enableClientValidation' => false ])
27   - ->hiddenInput()
28   - ->label(false);
29   - echo Html::tag('div', '', [
30   - 'class' => 'rateit',
31   - 'data-rateit-backingfld' => '#' . Html::getInputId($rating_model, 'value'),
32   - ]);
33   - }
34   - if(\Yii::$app->user->isGuest) {
35   - echo $form->field($comment_model, 'username')
36   - ->textInput();
37   - echo $form->field($comment_model, 'email')
38   - ->textInput();
39   - }
40   - echo $form->field($comment_model, 'text')
41   - ->textarea();
42   - echo Html::submitButton(/*Yii::t('artbox-comment', 'Submit')*/
43   - 'Submit');
44   - ActiveForm::end();
45 25 \ No newline at end of file
  26 +?>
  27 + <div class="form-comm-wr">
  28 + <?php
  29 + if(!empty( $rating_model )) {
  30 + ?>
  31 + <div class="input_bl stars-wr_">
  32 + <?php
  33 + echo $form->field($rating_model, 'value', [ 'enableClientValidation' => false ])
  34 + ->hiddenInput()
  35 + ->label(false);
  36 + echo Html::tag('div', '', [
  37 + 'class' => 'rateit',
  38 + 'data-rateit-backingfld' => '#' . Html::getInputId($rating_model, 'value'),
  39 + ]);
  40 + ?>
  41 + </div>
  42 + <?php
  43 + }
  44 + if(\Yii::$app->user->isGuest) {
  45 + echo $form->field($comment_model, 'username', [ 'options' => [ 'class' => 'form-group input_bl' ] ])
  46 + ->textInput();
  47 + echo $form->field($comment_model, 'email', [ 'options' => [ 'class' => 'form-group input_bl' ] ])
  48 + ->textInput();
  49 + }
  50 + echo $form->field($comment_model, 'text', [ 'options' => [ 'class' => 'form-group input_bl area_bl' ] ])
  51 + ->textarea();
  52 + echo Html::tag('div', Html::submitButton(Yii::t('artbox-comment', 'Submit')), [ 'class' => 'input_bl submit_btn' ]);
  53 + ?>
  54 + </div>
  55 +<?php
  56 + ActiveForm::end();
  57 +?>
46 58 \ No newline at end of file
... ...
common/modules/comment/views/artbox_comment_item.php
1 1 <?php
2 2 use common\modules\comment\models\CommentModel;
  3 + use yii\helpers\Html;
3 4 use yii\helpers\Url;
4 5 use yii\widgets\ListView;
5 6  
... ... @@ -10,146 +11,134 @@
10 11 * @var ListView $widget
11 12 */
12 13 ?>
13   -<div class="artbox_item_info">
14   - <div>
15   - <span>Пользователь:</span>
16   - <span>
  14 +<div class="comments-wr">
  15 + <div class="artbox_item_info">
  16 + <div class="user-ico">
  17 + <?php
  18 + echo Html::img('/img/user-noimage.png');
  19 + ?>
  20 + </div>
  21 + <div class="user_data">
  22 + <?php
  23 + echo date('d.m.Y', $model->date_add);
  24 + ?>
  25 + </div>
  26 + <div class="user_name">
17 27 <?php
18 28 if(!empty( $model->user )) {
19 29 echo $model->user->username;
20 30 } else {
21   - echo $model->username . ' (' . $model->email . ')';
  31 + echo $model->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')';
22 32 }
23 33 ?>
24   - </span>
25   - </div>
26   - <?php
27   - if(!empty( $model->rating )) {
28   - ?>
29   - <div>
30   - <span>Рейтинг:</span>
31   - <div class="rateit" data-rateit-value="<?php echo $model->rating->value; ?>" data-rateit-ispreset="true" data-rateit-readonly="true"></div>
32   - </div>
33   - <?php
34   - }
35   - ?>
36   - <div>
37   - <span>Дата: </span>
38   - <span>
39   - <?php
40   - echo date('d.m.Y', $model->date_add);
41   - ?>
42   - </span>
43   - </div>
44   - <div>
45   - <span>Сообщение: </span>
46   - <span>
  34 + </div>
47 35 <?php
48   - echo $model->text;
  36 + if(!empty( $model->rating )) {
  37 + ?>
  38 + <div class="user_rating">
  39 + <div class="rateit" data-rateit-value="<?php echo $model->rating->value; ?>" data-rateit-ispreset="true" data-rateit-readonly="true"></div>
  40 + </div>
  41 + <?php
  42 + }
49 43 ?>
50   - </span>
  44 + <div class="user_txt">
  45 + <?php
  46 + echo $model->text;
  47 + ?>
  48 + </div>
51 49 </div>
52   -</div>
53   -<div class="artbox_item_tools">
54   - <ul>
  50 + <div class="artbox_item_tools comment-panel">
55 51 <?php
56 52 if(!\Yii::$app->user->isGuest) {
57 53 ?>
58   - <li><a href="" data-action="reply">Ответить</a></li>
  54 + <a href="" class="btn-comm-answer" data-action="reply">Ответить</a>
59 55 <?php
60 56 }
61 57 if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $model->user_id) {
62 58 ?>
63   - <li><a href="" data-action="delete" data-url="<?php echo Url::to([
64   - 'artbox-comment/default/delete',
65   - 'id' => $model->artbox_comment_id,
66   - ]); ?>">Удалить</a></li>
  59 + <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to([
  60 + 'artbox-comment/default/delete',
  61 + 'id' => $model->artbox_comment_id,
  62 + ]); ?>">Удалить</a>
67 63 <?php
68 64 }
69 65 // Like / dislike to be done
70 66 /*
71 67 ?>
72   - <li><a href="" data-action="like" data-url="<?php echo Url::to([
  68 + <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([
73 69 'artbox-comment/default/like',
74 70 'id' => $model->artbox_comment_id,
75   - ]); ?>">Like</a></li>
76   - <li><a href="" data-action="dislike" data-url="<?php echo Url::to([
  71 + ]); ?>">Like</a>
  72 + <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([
77 73 'artbox-comment/default/dislike',
78 74 'id' => $model->artbox_comment_id,
79   - ]); ?>">Dislike</a></li>
  75 + ]); ?>">Dislike</a>
80 76 <?php
81 77 */
82 78 ?>
83   - </ul>
84   - <div class="artbox_item_reply"></div>
  79 + <div class="artbox_item_reply"></div>
  80 + </div>
85 81 </div>
86 82 <div class="artbox_children_container">
87 83 <?php
88 84 if(!empty( $model->children )) {
89 85 foreach($model->children as $index => $child) {
90 86 ?>
91   - <div class="artbox_child_container">
  87 + <div class="artbox_child_container comment-answer">
92 88 <div class="artbox_child_info">
93   - <div>
94   - <span>Пользователь:</span>
95   - <span>
  89 + <div class="user-ico">
96 90 <?php
97   - if(!empty( $child->user )) {
98   - echo $child->user->username;
99   - } else {
100   - echo $child->username . ' (' . $child->email . ')';
101   - }
  91 + echo Html::img('/img/user-noimage.png');
102 92 ?>
103   - </span>
104 93 </div>
105   - <div>
106   - <span>Дата: </span>
107   - <span>
  94 + <div class="user_data">
108 95 <?php
109 96 echo date('d.m.Y', $child->date_add);
110 97 ?>
111   - </span>
112 98 </div>
113   - <div>
114   - <span>Сообщение: </span>
115   - <span>
  99 + <div class="user_name">
  100 + <?php
  101 + if(!empty( $child->user )) {
  102 + echo $child->user->username;
  103 + } else {
  104 + echo $child->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')';
  105 + }
  106 + ?>
  107 + </div>
  108 + <div class="user_txt">
116 109 <?php
117 110 echo $child->text;
118 111 ?>
119   - </span>
120 112 </div>
121 113 </div>
122   - <div class="artbox_child_tools">
123   - <ul>
  114 + <div class="artbox_child_tools comment-panel">
124 115 <?php
125 116 if(!\Yii::$app->user->isGuest) {
126 117 ?>
127   - <li><a href="" data-action="reply">Ответить</a></li>
  118 + <a href="" class="btn-comm-answer" data-action="reply">Ответить</a>
128 119 <?php
129 120 }
130 121 if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $child->user_id) {
131 122 ?>
132   - <li>
133   - <a href="" data-action="delete" data-url="<?php echo Url::to([
  123 + <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to([
134 124 'artbox-comment/default/delete',
135 125 'id' => $child->artbox_comment_id,
136   - ]); ?>">Удалить</a></li>
  126 + ]); ?>">Удалить</a>
137 127 <?php
138 128 }
139 129 /* Like /dislike to be done
140 130 ?>
141   - <li><a href="" data-action="like" data-url="<?php echo Url::to([
  131 + <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([
142 132 'artbox-comment/default/like',
143 133 'id' => $child->artbox_comment_id,
144   - ]); ?>">Like</a></li>
145   - <li><a href="" data-action="dislike" data-url="<?php echo Url::to([
  134 + ]); ?>">Like</a>
  135 + <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([
146 136 'artbox-comment/default/dislike',
147 137 'id' => $child->artbox_comment_id,
148   - ]); ?>">Dislike</a></li>
  138 + ]); ?>">Dislike</a>
149 139 <?php
150 140 */
151 141 ?>
152   - </ul>
153 142 <div class="artbox_child_reply"></div>
154 143 </div>
155 144 </div>
... ...
common/modules/comment/views/artbox_comment_list.php
... ... @@ -16,7 +16,7 @@
16 16 * @var ActiveDataProvider $comments
17 17 * @var View $this
18 18 */
19   - //Pjax::begin();
  19 + Pjax::begin();
20 20 if(($success = \Yii::$app->session->getFlash('artbox_comment_success')) != null) {
21 21 echo Html::tag('p', $success);
22 22 }
... ... @@ -24,6 +24,7 @@
24 24 'dataProvider' => $comments,
25 25 'itemOptions' => $item_options,
26 26 'itemView' => $item_view,
  27 + 'summary' => '',
27 28 ]);
28   - //Pjax::end();
  29 + Pjax::end();
29 30  
30 31 \ No newline at end of file
... ...
common/modules/comment/views/artbox_comment_reply.php
... ... @@ -30,25 +30,32 @@
30 30 'entity' => $comment_model->encryptedEntity,
31 31 ]),
32 32 ]);
33   - echo $form->field($comment_model, 'artbox_comment_pid', [
34   - 'selectors' => $artbox_comment_pid_input_selectors,
35   - 'inputOptions' => [
36   - 'id' => $artbox_comment_pid_input_id,
37   - 'class' => 'form-control',
38   - ],
39   - ])
40   - ->hiddenInput()
41   - ->label(false);
42   - echo $form->field($comment_model, 'text', [
43   - 'selectors' => $text_input_selectors,
44   - 'inputOptions' => [
45   - 'id' => $text_input_id,
46   - 'class' => 'form-control',
47   - ],
48   - ])
49   - ->textarea();
50   - echo Html::submitButton(/*Yii::t('artbox-comment', 'Submit')*/
51   - 'Submit');
52   - echo Html::button(/*Yii::t('artbox-comment', 'Cancel')*/
53   - 'Cancel', [ 'data-action' => 'reply-cancel' ]);
54   - ActiveForm::end();
55 33 \ No newline at end of file
  34 +?>
  35 + <div class="answer-form">
  36 + <?php
  37 + echo $form->field($comment_model, 'artbox_comment_pid', [
  38 + 'selectors' => $artbox_comment_pid_input_selectors,
  39 + 'inputOptions' => [
  40 + 'id' => $artbox_comment_pid_input_id,
  41 + 'class' => 'form-control',
  42 + ],
  43 + ])
  44 + ->hiddenInput()
  45 + ->label(false);
  46 + echo $form->field($comment_model, 'text', [
  47 + 'selectors' => $text_input_selectors,
  48 + 'inputOptions' => [
  49 + 'id' => $text_input_id,
  50 + 'class' => 'form-control',
  51 + 'cols' => 30,
  52 + 'rows' => 10,
  53 + ],
  54 + ])
  55 + ->textarea();
  56 + echo Html::submitButton(Yii::t('artbox-comment', 'Submit'));
  57 + echo Html::button(Yii::t('artbox-comment', 'Cancel'), [ 'data-action' => 'reply-cancel' ]);
  58 + ?>
  59 + </div>
  60 +<?php
  61 + ActiveForm::end();
  62 +?>
56 63 \ No newline at end of file
... ...
common/modules/comment/widgets/CommentWidget.php
... ... @@ -32,7 +32,7 @@
32 32 * Options
33 33 * @var array
34 34 */
35   - public $options = [ 'class' => 'artbox_comment_container' ];
  35 + public $options = [ 'class' => 'artbox_comment_container comments-start', 'id' => 'artbox-comment' ];
36 36  
37 37 /**
38 38 * @var string the view file that will render comment form.
... ... @@ -138,7 +138,7 @@
138 138 */
139 139 public $pjaxContainerId;
140 140  
141   - public $layout = "{form} {reply_form} {list}";
  141 + public $layout = "<div class='comments-border'></div>{form} {reply_form} {list}";
142 142  
143 143 /**
144 144 * Model fully namespaced classname
... ... @@ -215,6 +215,7 @@
215 215 'entity' => $this->entity,
216 216 'entityId' => $this->entityId,
217 217 'encryptedEntity' => $this->encryptedEntityKey,
  218 + 'scenario' => \Yii::$app->user->getIsGuest()?$commentModelClass::SCENARIO_GUEST:$commentModelClass::SCENARIO_USER,
218 219 ]);
219 220 if($module::$enableRating) {
220 221 $ratingModelClass = $module->ratingModelClass;
... ... @@ -240,7 +241,7 @@
240 241 $options = Json::encode($this->clientOptions);
241 242 $view = $this->getView();
242 243 CommentAsset::register($view);
243   - $view->registerJs("jQuery('#{$this->formId}').artbox_comment({$options})", $view::POS_END);
  244 + $view->registerJs("jQuery('#{$this->formId}').artbox_comment({$options});");
244 245 }
245 246  
246 247 /**
... ...
common/modules/product/models/Product.php
... ... @@ -5,16 +5,13 @@ namespace common\modules\product\models;
5 5 use common\behaviors\Slug;
6 6 use common\models\ProductToRating;
7 7 use common\models\Share;
8   -use common\modules\comment\models\Comment;
  8 +use common\modules\comment\models\CommentModel;
9 9 use common\modules\product\behaviors\FilterBehavior;
10 10 use common\modules\rubrication\models\TaxGroup;
11 11 use common\modules\rubrication\models\TaxOption;
12 12 use Yii;
13 13 use common\modules\relation\relationBehavior;
14   -use yii\db\ActiveQuery;
15 14 use yii\db\ActiveRecord;
16   -use yii\helpers\Html;
17   -use yii\web\UploadedFile;
18 15  
19 16 /**
20 17 * This is the model class for table "{{%product}}".
... ... @@ -392,7 +389,7 @@ class Product extends \yii\db\ActiveRecord
392 389 /**
393 390 * @var ProductToRating $averageRating
394 391 */
395   - $average = $this->getComments()->joinWith('rating')->select(['average' => 'avg(rating.value)::float'])->scalar();
  392 + $average = $this->getComments()->joinWith('rating')->select(['average' => 'avg(artbox_comment_rating.value)::float'])->scalar();
396 393 if(!$average) {
397 394 $average = 0;
398 395 }
... ... @@ -410,7 +407,7 @@ class Product extends \yii\db\ActiveRecord
410 407 }
411 408  
412 409 public function getComments() {
413   - return $this->hasMany(Comment::className(), ['model_id' => 'product_id'])->where(['comment.model' => self::className(), 'comment.status' => Comment::STATUS_ACTIVE]);
  410 + return $this->hasMany(CommentModel::className(), ['entity_id' => 'product_id'])->where(['artbox_comment.entity' => self::className(), 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, 'artbox_comment.artbox_comment_pid' => NULL]);
414 411 }
415 412  
416 413 public function getAverageRating() {
... ...
frontend/assets/AppAsset.php
... ... @@ -19,7 +19,7 @@ class AppAsset extends AssetBundle
19 19 public $baseUrl = '@web';
20 20 public $css = [
21 21 'css/style.css',
22   - 'css/comments.css',
  22 + //'css/comments.css',
23 23 'http://fonts.googleapis.com/css?family=Roboto',
24 24 ];
25 25 public $js = [
... ...
frontend/controllers/CatalogController.php
... ... @@ -121,8 +121,8 @@ class CatalogController extends \yii\web\Controller
121 121 /*
122 122 * Greedy search for comments and rating
123 123 */
124   -// $query = $productProvider->query;
125   -// $query->with(['comments', 'averageRating']);
  124 + $query = $productProvider->query;
  125 + $query->with(['comments', 'averageRating']);
126 126 /*
127 127 * End of greedy search for rating and comments
128 128 */
... ...
frontend/views/catalog/product.php
... ... @@ -175,9 +175,6 @@
175 175 </ul>
176 176 </div>
177 177 <div class="artbox_comment_description">
178   - <?php
179   - /*
180   - ?>
181 178 <?php
182 179 if(!empty( $product->averageRating ) && $product->averageRating->value) {
183 180 ?>
... ... @@ -195,9 +192,6 @@
195 192 }
196 193 ?>
197 194 </a></p>
198   - <?php
199   - */
200   - ?>
201 195 </div>
202 196 <br>
203 197 <?php
... ... @@ -291,13 +285,15 @@
291 285 </ul>
292 286 </div>
293 287 <div class="both"></div>
294   - <div class="comment-wrapper">
  288 + <div class="comment-wrapper" style="padding-bottom:25px">
295 289 <?php
296   - // echo CommentWidget::widget([
297   - // 'model' => $product,
298   - // ]);
  290 + echo CommentWidget::widget([
  291 + 'model' => $product,
  292 + ]);
299 293 ?>
  294 + <div class="both"></div>
300 295 </div>
  296 + <div class="both"></div>
301 297 <?= \common\modules\product\widgets\similarProducts::widget([ 'product' => $product ]) ?>
302 298 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'promo' ]) ?>
303 299 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'new' ]) ?>
... ...
frontend/views/catalog/product_item.php
1 1 <?php
2 2 /** @var \common\modules\product\models\Product $product */
3   -// use common\modules\comment\assets\CommentAsset;
  3 + use common\modules\comment\assets\CommentAsset;
4 4 use yii\helpers\Html;
5 5 use yii\helpers\Url;
6 6  
7   -// CommentAsset::register($this);
  7 + Yii::$app->getModule('artbox-comment');
  8 + CommentAsset::register($this);
8 9 ?>
9 10 <li class="item" itemscope itemtype="http://schema.org/Product">
10 11 <div class="boxitem">
... ... @@ -41,8 +42,6 @@
41 42 <?php endif ?>
42 43 <div class="comment_display_block">
43 44 <?php
44   - /*
45   - <?php
46 45 if(!empty( $product->averageRating && $product->averageRating->value > 0)) {
47 46 ?>
48 47 <div class="rateit" data-rateit-value="<?php echo $product->averageRating->value; ?>" data-rateit-readonly="true" data-rateit-ispreset="true"></div>
... ... @@ -59,8 +58,6 @@
59 58 ]);
60 59 ?>
61 60 </p>
62   - */
63   - ?>
64 61 </div>
65 62 <div itemprop="name"><a href="<?= Url::to([
66 63 'catalog/product',
... ...
frontend/web/img/user-noimage.png 0 → 100644

3.09 KB