Commit 8a55149415c1ccd5a847a6feb694cbfd724a31e9

Authored by Yarik
1 parent 8ab566d4

test

common/modules/comment/Controller.php
... ... @@ -3,13 +3,16 @@
3 3  
4 4 class Controller extends \yii\web\Controller
5 5 {
  6 +
  7 + public $enableCsrfValidation = false;
  8 +
6 9 public function behaviors()
7 10 {
8 11 return [
9 12 'verbs' => [
10   - 'class' => \yii\filters\VerbFilter::className(),
  13 + 'class' => \yii\filters\VerbFilter::className(),
11 14 'actions' => [
12   - '*' => ['post'],
  15 + '*' => [ 'post' ],
13 16 ],
14 17 ],
15 18 ];
... ... @@ -20,25 +23,25 @@
20 23 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
21 24 $post = \Yii::$app->request->post('Comment');
22 25 $get = \Yii::$app->request->get();
23   - if(empty($post['comment_id']) && !empty($get['comment_id'])) {
24   - $post['comment_id'] = $get['comment_id'];
  26 + if(empty( $post[ 'comment_id' ] ) && !empty( $get[ 'comment_id' ] )) {
  27 + $post[ 'comment_id' ] = $get[ 'comment_id' ];
25 28 }
26   - if(!empty($post['comment_id'])) {
27   - if($model = \common\modules\comment\models\Comment::findOne($post['comment_id'])) {
  29 + if(!empty( $post[ 'comment_id' ] )) {
  30 + if($model = \common\modules\comment\models\Comment::findOne($post[ 'comment_id' ])) {
28 31 /**
29 32 * @var \common\modules\comment\models\Comment $model
30 33 */
31 34 $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;
32 35 if($model->deleteComment()) {
33   - \Yii::$app->response->data = ['text' => 'Comment marked as deleted and will be check by administrators'];
  36 + \Yii::$app->response->data = [ 'text' => 'Comment marked as deleted and will be check by administrators' ];
34 37 } else {
35   - \Yii::$app->response->data = ['error' => $model->hasErrors('comment_id')?$model->getFirstError('comment_id'):'Cannot delete message'];
  38 + \Yii::$app->response->data = [ 'error' => $model->hasErrors('comment_id') ? $model->getFirstError('comment_id') : 'Cannot delete message' ];
36 39 }
37   - }else {
38   - \Yii::$app->response->data = ['error' => 'Comment not found'];
  40 + } else {
  41 + \Yii::$app->response->data = [ 'error' => 'Comment not found' ];
39 42 };
40 43 } else {
41   - \Yii::$app->response->data = ['error' => 'Missing comment_id'];
  44 + \Yii::$app->response->data = [ 'error' => 'Missing comment_id' ];
42 45 }
43 46 \Yii::$app->response->send();
44 47 }
... ... @@ -47,55 +50,80 @@
47 50 {
48 51 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
49 52 $post = \Yii::$app->request->post();
50   - if(!empty($post['Comment']['comment_id'])) {
51   - if($model = \common\modules\comment\models\Comment::findOne($post['Comment']['comment_id'])) {
  53 + if(!empty( $post[ 'Comment' ][ 'comment_id' ] )) {
  54 + if($model = \common\modules\comment\models\Comment::findOne($post[ 'Comment' ][ 'comment_id' ])) {
52 55 /**
53 56 * @var \common\modules\comment\models\Comment $model
54 57 */
55 58 $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;
56 59 $model->load($post);
57   - if(empty($post['Comment']['comment_pid'])) {
58   - $model->comment_pid = null;
  60 + if(empty( $post[ 'Comment' ][ 'comment_pid' ] )) {
  61 + $model->comment_pid = NULL;
59 62 }
60 63 if($model->updateComment()) {
61   - \Yii::$app->response->data = ['text' => 'Comment successfully updated'];
  64 + $model->rating->load($post);
  65 + if($model->rating->save()) {
  66 + return [
  67 + 'result' => [
  68 + 'text' => 'Comment successfully updated',
  69 + 'html' => $this->renderAjax('@common/modules/comment/widgets/views/_review_comment_view', [ 'model' => $model ]),
  70 + ],
  71 + ];
  72 + } else {
  73 + return [
  74 + 'error' => $model->hasErrors() ? $model->getFirstErrors() : 'Cannot update message',
  75 + 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-review', [
  76 + 'model' => $model,
  77 + ]),
  78 + ];
  79 + }
62 80 } else {
63   - \Yii::$app->response->data = ['error' => $model->hasErrors()?$model->getFirstErrors():'Cannot update message'];
  81 + return [
  82 + 'error' => $model->hasErrors() ? $model->getFirstErrors() : 'Cannot update message',
  83 + 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-review', [
  84 + 'model' => $model,
  85 + ]),
  86 + ];
64 87 }
65   - }else {
66   - \Yii::$app->response->data = ['error' => 'Comment not found'];
67   - };
  88 + } else {
  89 + return [ 'error' => 'Comment not found' ];
  90 + }
68 91 } else {
69   - \Yii::$app->response->data = ['error' => 'Missing comment_id'];
  92 + return [ 'error' => 'Missing comment_id' ];
70 93 }
71   - \Yii::$app->response->send();
72 94 }
73 95  
74 96 public function actionForm()
75 97 {
  98 + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
76 99 $post = \Yii::$app->request->post('Comment');
77   - if(!empty($post['comment_id'])) {
78   - $model = \common\modules\comment\models\Comment::find()->where(['comment_id' => $post['comment_id']])->with('parent', 'author')->one();
  100 + if(!empty( $post[ 'comment_id' ] )) {
  101 + $model = \common\modules\comment\models\Comment::find()
  102 + ->where([ 'comment_id' => $post[ 'comment_id' ] ])
  103 + ->with('parent', 'author')
  104 + ->one();
79 105 if($model) {
80 106 /**
81 107 * @var \common\modules\comment\models\Comment $model
82 108 */
83 109 $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;
84 110 if($model->checkUpdate()) {
85   - return $this->renderAjax('@common/modules/comment/views/comment_form', [
86   - 'model' => $model,
87   - ]);
  111 + return [
  112 + 'result' => [
  113 + 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-review', [
  114 + 'model' => $model,
  115 + ]),
  116 + ],
  117 + ];
88 118 } else {
89   - \Yii::$app->response->data = ['error' => 'You are not able to update this comment'];
  119 + return [ 'error' => 'You are not able to update this comment' ];
90 120 }
91   - }else {
92   - \Yii::$app->response->data = ['error' => 'Comment not found'];
93   - };
  121 + } else {
  122 + return [ 'error' => 'Comment not found' ];
  123 + }
94 124 } else {
95   - \Yii::$app->response->data = ['error' => 'Missing comment_id'];
  125 + return [ 'error' => 'Missing comment_id' ];
96 126 }
97   - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
98   - \Yii::$app->response->send();
99 127 }
100 128  
101 129 }
102 130 \ No newline at end of file
... ...
common/modules/comment/assets/CommentAsset.php
... ... @@ -20,7 +20,7 @@
20 20 ];
21 21  
22 22 public $jsOptions = [
23   - 'position' => \yii\web\View::POS_READY,
  23 + 'position' => \yii\web\View::POS_HEAD,
24 24 ];
25 25  
26 26 }
27 27 \ No newline at end of file
... ...
common/modules/comment/models/Comment.php
... ... @@ -22,6 +22,7 @@
22 22 * @property int $model_id
23 23 * @property Rating $rating
24 24 * @property User $user
  25 + * @property User $author
25 26 * @package common\modules\comment\models
26 27 */
27 28 class Comment extends \yii\db\ActiveRecord
... ... @@ -206,7 +207,7 @@
206 207 return false;
207 208 } else {
208 209 if($this->update()) {
209   - $this->clearSafe();
  210 + // $this->clearSafe(); Clears safe attributes after AJAX update
210 211 return true;
211 212 } else {
212 213 return false;
... ... @@ -271,9 +272,11 @@
271 272 return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [
272 273 'model' => $this->model,
273 274 'model_id' => $this->model_id,
  275 + 'comment' => $this,
274 276 ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [
275 277 'model' => $this->model,
276 278 'model_id' => $this->model_id,
  279 + 'comment' => $this,
277 280 ]);
278 281 }
279 282 }
... ... @@ -283,15 +286,24 @@
283 286 if($this->scenario == self::SCENARIO_GUEST) {
284 287 return false;
285 288 } else {
286   - return (\Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [
287   - 'model' => $this->model,
288   - 'model_id' => $this->model_id,
289   - 'comment' => $this,
290   - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [
291   - 'model' => $this->model,
292   - 'model_id' => $this->model_id,
293   - 'comment' => $this,
294   - ]));
  289 + return ( \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [
  290 + 'model' => $this->model,
  291 + 'model_id' => $this->model_id,
  292 + 'comment' => $this,
  293 + ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [
  294 + 'model' => $this->model,
  295 + 'model_id' => $this->model_id,
  296 + 'comment' => $this,
  297 + ]) );
  298 + }
  299 + }
  300 +
  301 + public function checkReply()
  302 + {
  303 + if($this->scenario == self::SCENARIO_GUEST) {
  304 + return false;
  305 + } else {
  306 + return $this->allowReply;
295 307 }
296 308 }
297 309  
... ... @@ -310,6 +322,15 @@
310 322 return $this->hasOne(self::className(), [ 'comment_id' => 'comment_pid' ]);
311 323 }
312 324  
  325 + public function getAuthorName()
  326 + {
  327 + if(!empty( $this->author )) {
  328 + return $this->author->name;
  329 + } else {
  330 + return $this->user_name;
  331 + }
  332 + }
  333 +
313 334 public function getAuthor()
314 335 {
315 336 // if($this->user_id != NULL) {
... ... @@ -378,6 +399,23 @@
378 399 'comment_id' => $this->comment_id,
379 400 ]);
380 401 }
  402 + if($this->checkUpdate()) {
  403 + $this->buttons[ 'update' ] = Url::to([
  404 + 'artbox-comment/update',
  405 + 'comment_id' => $this->comment_id,
  406 + ]);
  407 + }
  408 + if($this->checkReply()) {
  409 + $this->buttons[ 'reply' ] = Url::to([
  410 + 'artbox-comment/reply',
  411 + 'comment_id' => $this->comment_id,
  412 + ]);
  413 + }
  414 + }
  415 +
  416 + public function getAllowReply()
  417 + {
  418 + return $this->hasAttribute('comment_pid');
381 419 }
382 420  
383 421 }
... ...
common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php
... ... @@ -11,6 +11,9 @@
11 11  
12 12 public function execute($user, $item, $params)
13 13 {
  14 + if($params['comment']->user_id == \Yii::$app->user->id) {
  15 + return true;
  16 + }
14 17 return false;
15 18 }
16 19  
... ...
common/modules/comment/rbac/ArtboxCommentUpdateRule.php
... ... @@ -11,7 +11,7 @@
11 11  
12 12 public function execute($user, $item, $params)
13 13 {
14   - return true;
  14 + return false;
15 15 }
16 16  
17 17 }
18 18 \ No newline at end of file
... ...
common/modules/comment/resources/comment.css
... ... @@ -16,4 +16,25 @@
16 16 height: 13px;
17 17 top: 0;
18 18 cursor: pointer;
19   -}
20 19 \ No newline at end of file
  20 +}
  21 +.removeable {
  22 + color: #a94442;
  23 + background-color: #f2dede;
  24 + border-color: #ebccd1;
  25 + border-radius: 4px;
  26 + padding: 15px;
  27 + padding-right: 35px;
  28 + position: relative;
  29 +}
  30 +.removeable::after {
  31 + content: ' ';
  32 + display: block;
  33 + position: absolute;
  34 + right: 5px;
  35 + top: 5px;
  36 + width: 15px;
  37 + height: 15px;
  38 + background: url('delete-ico.png');
  39 + background-size: cover;
  40 + cursor: pointer;
  41 +}
... ...
common/modules/comment/resources/comment.js
1 1 $(function() {
2 2  
3   - $(document).on('click', '.artbox_comment_delete', function() {
  3 + $(document).on('click', '.artbox_comment_container .removeable', function(e) {
  4 + e.preventDefault();
4 5 var container = $(this).parents('.artbox_comment_container');
5   - var comment_id = $(container).data('comment_id');
6   - var form_name = $(container).data('form_name');
7   - if(confirm("Уверены, что хотите удалить комментарий?")) {
8   - $.post(
9   - '/artbox-comment/delete',
10   - {
11   - Comment: {
12   - comment_id: comment_id
13   - }
14   - },
15   - function(data, textStatus, jqXHR) {
16   - if(!data.error) {
17   - $(container).after('<p class="removeable">'+data.text+'</p>');
18   - $(container).remove();
19   - } else {
20   - $(container).prepend('<p class="removeable error_message">'+data.error+'</p>')
  6 + $(container).remove();
  7 + });
  8 +
  9 + $(document).on(
  10 + 'click', '.artbox_comment_delete', function(e)
  11 + {
  12 + e.preventDefault();
  13 + var container = $(this).parents('.artbox_comment_container');
  14 + var comment_id = $(container).data('key');
  15 + var form_name = $(container).data('form');
  16 + if(confirm("Уверены, что хотите удалить комментарий?"))
  17 + {
  18 + $.post(
  19 + '/artbox-comment/delete', {
  20 + Comment : {
  21 + comment_id : comment_id
  22 + }
  23 + }, function(data, textStatus, jqXHR)
  24 + {
  25 + if(!data.error)
  26 + {
  27 + $(container).empty();
  28 + $(container).append('<p class="removeable">' + data.text + '</p>');
  29 + } else
  30 + {
  31 + $(container).prepend('<p class="removeable error_message">' + data.error + '</p>')
  32 + }
21 33 }
  34 + );
  35 + }
  36 + }
  37 + );
  38 +
  39 + $(document).on(
  40 + 'click', '.artbox_comment_reply', function(e)
  41 + {
  42 + e.preventDefault();
  43 + var container = $(this).parents('.artbox_comment_container').first();
  44 + var comment_id = $(container).data('key');
  45 + var form_name = $(container).data('form');
  46 + var author = $(container).find('.artbox_comment_author').first().text();
  47 + var comment_form = $(container).parents('.artbox_comment_widget').find('.artbox_comment_form').first();
  48 + var offset = $(comment_form).offset();
  49 + var reply_block = $(comment_form).find('.artbox_comment_reply_block').first();
  50 + $(reply_block).empty();
  51 + $(reply_block).append('<input type="hidden" name="' + form_name + '[comment_pid]" value="' + comment_id + '">');
  52 + $(reply_block).append('<p class="artbox_comment_reply_author">' + author + '</p>');
  53 + $('html, body').animate(
  54 + {
  55 + scrollTop : offset.top - 50,
22 56 }
23 57 );
24 58 }
25   - });
  59 + );
26 60  
27   - $(document).on('click', '.artbox_comment_reply', function() {
28   - var container = $(this).parents('.artbox_comment_container').first();
29   - var comment_id = $(container).data('comment_id');
30   - var form_name = $(container).data('form_name');
31   - var author = $(container).find('.artbox_comment_author').first().text();
32   - var comment_form = $('.artbox_comment_form').first();
33   - var offset = $(comment_form).offset();
34   - var reply_block = $(comment_form).find('.artbox_comment_reply_block').first();
35   - $(reply_block).empty();
36   - $(reply_block).append('<input type="hidden" name="'+form_name+'[comment_pid]" value="'+comment_id+'">');
37   - $(reply_block).append('<p class="artbox_comment_reply_author">'+author+'</p>');
38   - $('html, body').animate({
39   - scrollTop: offset.top - 50,
40   - });
41   - });
42   -
43   - $(document).on('click', '.artbox_comment_reply_author', function() {
44   - $(this).parents('.artbox_comment_reply_block').first().empty();
45   - });
  61 + $(document).on(
  62 + 'click', '.artbox_comment_reply_author', function()
  63 + {
  64 + $(this).parents('.artbox_comment_reply_block').first().empty();
  65 + }
  66 + );
46 67  
47   - $(document).on('click', '.artbox_comment_update', function() {
48   - $(this).removeClass('artbox_comment_update');
49   - $(this).text('Сохранить');
50   - $(this).addClass('artbox_comment_update_submit');
51   - var container = $(this).parents('.artbox_comment_container').first();
52   - var comment_id = $(container).data('comment_id');
53   - var form_name = $(container).data('form_name');
54   - var text = $(container).find('.artbox_comment_text');
55   - var object = {};
56   - object[form_name] = {comment_id: comment_id};
57   - $.post(
58   - '/artbox-comment/form',
59   - object,
60   - function(data, textStatus, jqXHR) {
61   - $(text).hide();
62   - $(text).after(
63   - '<div class="artbox_comment_text_edit new-portf-answer">'
64   - + data
65   - + '</div>'
66   - );
67   - }
68   - );
69   - });
  68 + $(document).on(
  69 + 'click', '.artbox_comment_update', function(e)
  70 + {
  71 + e.preventDefault();
  72 + var container = $(this).parents('.artbox_comment_container').first();
  73 + var comment_id = $(container).data('key');
  74 + var form_name = $(container).data('form');
  75 + var object = {};
  76 + object[form_name] = {comment_id : comment_id};
  77 + $.post(
  78 + '/artbox-comment/form', object, function(data, textStatus, jqXHR)
  79 + {
  80 + $(container).empty();
  81 + $(container).append(data.result.form);
  82 + }
  83 + );
  84 + }
  85 + );
70 86  
71   - $(document).on('click', '.artbox_comment_update_reply', function() {
72   - $(this).remove();
73   - });
  87 + // @TODO What is this
  88 + $(document).on(
  89 + 'click', '.artbox_comment_update_reply', function()
  90 + {
  91 + $(this).remove();
  92 + }
  93 + );
74 94  
75   - $(document).on('click', '.artbox_comment_update_submit', function(e) {
76   - e.preventDefault();
77   - var container = $(this).parents('.artbox_comment_container').first();
78   - var edit = $(container).find('.artbox_comment_text_edit').first();
79   - $.post(
80   - '/artbox-comment/update',
81   - $(edit).find('form').serialize(),
82   - function(data) {
83   - if(!data.error) {
84   - location.reload(true);
  95 + $(document).on(
  96 + 'click', '.artbox_comment_update_submit', function(e)
  97 + {
  98 + e.preventDefault();
  99 + var container = $(this).parents('.artbox_comment_container').first();
  100 + $.post(
  101 + '/artbox-comment/update', $(container).find('form').serialize(), function(data)
  102 + {
  103 + $(container).empty();
  104 + if(!data.error)
  105 + {
  106 + $(container).append('<p>'+data.result.text+'</p>');
  107 + $(container).append(data.result.html);
  108 + } else {
  109 + $(container).append(data.form);
  110 + }
85 111 }
86   - }
87   - )
88   - });
89   -});
90 112 \ No newline at end of file
  113 + )
  114 + }
  115 + );
  116 +});
... ...
common/modules/comment/widgets/CommentWidget.php
1 1 <?php
2 2 namespace common\modules\comment\widgets;
3 3  
  4 + use yii\data\Sort;
4 5 use \yii\helpers\ArrayHelper;
5 6 use \yii\helpers\Html;
6 7  
... ... @@ -8,6 +9,31 @@
8 9 {
9 10  
10 11 /**
  12 + * 'comment_container' - apply to container of one comment. Must have data-key and data-form
  13 + * 'comment_delete' - apply to comment delete link
  14 + * 'comment_reply' - apply to comment reply link
  15 + * 'comment_author' - apply to comment author text wrapper
  16 + * 'widget_container' - apply to comment widget
  17 + * 'form_container' - apply to comment form wrapper
  18 + * 'reply_block' - apply to reply block of comment form
  19 + * 'reply_author' - apply to reply author text block inside of reply block of comment form
  20 + * 'comment_update' - apply to comment update link
  21 + * 'comment_update_submit' - apply to submit button of comment update form
  22 + */
  23 + static $baseClass = [
  24 + 'comment_container' => 'artbox_comment_container',
  25 + 'comment_delete' => 'artbox_comment_delete',
  26 + 'comment_reply' => 'artbox_comment_reply',
  27 + 'comment_author' => 'artbox_comment_author',
  28 + 'widget_container' => 'artbox_comment_widget',
  29 + 'form_container' => 'artbox_comment_form',
  30 + 'reply_block' => 'artbox_comment_reply_block',
  31 + 'reply_author' => 'artbox_comment_reply_author',
  32 + 'comment_update' => 'artbox_comment_update',
  33 + 'comment_update_submit' => 'artbox_comment_update_submit',
  34 + ];
  35 +
  36 + /**
11 37 * @var null|\yii\web\View
12 38 */
13 39 public $context = NULL;
... ... @@ -50,6 +76,7 @@
50 76 * @var bool Whether to allow one user post multiple comments
51 77 */
52 78 public $allow_multiple = true;
  79 + public $allow_reply = true;
53 80  
54 81 /**
55 82 * @var array Options sent to list part
... ... @@ -170,6 +197,11 @@
170 197 if($this->display_comment_form && $this->comment_class->checkCreate()) {
171 198 $tag = ArrayHelper::remove($this->form_options, 'tag', 'div');
172 199 $view = ArrayHelper::remove($this->form_options, 'view');
  200 + if(!empty($this->form_options['class'])) {
  201 + $this->form_options['class'] .= ' '.self::$baseClass['form_container'];
  202 + } else {
  203 + $this->form_options['class'] = self::$baseClass['form_container'];
  204 + }
173 205 $this->parts[ 'form' ] = Html::tag($tag, $this->renderForm($view), $this->form_options);
174 206 }
175 207 }
... ... @@ -178,6 +210,11 @@
178 210 {
179 211 $this->dataProvider = new \yii\data\ActiveDataProvider([
180 212 'query' => $this->comment_class->getComments($this->model, $this->model_id),
  213 + 'sort' => new Sort([
  214 + 'defaultOrder' => [
  215 + 'date_add' => SORT_DESC,
  216 + ],
  217 + ]),
181 218 'pagination' => [
182 219 'pageSize' => 10,
183 220 ],
... ... @@ -189,7 +226,10 @@
189 226 if(empty( $view )) {
190 227 throw new \yii\base\InvalidConfigException("list_options[view] must be set");
191 228 }
192   - return $this->render($view, [ 'dataProvider' => $this->dataProvider ]);
  229 + return $this->render($view, [
  230 + 'dataProvider' => $this->dataProvider,
  231 + 'commentClass' => $this->comment_class,
  232 + ]);
193 233 }
194 234  
195 235 public function renderForm($view)
... ... @@ -197,7 +237,7 @@
197 237 if(empty( $view )) {
198 238 throw new \yii\base\InvalidConfigException("form_options[view] must be set");
199 239 }
200   - if($this->comment_class->guestComment || !empty(\Yii::$app->user->identity)) {
  240 + if($this->comment_class->guestComment || !empty( \Yii::$app->user->identity )) {
201 241 return $this->render($view, [
202 242 'model' => $this->comment_class,
203 243 'rating' => $this->rating_class,
... ... @@ -218,6 +258,11 @@
218 258 $template = preg_replace('/{list}/', ArrayHelper::remove($parts, 'list', ''), $template);
219 259 $template = preg_replace('/{form}/', ArrayHelper::remove($parts, 'form', ''), $template);
220 260 $tag = ArrayHelper::remove($options, 'tag', 'div');
  261 + if(!empty($options['class'])) {
  262 + $options['class'] .= ' '.self::$baseClass['widget_container'];
  263 + } else {
  264 + $options['class'] = self::$baseClass['widget_container'];
  265 + }
221 266 return Html::tag($tag, $template, $options);
222 267 }
223 268  
... ... @@ -233,4 +278,5 @@
233 278 }
234 279 }
235 280 }
  281 +
236 282 }
237 283 \ No newline at end of file
... ...
common/modules/comment/widgets/views/_review_comment_view.php
1 1 <?php
2 2 use common\models\User;
  3 + use common\modules\comment\widgets\CommentWidget;
3 4 use yii\helpers\Html;
  5 + use yii\web\View;
4 6  
5 7 /**
  8 + * @var View $this
6 9 * @var \common\modules\comment\models\Comment $model Current comment model
7 10 * @var integer $key ID of current comment
8 11 * @var integer $index index of current element according
... ... @@ -13,7 +16,7 @@
13 16 $user = $model->user;
14 17 $model->buildButtons();
15 18 ?>
16   - <div class="comments-name"><?= $user->name ?></div>
  19 + <div class="comments-name <?= CommentWidget::$baseClass[ 'comment_author' ] ?>"><?= $user->name ?></div>
17 20 <?php
18 21 /* == STATUS PRO ==
19 22 ?>
... ... @@ -37,12 +40,27 @@
37 40 </div>
38 41 <div>
39 42 <?php
40   - if(!empty($model->buttons['delete'])) {
41   - echo Html::a('Удалить', $model->buttons['delete'], ['data-method' => 'post', 'data-confirm' => 'Really?']);
  43 + if(!empty( $model->buttons[ 'delete' ] )) {
  44 + echo Html::a('Удалить', $model->buttons[ 'delete' ], [ 'class' => CommentWidget::$baseClass[ 'comment_delete' ] ]);
  45 + }
  46 + if(!empty( $model->buttons[ 'update' ] )) {
  47 + echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => CommentWidget::$baseClass[ 'comment_update' ] ]);
  48 + }
  49 + if(!empty( $model->buttons[ 'reply' ] )) {
  50 + echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] ]);
42 51 }
43 52 ?>
44 53 </div>
45 54 <?php
  55 + if(!$model->isNewRecord) {
  56 + $this->registerJs("$('div.rating').rating(
  57 + {
  58 + fx : 'full', readOnly : 'true', url : 'rating.php'
  59 + }
  60 + );");
  61 + }
  62 +?>
  63 +<?php
46 64 /* == PROJECT INFO ==
47 65 ?>
48 66 <div class="comments-project-link">Проект: <a href="#">Ремонт спальни</a></div>
... ...
common/modules/comment/widgets/views/form-comment-review.php
1 1 <?php
2 2 /**
  3 + * @var View $this
3 4 * @var \common\modules\comment\models\Comment $model
4 5 * @var \common\models\User $user
5 6 * @var \yii\data\ActiveDataProvider $dataProvider
6 7 * @var null|\common\modules\comment\models\Rating $rating
7 8 */
  9 + use common\modules\comment\widgets\CommentWidget;
  10 + use yii\web\View;
8 11 use yii\widgets\ActiveForm;
9 12 use yii\helpers\Html;
10 13  
11 14 ?>
12   -<div class="workplace-title style">
13   - <p></p>Мнения о пользователе: <?= $dataProvider->totalCount ?></p></div>
  15 +<?php
  16 + if(!empty( $dataProvider )) {
  17 + ?>
  18 + <div class="workplace-title style">
  19 + <p>Мнения о пользователе: <?= $dataProvider->totalCount ?></p>
  20 + </div>
  21 + <?php
  22 + }
  23 +?>
14 24 <div class="new-portf-add-comm style">
15 25 <?php
16 26 $form = ActiveForm::begin();
17   - echo $form->field($rating, 'value')
  27 + if(!$model->isNewRecord) {
  28 + echo $form->field($model, 'comment_id')
  29 + ->hiddenInput()
  30 + ->label(false)
  31 + ->error(false);
  32 + }
  33 + echo $form->field(( !empty( $model->rating ) ? $model->rating : $rating ), 'value')
18 34 ->label(false)
19 35 ->radioList([
20 36 1 => 1,
... ... @@ -43,10 +59,11 @@
43 59 ])
44 60 ->textInput();
45 61 }
46   -
47   - ?>
48   - <div class="artbox_comment_reply_block"></div>
49   - <?php
  62 + if(!empty( $model->comment_pid )) {
  63 + echo Html::tag('div', Html::activeHiddenInput($model, 'comment_pid') . Html::tag('p', $model->parent->authorName, [ 'class' => 'artbox_comment_reply_author' ]), [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] ]);
  64 + } else {
  65 + echo Html::tag('div', '', [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] ]);
  66 + }
50 67 echo $form->field($model, 'text', [
51 68 'options' => [
52 69 'class' => 'input-blocks-comm area-comm',
... ... @@ -58,7 +75,13 @@
58 75 ->textarea();
59 76 ?>
60 77 <div class="input-blocks-comm-button style">
61   - <?= Html::submitButton('Добавить комментарий') ?>
  78 + <?php
  79 + if($model->isNewRecord) {
  80 + echo Html::submitButton('Добавить комментарий');
  81 + } else {
  82 + echo Html::submitButton('Обновить комментарий', [ 'class' => CommentWidget::$baseClass[ 'comment_update_submit' ] ]);
  83 + }
  84 + ?>
62 85 </div>
63 86 <?php
64 87 $form->end();
... ...
common/modules/comment/widgets/views/list-comment-review.php
1 1 <?php
2 2 /**
3 3 * @var \yii\data\DataProviderInterface $dataProvider
  4 + * @var Comment $commentClass
4 5 */
5   -echo \yii\widgets\ListView::widget([
6   - 'dataProvider' => $dataProvider,
7   - 'itemView' => '_review_comment_view',
8   - 'options' => [
9   - 'tag' => 'ul',
10   - 'class' => 'proektant-comments style'
11   - ],
12   - 'itemOptions' => [
13   - 'tag' => 'li',
14   - ],
15   - 'layout' => "{items}\n{pager}",
16   -]);
17 6 \ No newline at end of file
  7 + use common\modules\comment\models\Comment;
  8 + use common\modules\comment\widgets\CommentWidget;
  9 + echo \yii\widgets\ListView::widget([
  10 + 'dataProvider' => $dataProvider,
  11 + 'itemView' => '_review_comment_view',
  12 + 'options' => [
  13 + 'tag' => 'ul',
  14 + 'class' => 'proektant-comments style',
  15 + ],
  16 + 'itemOptions' => [
  17 + 'tag' => 'li',
  18 + 'class' => CommentWidget::$baseClass[ 'comment_container' ],
  19 + 'data' => [
  20 + 'form' => $commentClass->formName(),
  21 + ],
  22 + ],
  23 + 'layout' => "{items}\n{pager}",
  24 + ]);
18 25 \ No newline at end of file
... ...
frontend/controllers/SiteController.php
... ... @@ -279,15 +279,11 @@ class SiteController extends Controller
279 279  
280 280 $user_info->save();
281 281  
282   - if($user->type == 2 ){
  282 + $company_info = new CompanyInfo();
  283 + $company_info->load(Yii::$app->request->post(), 'SignupForm');
  284 + $company_info->user_id = $user->id;
283 285  
284   - $company_info = new CompanyInfo();
285   - $company_info->load(Yii::$app->request->post(),'SignupForm');
286   - $company_info->user_id = $user->id;
287   -
288   - $company_info->save();
289   -
290   - }
  286 + $company_info->save();
291 287  
292 288 if (Yii::$app->getUser()->login($user)) {
293 289  
... ...
server.js 0 → 100644
  1 +/**
  2 + * Created by Ярик on 08.04.2016.
  3 + */
... ...