Commit c05bf00561104c659a289b6273160ff75d82ab7c

Authored by Yarik
1 parent 93ca7a71

Comment added

Showing 72 changed files with 2276 additions and 3523 deletions   Show diff stats
backend/config/main.php
@@ -32,9 +32,10 @@ return [ @@ -32,9 +32,10 @@ return [
32 'targetMinPixel' => 200 // Target image minimum pixel size 32 'targetMinPixel' => 200 // Target image minimum pixel size
33 ] 33 ]
34 ], 34 ],
35 -// 'artbox-comment' => [  
36 -// 'class' => \common\modules\comment\Controller::className(),  
37 -// ], 35 + 'artbox-comments' => [
  36 + 'class' => 'common\modules\comment\controllers\ManageController',
  37 + 'viewPath' => '@common/modules/comment/views/manage',
  38 + ],
38 ], 39 ],
39 'layout' => 'admin', 40 'layout' => 'admin',
40 'controllerNamespace' => 'backend\controllers', 41 'controllerNamespace' => 'backend\controllers',
@@ -101,7 +102,11 @@ return [ @@ -101,7 +102,11 @@ return [
101 ], 102 ],
102 'gridview' => [ 103 'gridview' => [
103 'class' => '\kartik\grid\Module' 104 'class' => '\kartik\grid\Module'
104 - ] 105 + ],
  106 + 'artbox-comment' => [
  107 + 'class' => 'common\modules\comment\Module',
  108 + 'userIdentityClass' => 'common\models\Customer',
  109 + ],
105 ], 110 ],
106 'components' => [ 111 'components' => [
107 'authManager' => [ 112 'authManager' => [
backend/controllers/CommentController.php 100644 → 100755
backend/models/CommentSearch.php 100644 → 100755
backend/views/comment/_form.php 100644 → 100755
backend/views/comment/_search.php 100644 → 100755
backend/views/comment/index.php 100644 → 100755
backend/views/comment/update.php 100644 → 100755
backend/views/comment/view.php 100644 → 100755
common/config/main.php
@@ -3,9 +3,9 @@ return [ @@ -3,9 +3,9 @@ return [
3 'language' => 'ru', 3 'language' => 'ru',
4 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 4 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
5 'controllerMap' => [ 5 'controllerMap' => [
6 - 'artbox-comment' => [  
7 - 'class' => \common\modules\comment\Controller::className(),  
8 - ], 6 +// 'artbox-comment' => [
  7 +// 'class' => \common\modules\comment\Controller::className(),
  8 +// ],
9 ], 9 ],
10 'components' => [ 10 'components' => [
11 'assetManager' => [ 11 'assetManager' => [
@@ -42,7 +42,11 @@ return [ @@ -42,7 +42,11 @@ return [
42 'app/error' => 'error.php', 42 'app/error' => 'error.php',
43 ], 43 ],
44 ], 44 ],
45 - ], 45 + 'artbox-comment' => [
  46 + 'class' => 'yii\i18n\PhpMessageSource',
  47 + 'basePath' => '@common/modules/comment/messages',
  48 + ],
  49 + ],
46 ], 50 ],
47 'artboximage' => [ 51 'artboximage' => [
48 'class' => 'common\components\artboximage\ArtboxImage', 52 'class' => 'common\components\artboximage\ArtboxImage',
@@ -159,6 +163,9 @@ return [ @@ -159,6 +163,9 @@ return [
159 'file' => [ 163 'file' => [
160 'class' => 'common\modules\file\Module', 164 'class' => 'common\modules\file\Module',
161 ], 165 ],
  166 + 'artbox-comment' => [
  167 + 'class' => 'common\modules\comment\Module',
  168 + ],
162 'relation' => [ 169 'relation' => [
163 'class' => 'common\modules\relation\Module', 170 'class' => 'common\modules\relation\Module',
164 'relations' => [ 171 'relations' => [
common/models/ProductToRating.php 100644 → 100755
common/modules/comment/Controller.php deleted
1 -<?php  
2 - namespace common\modules\comment;  
3 -  
4 - class Controller extends \yii\web\Controller  
5 - {  
6 -  
7 - public $enableCsrfValidation = false;  
8 -  
9 - public function behaviors()  
10 - {  
11 - return [  
12 - 'verbs' => [  
13 - 'class' => \yii\filters\VerbFilter::className(),  
14 - 'actions' => [  
15 - '*' => [ 'post' ],  
16 - ],  
17 - ],  
18 - ];  
19 - }  
20 -  
21 - public function actionDelete()  
22 - {  
23 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
24 - $post = \Yii::$app->request->post('Comment');  
25 - $get = \Yii::$app->request->get();  
26 - if(empty( $post[ 'comment_id' ] ) && !empty( $get[ 'comment_id' ] )) {  
27 - $post[ 'comment_id' ] = $get[ 'comment_id' ];  
28 - }  
29 - if(!empty( $post[ 'comment_id' ] )) {  
30 - if($model = \common\modules\comment\models\Comment::findOne($post[ 'comment_id' ])) {  
31 - /**  
32 - * @var \common\modules\comment\models\Comment $model  
33 - */  
34 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;  
35 - if($model->deleteComment()) {  
36 - \Yii::$app->response->data = [ 'text' => 'Comment marked as deleted and will be check by administrators' ];  
37 - } else {  
38 - \Yii::$app->response->data = [ 'error' => $model->hasErrors('comment_id') ? $model->getFirstError('comment_id') : 'Cannot delete message' ];  
39 - }  
40 - } else {  
41 - \Yii::$app->response->data = [ 'error' => 'Comment not found' ];  
42 - };  
43 - } else {  
44 - \Yii::$app->response->data = [ 'error' => 'Missing comment_id' ];  
45 - }  
46 - \Yii::$app->response->send();  
47 - }  
48 -  
49 - public function actionUpdate()  
50 - {  
51 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
52 - $post = \Yii::$app->request->post();  
53 - if(!empty( $post[ 'Comment' ][ 'comment_id' ] )) {  
54 - if($model = \common\modules\comment\models\Comment::findOne($post[ 'Comment' ][ 'comment_id' ])) {  
55 - /**  
56 - * @var \common\modules\comment\models\Comment $model  
57 - */  
58 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;  
59 - $model->load($post);  
60 - if(empty( $post[ 'Comment' ][ 'comment_pid' ] )) {  
61 - $model->comment_pid = NULL;  
62 - }  
63 - if($model->updateComment()) {  
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 - }  
80 - } else {  
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 - ];  
87 - }  
88 - } else {  
89 - return [ 'error' => 'Comment not found' ];  
90 - }  
91 - } else {  
92 - return [ 'error' => 'Missing comment_id' ];  
93 - }  
94 - }  
95 -  
96 - public function actionForm()  
97 - {  
98 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
99 - $post = \Yii::$app->request->post('Comment');  
100 - if(!empty( $post[ 'comment_id' ] )) {  
101 - $model = \common\modules\comment\models\Comment::find()  
102 - ->where([ 'comment_id' => $post[ 'comment_id' ] ])  
103 - ->with('parent', 'user')  
104 - ->one();  
105 - if($model) {  
106 - /**  
107 - * @var \common\modules\comment\models\Comment $model  
108 - */  
109 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST;  
110 - if($model->checkUpdate()) {  
111 - return [  
112 - 'result' => [  
113 - 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-review', [  
114 - 'model' => $model,  
115 - ]),  
116 - ],  
117 - ];  
118 - } else {  
119 - return [ 'error' => 'You are not able to update this comment' ];  
120 - }  
121 - } else {  
122 - return [ 'error' => 'Comment not found' ];  
123 - }  
124 - } else {  
125 - return [ 'error' => 'Missing comment_id' ];  
126 - }  
127 - }  
128 -  
129 - public function actionUpdateAnswer()  
130 - {  
131 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
132 - $post = \Yii::$app->request->post();  
133 - if(!empty( $post[ 'CommentProjectAnswer' ][ 'comment_id' ] )) {  
134 - if($model = \common\modules\comment\models\CommentProjectAnswer::findOne($post[ 'CommentProjectAnswer' ][ 'comment_id' ])) {  
135 - /**  
136 - * @var \common\modules\comment\models\CommentProjectAnswer $model  
137 - */  
138 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\CommentProjectAnswer::SCENARIO_USER : \common\modules\comment\models\CommentProjectAnswer::SCENARIO_GUEST;  
139 - $model->load($post);  
140 - if(empty( $post[ 'CommentProjectAnswer' ][ 'comment_pid' ] )) {  
141 - $model->comment_pid = NULL;  
142 - }  
143 - if($model->updateComment()) {  
144 - $model->rating->load($post);  
145 - if($model->rating->save()) {  
146 - return [  
147 - 'result' => [  
148 - 'text' => 'Comment successfully updated',  
149 - 'html' => $this->renderAjax('@common/modules/comment/widgets/views/_question_comment_view', [ 'model' => $model ]),  
150 - ],  
151 - ];  
152 - } else {  
153 - return [  
154 - 'error' => $model->hasErrors() ? $model->getFirstErrors() : 'Cannot update message',  
155 - 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-answer', [  
156 - 'model' => $model,  
157 - ]),  
158 - ];  
159 - }  
160 - } else {  
161 - return [  
162 - 'error' => $model->hasErrors() ? $model->getFirstErrors() : 'Cannot update message',  
163 - 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-answer', [  
164 - 'model' => $model,  
165 - ]),  
166 - ];  
167 - }  
168 - } else {  
169 - return [ 'error' => 'Comment not found' ];  
170 - }  
171 - } else {  
172 - return [ 'error' => 'Missing comment_id' ];  
173 - }  
174 - }  
175 -  
176 - public function actionFormAnswer()  
177 - {  
178 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
179 - $post = \Yii::$app->request->post('CommentProjectAnswer');  
180 - if(!empty( $post[ 'comment_id' ] )) {  
181 - $model = \common\modules\comment\models\CommentProjectAnswer::find()  
182 - ->where([ 'comment_id' => $post[ 'comment_id' ] ])  
183 - ->with('parent', 'user')  
184 - ->one();  
185 - if($model) {  
186 - /**  
187 - * @var \common\modules\comment\models\CommentProjectAnswer $model  
188 - */  
189 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\CommentProjectAnswer::SCENARIO_USER : \common\modules\comment\models\CommentProjectAnswer::SCENARIO_GUEST;  
190 - if($model->checkUpdate()) {  
191 - return [  
192 - 'result' => [  
193 - 'form' => $this->renderAjax('@common/modules/comment/widgets/views/form-comment-answer', [  
194 - 'model' => $model,  
195 - ]),  
196 - ],  
197 - ];  
198 - } else {  
199 - return [ 'error' => 'You are not able to update this comment' ];  
200 - }  
201 - } else {  
202 - return [ 'error' => 'Comment not found' ];  
203 - }  
204 - } else {  
205 - return [ 'error' => 'Missing comment_id' ];  
206 - }  
207 - }  
208 -  
209 - public function actionDeleteAnswer()  
210 - {  
211 - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;  
212 - $post = \Yii::$app->request->post('CommentProjectAnswer');  
213 - $get = \Yii::$app->request->get();  
214 - if(empty( $post[ 'comment_id' ] ) && !empty( $get[ 'comment_id' ] )) {  
215 - $post[ 'comment_id' ] = $get[ 'comment_id' ];  
216 - }  
217 - if(!empty( $post[ 'comment_id' ] )) {  
218 - if($model = \common\modules\comment\models\CommentProjectAnswer::findOne($post[ 'comment_id' ])) {  
219 - /**  
220 - * @var \common\modules\comment\models\Comment $model  
221 - */  
222 - $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\CommentProjectAnswer::SCENARIO_USER : \common\modules\comment\models\CommentProjectAnswer::SCENARIO_GUEST;  
223 - if($model->deleteComment()) {  
224 - \Yii::$app->response->data = [ 'text' => 'Comment marked as deleted and will be check by administrators' ];  
225 - } else {  
226 - \Yii::$app->response->data = [ 'error' => $model->hasErrors('comment_id') ? $model->getFirstError('comment_id') : 'Cannot delete message' ];  
227 - }  
228 - } else {  
229 - \Yii::$app->response->data = [ 'error' => 'Comment not found' ];  
230 - };  
231 - } else {  
232 - \Yii::$app->response->data = [ 'error' => 'Missing comment_id' ];  
233 - }  
234 - \Yii::$app->response->send();  
235 - }  
236 -  
237 - }  
238 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/Module.php
1 <?php 1 <?php
  2 +
2 namespace common\modules\comment; 3 namespace common\modules\comment;
3 - 4 +
  5 + use common\modules\comment\models\CommentModel;
  6 + use common\modules\comment\models\RatingModel;
  7 + use Yii;
  8 +
4 /** 9 /**
5 * Class Module 10 * Class Module
6 * @package common\modules\comment 11 * @package common\modules\comment
7 */ 12 */
8 class Module extends \yii\base\Module 13 class Module extends \yii\base\Module
9 { 14 {
10 - 15 +
11 /** 16 /**
12 - * @var string Module name 17 + * @var string module name
13 */ 18 */
14 - public static $moduleName = 'artbox_comment';  
15 - 19 + public static $name = 'artbox-comment';
  20 +
16 /** 21 /**
17 - * @var bool Wheather to use Rbac system  
18 - * @link http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#rbac  
19 - * @see \yii\rbac\ManagerInterface 22 + * User identity class, default to common\models\User
  23 + * @var string|null
20 */ 24 */
21 - public $useRbac = false;  
22 - 25 + public $userIdentityClass = NULL;
  26 +
23 /** 27 /**
24 - * Array of RBAC rules and permissions that can be used by install command.  
25 - *  
26 - * Currently supports associative array, of such view:  
27 - *  
28 - * <code>  
29 - * [  
30 - * 'rules' => [  
31 - * \full\namapaced\ClassName,  
32 - * \another\one\ClassName,  
33 - * ],  
34 - * 'permissions' => [  
35 - * [  
36 - * 'name' => stringName,  
37 - * 'description' => descriptionText,  
38 - * 'ruleName' => (new \full\namespaced\ClassName())->name (optional)  
39 - * ],  
40 - * [  
41 - * 'name' => stringName2,  
42 - * 'description' => descriptionText2,  
43 - * 'ruleName' => (new \another\one\ClassName())->name (optional)  
44 - * ],  
45 - * ]  
46 - * ]  
47 - * </code> 28 + * Comment model class, default to common\modules\models\CommentModel
  29 + * @var string comment model class
  30 + */
  31 + public $commentModelClass = NULL;
  32 +
  33 + public $ratingModelClass = NULL;
  34 +
  35 + /**
  36 + * This namespace will be used to load controller classes by prepending it to the controller
  37 + * class name.
  38 + * @var string the namespace that controller classes are in.
  39 + */
  40 + public $controllerNamespace = 'common\modules\comment\controllers';
  41 +
  42 + /**
  43 + * @var \yii\db\Connection DB connection, default to \Yii::$app->db
  44 + */
  45 + public $db = NULL;
  46 +
  47 + /**
  48 + * Key, used to encrypt and decrypt comment service data.
48 * 49 *
49 - * @var array  
50 - * @see \common\modules\comment\commands\RbacController 50 + * @var string Encryption key
51 */ 51 */
52 - public $rbac = [];  
53 - 52 + public static $encryptionKey = 'artbox-comment';
  53 +
54 /** 54 /**
55 - * @var \yii\db\Connection Connection to the db 55 + * Whether to enable comment rating or not.
  56 + *
  57 + * @var bool
56 */ 58 */
57 - public $db = null;  
58 - 59 + public static $enableRating = true;
  60 +
59 /** 61 /**
60 - * @inheritdoc 62 + * Initializes the module.
  63 + * This method is called after the module is created and initialized with property values
  64 + * given in configuration. The default implementation will initialize
  65 + * [[controllerNamespace]] if it is not set. If you override this method, please make sure
  66 + * you call the parent implementation.
61 */ 67 */
62 public function init() 68 public function init()
63 { 69 {
64 - parent::init(); 70 + if($this->userIdentityClass === NULL) {
  71 + $this->userIdentityClass = Yii::$app->getUser()->identityClass;
  72 + }
  73 + if($this->commentModelClass === NULL) {
  74 + $this->commentModelClass = CommentModel::className();
  75 + }
  76 + if(self::$enableRating && $this->ratingModelClass === NULL) {
  77 + $this->ratingModelClass = RatingModel::className();
  78 + }
65 if(\Yii::$app instanceof \yii\console\Application) { 79 if(\Yii::$app instanceof \yii\console\Application) {
66 $this->controllerNamespace = 'common\modules\comment\commands'; 80 $this->controllerNamespace = 'common\modules\comment\commands';
67 } 81 }
68 - if($this->db === null) { 82 + if($this->db === NULL) {
69 $this->db = \Yii::$app->db; 83 $this->db = \Yii::$app->db;
70 - } elseif(!$this->db instanceof \yii\db\Connection) {  
71 - throw new \yii\base\InvalidConfigException('Конфиг db обязан наследоваться от'.\yii\db\Connection::className());  
72 } 84 }
  85 + Yii::setAlias('@artbox-comment', __DIR__);
  86 + parent::init();
73 } 87 }
74 - }  
75 \ No newline at end of file 88 \ No newline at end of file
  89 +
  90 + }
common/modules/comment/Permissions.php deleted
1 -<?php  
2 - namespace common\modules\comment;  
3 -  
4 - class Permissions  
5 - {  
6 -  
7 - const CREATE = 'artbox_comment.create';  
8 - const UPDATE = 'artbox_comment.update';  
9 - const DELETE = 'artbox_comment.delete';  
10 - const UPDATE_OWN = 'artbox_comment.update_own';  
11 - const DELETE_OWN = 'artbox_comment.delete_own';  
12 - }  
13 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/assets/CommentAsset.php
1 <?php 1 <?php
2 - namespace common\modules\comment\assets;  
3 -  
4 - class CommentAsset extends \yii\web\AssetBundle  
5 - {  
6 -  
7 - public $sourcePath = '@common/modules/comment/resources';  
8 -  
9 - public $css = [  
10 - 'comment.css',  
11 - 'rateit.css',  
12 - ];  
13 -  
14 - public $js = [  
15 - 'comment.js',  
16 - 'jquery.rateit.min.js',  
17 - ];  
18 -  
19 - public $depends = [  
20 - '\yii\web\YiiAsset',  
21 - '\yii\web\JqueryAsset',  
22 - ];  
23 -  
24 - public $jsOptions = [  
25 - 'position' => \yii\web\View::POS_HEAD,  
26 - ];  
27 -  
28 - }  
29 \ No newline at end of file 2 \ No newline at end of file
  3 +
  4 +namespace common\modules\comment\assets;
  5 +
  6 +use yii\web\AssetBundle;
  7 +
  8 +/**
  9 + * Class CommentAsset
  10 + * @package common\modules\comment\assets
  11 + */
  12 +class CommentAsset extends AssetBundle
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public $sourcePath = '@artbox-comment/resources';
  18 +
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public $js = [
  23 + 'artbox_comment.js',
  24 + 'jquery.rateit.min.js',
  25 + ];
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public $css = [
  31 + 'artbox_comment.css',
  32 + 'rateit.css',
  33 + ];
  34 +
  35 + /**
  36 + * @inheritdoc
  37 + */
  38 + public $depends = [
  39 + 'yii\web\JqueryAsset',
  40 + 'yii\web\YiiAsset'
  41 + ];
  42 +}
30 \ No newline at end of file 43 \ No newline at end of file
common/modules/comment/behaviors/ParentBehavior.php 0 → 100644
  1 +<?php
  2 + namespace common\modules\comment\behaviors;
  3 +
  4 + use common\modules\comment\models\CommentModel;
  5 + use yii\base\Behavior;
  6 + use yii\base\Event;
  7 + use yii\db\ActiveRecord;
  8 +
  9 + class ParentBehavior extends Behavior
  10 + {
  11 + public function events()
  12 + {
  13 + return [
  14 + ActiveRecord::EVENT_AFTER_VALIDATE => 'afterValidate',
  15 + ];
  16 + }
  17 +
  18 + /**
  19 + * @param Event $event
  20 + */
  21 + public function afterValidate($event) {
  22 + /**
  23 + * @var CommentModel $owner
  24 + */
  25 + $owner = $this->owner;
  26 + if(!empty($owner->artbox_comment_pid)) {
  27 + /**
  28 + * @var CommentModel $parent
  29 + */
  30 + $parent = CommentModel::find()->where(['artbox_comment_id' => $owner->artbox_comment_pid])->one();
  31 + if(!empty($parent->artbox_comment_pid)) {
  32 + $owner->related_id = $owner->artbox_comment_pid;
  33 + $owner->artbox_comment_pid = $parent->artbox_comment_pid;
  34 + }
  35 + }
  36 + }
  37 + }
0 \ No newline at end of file 38 \ No newline at end of file
common/modules/comment/commands/RbacController.php deleted
1 -<?php  
2 - namespace common\modules\comment\commands;  
3 -  
4 - class RbacController extends \yii\console\Controller  
5 - {  
6 -  
7 - public function actionInstall()  
8 - {  
9 - /**  
10 - * @var \common\modules\comment\Module $module  
11 - */  
12 - $module = \Yii::$app->controller->module;  
13 - if(!$module->useRbac) {  
14 - throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs');  
15 - }  
16 - $auth = \Yii::$app->getAuthManager();  
17 - if(!$auth instanceof \yii\rbac\ManagerInterface) {  
18 - throw new \yii\base\InvalidConfigException('ManagerInterface is not configured');  
19 - }  
20 - if(!empty($module->rbac['rules'])) {  
21 - foreach($module->rbac['rules'] as $rule) {  
22 - $rule_model = new $rule();  
23 - echo "Creating rule: ".$rule_model->name."\n";  
24 - if($auth->add($rule_model)) {  
25 - echo "Successful\n";  
26 - } else {  
27 - echo "Failed\n";  
28 - }  
29 - unset($rule_model);  
30 - }  
31 - }  
32 - if(!empty($module->rbac['permissions'])) {  
33 - foreach($module->rbac['permissions'] as $permission) {  
34 - echo "Creating permission: ".$permission['name']."\n";  
35 - if($auth->add(new \yii\rbac\Permission($permission))) {  
36 - echo "Successful\n";  
37 - } else {  
38 - echo "Failed\n";  
39 - }  
40 - }  
41 - }  
42 - }  
43 -  
44 - public function actionUninstall()  
45 - {  
46 - /**  
47 - * @var \common\modules\comment\Module $module  
48 - */  
49 - $module = \Yii::$app->controller->module;  
50 - if(!$module->useRbac) {  
51 - throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs');  
52 - }  
53 - $auth = \Yii::$app->getAuthManager();  
54 - if(!$auth instanceof \yii\rbac\ManagerInterface) {  
55 - throw new \yii\base\InvalidConfigException('ManagerInterface is not configured');  
56 - }  
57 - if(!empty($module->rbac['rules'])) {  
58 - foreach($module->rbac['rules'] as $rule) {  
59 - $rule_model = new $rule();  
60 - echo "Removing rule: ".$rule_model->name."\n";  
61 - if($auth->remove($rule_model)) {  
62 - echo "Successful\n";  
63 - } else {  
64 - echo "Failed\n";  
65 - }  
66 - unset($rule_model);  
67 - }  
68 - }  
69 - if(!empty($module->rbac['permissions'])) {  
70 - foreach($module->rbac['permissions'] as $permission) {  
71 - echo "Removing permission: ".$permission['name']."\n";  
72 - if($auth->remove(new \yii\rbac\Permission($permission))) {  
73 - echo "Successful\n";  
74 - } else {  
75 - echo "Failed\n";  
76 - }  
77 - }  
78 - }  
79 - }  
80 -  
81 - }  
82 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/controllers/DefaultController.php 0 → 100644
  1 +<?php
  2 + namespace common\modules\comment\controllers;
  3 +
  4 + use common\modules\comment\models\CommentModel;
  5 + use common\modules\comment\models\RatingModel;
  6 + use common\modules\comment\Module;
  7 + use yii\filters\AccessControl;
  8 + use yii\filters\VerbFilter;
  9 + use yii\helpers\Json;
  10 + use yii\web\Controller;
  11 + use yii\web\NotFoundHttpException;
  12 + use yii\web\Response;
  13 +
  14 + class DefaultController extends Controller
  15 + {
  16 +
  17 + /**
  18 + * Returns a list of behaviors that this component should behave as.
  19 + * @return array
  20 + */
  21 + public function behaviors()
  22 + {
  23 + return [
  24 + 'verbs' => [
  25 + 'class' => VerbFilter::className(),
  26 + 'actions' => [
  27 + 'create' => [ 'post' ],
  28 + 'delete' => [
  29 + 'post',
  30 + 'delete',
  31 + ],
  32 + ],
  33 + ],
  34 + 'access' => [
  35 + 'class' => AccessControl::className(),
  36 + 'only' => [ 'delete' ],
  37 + 'rules' => [
  38 + [
  39 + 'allow' => true,
  40 + 'roles' => [ '@' ],
  41 + ],
  42 + ],
  43 + ],
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * Create comment.
  49 + * @return array|null|Response
  50 + */
  51 + public function actionCreate(string $entity)
  52 + {
  53 + \Yii::$app->response->format = Response::FORMAT_JSON;
  54 + /* @var $module Module */
  55 + $module = \Yii::$app->getModule(Module::$name);
  56 + $entity_data_json = \Yii::$app->getSecurity()
  57 + ->decryptByKey($entity, $module::$encryptionKey);
  58 + if($entity_data_json != false) {
  59 + $entity_data = Json::decode($entity_data_json);
  60 + $commentModelClass = $module->commentModelClass;
  61 + /**
  62 + * @var CommentModel $model
  63 + */
  64 + $model = new $commentModelClass;
  65 + if($model->load(\Yii::$app->request->post())) {
  66 + $model->setAttributes($entity_data);
  67 + if($model->save()) {
  68 + if(empty($model->artbox_comment_pid) && $module::$enableRating) {
  69 + $ratingModelClass = $module->ratingModelClass;
  70 + /**
  71 + * @var RatingModel $rating
  72 + */
  73 + $rating = new $ratingModelClass([
  74 + 'model' => $model::className(),
  75 + 'model_id' => $model->primaryKey,
  76 + ]);
  77 + if($rating->load(\Yii::$app->request->post())) {
  78 + $rating->save();
  79 + }
  80 + }
  81 + \Yii::$app->session->setFlash('artbox_comment_success', \Yii::t('artbox-comment', 'Comment posted'));
  82 + return [ 'status' => 'success' ];
  83 + } else {
  84 + return [
  85 + 'status' => 'error',
  86 + 'errors' => $model->getFirstErrors(),
  87 + ];
  88 + }
  89 + }
  90 + }
  91 + return [
  92 + '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 + ];
  96 + }
  97 +
  98 + /**
  99 + * Delete comment.
  100 + *
  101 + * @param integer $id Comment ID
  102 + *
  103 + * @return string Comment text
  104 + */
  105 + public function actionDelete($id)
  106 + {
  107 + \Yii::$app->response->format = Response::FORMAT_JSON;
  108 + $model = $this->findModel($id);
  109 + if($model->deleteComment()) {
  110 + return [ 'status' => 'success',
  111 + 'message' => /*\Yii::t('yii2mod.comments', 'Comment has been deleted.');*/
  112 + "Comment has been deleted.",
  113 + ];
  114 + } else {
  115 + \Yii::$app->response->setStatusCode(500);
  116 + return \Yii::t('yii2mod.comments', 'Comment has not been deleted. Please try again!');
  117 + }
  118 + }
  119 +
  120 + /**
  121 + * Find model by ID.
  122 + *
  123 + * @param integer|array $id Comment ID
  124 + *
  125 + * @return CommentModel
  126 + * @throws NotFoundHttpException
  127 + */
  128 + protected function findModel(int $id): CommentModel
  129 + {
  130 + /** @var CommentModel $model */
  131 + $commentModelClass = \Yii::$app->getModule(Module::$name)->commentModelClass;
  132 + if(( $model = $commentModelClass::findOne($id) ) !== NULL) {
  133 + return $model;
  134 + } else {
  135 + throw new NotFoundHttpException(/*\Yii::t('yii2mod.comments', 'The requested page does not exist.')*/
  136 + "Comment not found.");
  137 + }
  138 + }
  139 + }
0 \ No newline at end of file 140 \ No newline at end of file
common/modules/comment/controllers/ManageController.php 0 → 100755
  1 +<?php
  2 +
  3 +namespace common\modules\comment\controllers;
  4 +
  5 +use common\modules\comment\models\CommentModel;
  6 +use common\modules\comment\models\CommentModelSearch;
  7 +use common\modules\comment\Module;
  8 +use Yii;
  9 +use yii\filters\VerbFilter;
  10 +use yii\web\Controller;
  11 +use yii\web\NotFoundHttpException;
  12 +
  13 +class ManageController extends Controller
  14 +{
  15 + /**
  16 + * Returns a list of behaviors that this component should behave as.
  17 + *
  18 + * @return array
  19 + */
  20 + public function behaviors()
  21 + {
  22 + return [
  23 + 'verbs' => [
  24 + 'class' => VerbFilter::className(),
  25 + 'actions' => [
  26 + 'index' => ['get'],
  27 + 'update' => ['get', 'post'],
  28 + 'delete' => ['post'],
  29 + ],
  30 + ],
  31 + ];
  32 + }
  33 +
  34 + /**
  35 + * Lists all comments.
  36 + *
  37 + * @return mixed
  38 + */
  39 + public function actionIndex()
  40 + {
  41 + $searchModel = new CommentModelSearch();
  42 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  43 + $commentModel = Yii::$app->getModule(Module::$name)->commentModelClass;
  44 +
  45 + return $this->render('index', [
  46 + 'dataProvider' => $dataProvider,
  47 + 'searchModel' => $searchModel,
  48 + 'commentModel' => $commentModel
  49 + ]);
  50 + }
  51 +
  52 + /**
  53 + * Updates an existing CommentModel model.
  54 + *
  55 + * If update is successful, the browser will be redirected to the 'view' page.
  56 + *
  57 + * @param integer $id
  58 + * @return mixed
  59 + */
  60 + public function actionUpdate($id)
  61 + {
  62 + $model = $this->findModel($id);
  63 +
  64 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  65 + Yii::$app->session->setFlash('artbox_comment_success', /*Yii::t('yii2mod.comments', 'Comment has been saved.')*/'Comment has been saved.');
  66 + return $this->redirect(['index']);
  67 + }
  68 +
  69 + return $this->render('update', [
  70 + 'model' => $model,
  71 + ]);
  72 +
  73 + }
  74 +
  75 + /**
  76 + * Deletes an existing CommentModel model.
  77 + *
  78 + * If deletion is successful, the browser will be redirected to the 'index' page.
  79 + *
  80 + * @param integer $id
  81 + * @return mixed
  82 + */
  83 + public function actionDelete($id)
  84 + {
  85 + $this->findModel($id)->delete();
  86 + Yii::$app->session->setFlash('artbox_comment_success', Yii::t('artbox-comment', 'Comment has been deleted.'));
  87 + return $this->redirect(['index']);
  88 + }
  89 +
  90 + /**
  91 + * Finds the CommentModel model based on its primary key value.
  92 + *
  93 + * If the model is not found, a 404 HTTP exception will be thrown.
  94 + *
  95 + * @param integer $id
  96 + * @return CommentModel the loaded model
  97 + *
  98 + * @throws NotFoundHttpException if the model cannot be found
  99 + */
  100 + protected function findModel($id)
  101 + {
  102 + if (($model = CommentModel::findOne($id)) !== null) {
  103 + return $model;
  104 + } else {
  105 + throw new NotFoundHttpException(/*Yii::t('yii2mod.comments', 'The requested page does not exist.')*/'The requested page does not exist.');
  106 + }
  107 + }
  108 +}
0 \ No newline at end of file 109 \ No newline at end of file
common/modules/comment/interfaces/CommentInterface.php deleted
1 -<?php  
2 - namespace common\modules\comment\interfaces;  
3 -  
4 - interface CommentInterface {  
5 - public function load($data, $formName = null);  
6 - public function formName();  
7 - public static function getComments($model, $model_id);  
8 - public function postComment();  
9 - public function deleteComment();  
10 - public function updateComment();  
11 - }  
common/modules/comment/messages/config.php 0 → 100755
  1 +<?php
  2 +
  3 +return [
  4 + // string, required, root directory of all source files
  5 + 'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..',
  6 + // array, required, list of language codes that the extracted messages
  7 + // should be translated to. For example, ['zh-CN', 'de'].
  8 + 'languages' => ['en', 'ru'],
  9 + // string, the name of the function for translating messages.
  10 + // Defaults to 'Yii::t'. This is used as a mark to find the messages to be
  11 + // translated. You may use a string for single function name or an array for
  12 + // multiple function names.
  13 + 'translator' => 'Yii::t',
  14 + // boolean, whether to sort messages by keys when merging new messages
  15 + // with the existing ones. Defaults to false, which means the new (untranslated)
  16 + // messages will be separated from the old (translated) ones.
  17 + 'sort' => true,
  18 + // boolean, whether to remove messages that no longer appear in the source code.
  19 + // Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
  20 + 'removeUnused' => false,
  21 + // array, list of patterns that specify which files (not directories) should be processed.
  22 + // If empty or not set, all files will be processed.
  23 + // Please refer to "except" for details about the patterns.
  24 + 'only' => ['*.php'],
  25 + // array, list of patterns that specify which files/directories should NOT be processed.
  26 + // If empty or not set, all files/directories will be processed.
  27 + // A path matches a pattern if it contains the pattern string at its end. For example,
  28 + // '/a/b' will match all files and directories ending with '/a/b';
  29 + // the '*.svn' will match all files and directories whose name ends with '.svn'.
  30 + // and the '.svn' will match all files and directories named exactly '.svn'.
  31 + // Note, the '/' characters in a pattern matches both '/' and '\'.
  32 + // See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
  33 + // If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
  34 + 'except' => [
  35 + '.svn',
  36 + '.git',
  37 + '.gitignore',
  38 + '.gitkeep',
  39 + '.hgignore',
  40 + '.hgkeep',
  41 + '/messages',
  42 + '/tests',
  43 + '/runtime',
  44 + '/vendor',
  45 + ],
  46 +
  47 + // 'php' output format is for saving messages to php files.
  48 + 'format' => 'php',
  49 + // Root directory containing message translations.
  50 + 'messagePath' => __DIR__,
  51 + // boolean, whether the message file should be overwritten with the merged messages
  52 + 'overwrite' => true,
  53 +
  54 + // Message categories to ignore
  55 + 'ignoreCategories' => [
  56 + 'yii',
  57 + ],
  58 +];
common/modules/comment/messages/en/artbox-comment.php 0 → 100755
  1 +<?php
  2 +/**
  3 + * Message translations.
  4 + *
  5 + * This file is automatically generated by 'yii message' command.
  6 + * It contains the localizable messages extracted from source code.
  7 + * You may modify this file by translating the extracted messages.
  8 + *
  9 + * Each array element represents the translation (value) of a message (key).
  10 + * If the value is empty, the message is considered as not translated.
  11 + * Messages that no longer need translation will have their translations
  12 + * enclosed between a pair of '@@' marks.
  13 + *
  14 + * Message string can be used with plural forms format. Check i18n section
  15 + * of the guide for details.
  16 + *
  17 + * NOTE: this file must be saved in UTF-8 encoding.
  18 + */
  19 +return [
  20 + 'ID' => 'ID',
  21 + 'Text' => 'Content',
  22 + 'Entity' => 'Entity',
  23 + 'Entity ID' => 'Entity ID',
  24 + 'Parent ID' => 'Parent ID',
  25 + 'Status' => 'Status',
  26 + 'Level' => 'Level',
  27 + 'User' => 'User',
  28 + 'Username' => 'User name',
  29 + 'Date add' => 'Date add',
  30 + 'Date update' => 'Date update',
  31 + 'Date delete' => 'Date delete',
  32 + 'Comment parent' => 'Parent comment',
  33 + 'Comment related' => 'Related comment',
  34 + 'Info' => 'Additional info',
  35 + 'Created by' => 'Created by',
  36 + 'Updated by' => 'Related to',
  37 + 'Related to' => 'Related to',
  38 + 'Created date' => 'Created date',
  39 + 'Updated date' => 'Updated date',
  40 + 'Update' => 'Update',
  41 + 'Delete' => 'Delete',
  42 + 'Reply' => 'Reply',
  43 + 'Comments ({0})' => 'Comments ({0})',
  44 + 'Comment cannot be blank.' => 'Comment cannot be blank.',
  45 + 'Comment has not been deleted. Please try again!' => 'Comment has not been deleted. Please try again!',
  46 + 'Add a comment...' => 'Add a comment...',
  47 + 'Comment' => 'Comment',
  48 + 'Oops, something went wrong. Please try again later.' => 'Oops, something went wrong. Please try again later.',
  49 + 'The requested page does not exist.' => 'The requested page does not exist.',
  50 + 'Comment has been deleted.' => 'Comment has been deleted.',
  51 + 'Comment has been saved.' => 'Comment has been saved.',
  52 + 'Click here to cancel reply.' => 'Click here to cancel reply.',
  53 + 'Comments Management' => 'Comments Management',
  54 + 'Select Status' => 'Select Status',
  55 + 'Select Author' => 'Select Author',
  56 + 'Update Comment: {0}' => 'Update Comment: {0}',
  57 + 'Active' => 'Active',
  58 + 'Deleted' => 'Deleted',
  59 + 'Comment posted' => 'Comment successfully added and will appear after moderator check.',
  60 +];
common/modules/comment/messages/ru/artbox-comment.php 0 → 100755
  1 +<?php
  2 + /**
  3 + * Message translations.
  4 + * This file is automatically generated by 'yii message' command.
  5 + * It contains the localizable messages extracted from source code.
  6 + * You may modify this file by translating the extracted messages.
  7 + * Each array element represents the translation (value) of a message (key).
  8 + * If the value is empty, the message is considered as not translated.
  9 + * Messages that no longer need translation will have their translations
  10 + * enclosed between a pair of '@@' marks.
  11 + * Message string can be used with plural forms format. Check i18n section
  12 + * of the guide for details.
  13 + * NOTE: this file must be saved in UTF-8 encoding.
  14 + */
  15 + return [
  16 + 'ID' => 'Идентификатор',
  17 + 'Text' => 'Комментарий',
  18 + 'Entity' => 'Модель',
  19 + 'Entity ID' => 'Идентификатор модели',
  20 + 'Parent ID' => 'Родитель',
  21 + 'Status' => 'Статус',
  22 + 'Level' => 'Уровень',
  23 + 'User' => 'Пользователь',
  24 + 'Username' => 'Имя',
  25 + 'Date add' => 'Дата добавления',
  26 + 'Date update' => 'Дата обновления',
  27 + 'Date delete' => 'Дата удаления',
  28 + 'Comment parent' => 'Родитель',
  29 + 'Comment related' => 'Связзанный комментарий',
  30 + 'Info' => 'Дополнительная информация',
  31 + 'Created by' => 'Создан',
  32 + 'Updated by' => 'Обновлен',
  33 + 'Related to' => 'Относится к',
  34 + 'Created date' => 'Дата создания',
  35 + 'Updated date' => 'Дата обновления',
  36 + 'Update' => 'Обновить',
  37 + 'Delete' => 'Удалить',
  38 + 'Reply' => 'Ответить',
  39 + 'Comments ({0})' => 'Комментарии ({0})',
  40 + 'Comment cannot be blank.' => 'Комментарий не может быть пустым.',
  41 + 'Comment has not been deleted. Please try again!' => 'Не удалось удалить комментарий. Попробуйте пожалуйста еще раз!',
  42 + 'Add a comment...' => 'Добавить комментарий...',
  43 + 'Comment' => 'Опубликовать комментарий',
  44 + 'Oops, something went wrong. Please try again later.' => 'Не удалось добавить комментарий. Попробуйте пожалуйста еще раз.',
  45 + 'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!',
  46 + 'Comment has been deleted.' => 'Комментарий был удалён.',
  47 + 'Comment has been saved.' => 'Комментарий был сохранён.',
  48 + 'Click here to cancel reply.' => 'Нажмите здесь, чтобы отменить ответ.',
  49 + 'Comments Management' => 'Управление Комментариями',
  50 + 'Select Status' => 'Выберите Статус',
  51 + 'Select Author' => 'Выберите Автора',
  52 + 'Update Comment: {0}' => 'Обновить комментарий: {0}',
  53 + 'Active' => 'Включён',
  54 + 'Deleted' => 'Удален',
  55 + 'Comment posted' => 'Комментарий успешно добавлен и появится после проверки администрацией.',
  56 + ];
common/modules/comment/migrations/m160724_162347_artbox_comment.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m160724_162347_artbox_comment extends Migration
  6 +{
  7 + public function up()
  8 + {
  9 + $this->createTable('{{%artbox_comment}}', [
  10 + 'artbox_comment_id' => $this->primaryKey(),
  11 + 'text' => $this->text()->notNull(),
  12 + 'user_id' => $this->integer(),
  13 + 'username' => $this->string(),
  14 + 'email' => $this->string(),
  15 + 'date_add' => $this->integer()->notNull(),
  16 + 'date_update' => $this->integer()->notNull(),
  17 + 'date_delete' => $this->integer(),
  18 + 'status' => $this->integer()->notNull()->defaultValue(1),
  19 + 'artbox_comment_pid' => $this->integer(),
  20 + 'related_id' => $this->integer(),
  21 + 'ip' => $this->string()->notNull(),
  22 + 'info' => $this->text(),
  23 + ]);
  24 +
  25 + $this->addForeignKey('user_id_user', '{{%artbox_comment}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
  26 + $this->addForeignKey('artbox_comment_pid_artbox_comment', '{{%artbox_comment}}', 'artbox_comment_pid', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
  27 + $this->addForeignKey('related_id_artbox_comment', '{{%artbox_comment}}', 'related_id', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
  28 +
  29 + $this->createTable('{{%artbox_like}}', [
  30 + 'artbox_like_id' => $this->primaryKey(),
  31 + 'artbox_comment_id' => $this->integer()->notNull(),
  32 + 'user_id' => $this->integer(),
  33 + 'date_add' => $this->integer()->notNull(),
  34 + 'is_like' => $this->integer()->notNull()->defaultValue(1),
  35 + ]);
  36 +
  37 + $this->addForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}', 'artbox_comment_id', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
  38 + $this->addForeignKey('user_id_user', '{{%artbox_like}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
  39 + $this->createIndex('artbox_like_unique', '{{%artbox_like}}', ['artbox_comment_id', 'user_id', 'is_like'], true);
  40 +
  41 + }
  42 +
  43 + public function down()
  44 + {
  45 + $this->dropForeignKey('user_id_user', '{{%artbox_comment}}');
  46 + $this->dropForeignKey('artbox_comment_pid_artbox_comment', '{{%artbox_comment}}');
  47 + $this->dropForeignKey('related_id_artbox_comment', '{{%artbox_comment}}');
  48 + $this->dropForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}');
  49 + $this->dropForeignKey('user_id_user', '{{%artbox_like}}');
  50 + $this->dropIndex('artbox_like_unique', '{{%artbox_like}}');
  51 + $this->dropTable('{{%artbox_comment}}');
  52 + $this->dropTable('{{%artbox_like}}');
  53 + }
  54 +}
common/modules/comment/migrations/m160726_092634_add_entity_fields.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m160726_092634_add_entity_fields extends Migration
  6 +{
  7 + public function up()
  8 + {
  9 + $this->addColumn('{{%artbox_comment}}', 'entity', $this->string()->notNull()->defaultValue(''));
  10 + $this->addColumn('{{%artbox_comment}}', 'entity_id', $this->integer()->notNull()->defaultValue(1));
  11 + }
  12 +
  13 + public function down()
  14 + {
  15 + $this->dropColumn('{{%artbox_comment}}', 'entity');
  16 + $this->dropColumn('{{%artbox_comment}}', 'entity_id');
  17 + }
  18 +}
common/modules/comment/migrations/m160726_211227_create_artbox_comment_rating.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m160726_211227_create_artbox_comment_rating extends Migration
  6 + {
  7 +
  8 + public function up()
  9 + {
  10 + $this->createTable('{{%artbox_comment_rating}}', [
  11 + 'artbox_comment_rating_id' => $this->primaryKey(),
  12 + 'date_add' => $this->integer()
  13 + ->notNull(),
  14 + 'date_update' => $this->integer()
  15 + ->notNull(),
  16 + 'user_id' => $this->integer(),
  17 + 'value' => $this->float(),
  18 + 'model' => $this->string()
  19 + ->notNull(),
  20 + 'model_id' => $this->integer()
  21 + ->notNull(),
  22 + ]);
  23 + $this->addForeignKey('user_id_user', '{{%artbox_comment_rating}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
  24 + }
  25 +
  26 + public function down()
  27 + {
  28 + $this->dropForeignKey('user_id_user', '{{%artbox_comment_rating}}');
  29 + $this->dropTable('{{%artbox_comment_rating}}');
  30 + }
  31 + }
common/modules/comment/models/Comment.php deleted
1 -<?php  
2 - namespace common\modules\comment\models;  
3 -  
4 - use common\models\User;  
5 - use common\modules\product\models\Product;  
6 - use yii\db\ActiveQuery;  
7 - use yii\helpers\Url;  
8 -  
9 - /**  
10 - * Class Comment  
11 - * @property bool $guestComment  
12 - * @property integer $comment_id  
13 - * @property string $text  
14 - * @property int $user_id  
15 - * @property string $user_name  
16 - * @property string $user_email  
17 - * @property int $comment_pid  
18 - * @property int $status  
19 - * @property string $date_add  
20 - * @property string $date_update  
21 - * @property string $date_delete  
22 - * @property string $model  
23 - * @property int $model_id  
24 - * @property Rating $rating  
25 - * @property User $user  
26 - * @property User $author  
27 - * @package common\modules\comment\models  
28 - */  
29 - class Comment extends \yii\db\ActiveRecord  
30 - implements \common\modules\comment\interfaces\CommentInterface  
31 - {  
32 -  
33 - const STATUS_HIDDEN = 0;  
34 - const STATUS_DELETED = 2;  
35 - const STATUS_ACTIVE = 1;  
36 - const STATUS_PERSONAL = 3;  
37 -  
38 - const SCENARIO_USER = 'user';  
39 - const SCENARIO_GUEST = 'guest';  
40 -  
41 - /**  
42 - * @var bool  
43 - */  
44 - public $guestComment = true;  
45 -  
46 - public $buttons = [ ];  
47 -  
48 - public function rules()  
49 - {  
50 - return [  
51 - [  
52 - [  
53 - 'text',  
54 - 'user_name',  
55 - 'user_email',  
56 - ],  
57 - 'required',  
58 - ],  
59 - [  
60 - [  
61 - 'rating',  
62 - ],  
63 - 'safe',  
64 - ],  
65 - [  
66 - [ 'user_email' ],  
67 - 'email',  
68 - ],  
69 - [  
70 - [ 'user_name' ],  
71 - 'string',  
72 - ],  
73 - [  
74 - [  
75 - 'comment_id',  
76 - 'comment_pid',  
77 - ],  
78 - 'integer',  
79 - ],  
80 - [  
81 - [ 'status' ],  
82 - 'default',  
83 - 'value' => 1,  
84 - ],  
85 - [  
86 - [ 'comment_pid' ],  
87 - 'exist',  
88 - 'targetAttribute' => 'comment_id',  
89 - 'filter' => [  
90 - 'model' => $this->model,  
91 - 'model_id' => $this->model_id,  
92 - ],  
93 - ],  
94 - ];  
95 - }  
96 -  
97 - public function scenarios()  
98 - {  
99 - return [  
100 - self::SCENARIO_GUEST => [  
101 - 'user_name',  
102 - 'user_email',  
103 - 'text',  
104 - 'comment_pid',  
105 - ],  
106 - self::SCENARIO_USER => [  
107 - 'text',  
108 - 'comment_pid',  
109 - ],  
110 - ];  
111 - }  
112 -  
113 - /**  
114 - * @inheritdoc  
115 - */  
116 - public function behaviors()  
117 - {  
118 - return [  
119 - [  
120 - 'class' => \yii\behaviors\TimestampBehavior::className(),  
121 - 'createdAtAttribute' => 'date_add',  
122 - 'updatedAtAttribute' => 'date_update',  
123 - 'value' => new \yii\db\Expression('NOW()'),  
124 - ],  
125 - ];  
126 - }  
127 -  
128 - public function afterSave($insert, $changedAttributes)  
129 - {  
130 - if($this->model == User::className()) {  
131 - if($user = User::findOne($this->model_id)) {  
132 - /**  
133 - * @var User $user  
134 - */  
135 - $user->updateRating();  
136 - }  
137 - }  
138 - if($this->model == Product::className()) {  
139 - if($product = Product::findOne($this->model_id)) {  
140 - $product->recalculateRating();  
141 - }  
142 - }  
143 - parent::afterSave($insert, $changedAttributes);  
144 - }  
145 -  
146 - /**  
147 - * @inheritdoc  
148 - */  
149 - public static function tableName()  
150 - {  
151 - return '{{%comment}}';  
152 - }  
153 -  
154 - /**  
155 - * @inheritdoc  
156 - */  
157 - public function attributeLabels()  
158 - {  
159 - return [  
160 - 'text' => \Yii::t('app', 'Комментарий'),  
161 - 'user_name' => \Yii::t('app', 'Имя'),  
162 - 'user_email' => \Yii::t('app', 'Email'),  
163 - ];  
164 - }  
165 -  
166 - public function getGuestComment()  
167 - {  
168 - return $this->guestComment;  
169 - }  
170 -  
171 - public function setGuestComment($value)  
172 - {  
173 - $this->guestComment = $value;  
174 - }  
175 -  
176 - /**  
177 - * @param string $model  
178 - * @param integer $model_id  
179 - *  
180 - * @return ActiveQuery  
181 - */  
182 - public static function getComments($model, $model_id)  
183 - {  
184 - return self::find()  
185 - ->where([  
186 - 'comment.model' => $model,  
187 - 'comment.model_id' => $model_id,  
188 - 'comment.status' => 1,  
189 - ])  
190 - ->with('rating');  
191 - }  
192 -  
193 - public function postComment()  
194 - {  
195 - if($this->checkCreate()) {  
196 - if(!empty($this->comment_pid) && !$this->checkReply()) {  
197 - $this->addError('comment_id', 'You can`t reply to this message');  
198 - return false;  
199 - }  
200 - if($this->insert()) {  
201 - $this->clearSafe();  
202 - return true;  
203 - } else {  
204 - return false;  
205 - }  
206 - }  
207 - $this->addError('comment_id', 'You can`t post comment here');  
208 - return false;  
209 - }  
210 -  
211 - public function updateComment()  
212 - {  
213 - if($this->checkUpdate()) {  
214 - if(empty( $this->comment_id )) {  
215 - $this->addError('comment_id', 'Comment ID not found');  
216 - return false;  
217 - } else {  
218 - if($this->update()) {  
219 - // $this->clearSafe(); Clears safe attributes after AJAX update  
220 - return true;  
221 - } else {  
222 - return false;  
223 - }  
224 - }  
225 - } else {  
226 - $this->addError('comment_id', 'You can`t update this post');  
227 - return false;  
228 - }  
229 - }  
230 -  
231 - public function deleteComment()  
232 - {  
233 - if($this->checkDelete()) {  
234 - if(empty( $this->comment_id )) {  
235 - $this->addError('comment_id', 'Comment ID not found');  
236 - return false;  
237 - } else {  
238 - if($this->user_id == \Yii::$app->user->id) {  
239 - if($this->delete()) {  
240 - return true;  
241 - } else {  
242 - $this->addError('comment_id', 'Can\'t delete post.');  
243 - return false;  
244 - }  
245 - } else {  
246 - if($this->status == self::STATUS_DELETED) {  
247 - return false;  
248 - }  
249 - $this->status = self::STATUS_DELETED;  
250 - if($this->update()) {  
251 - $this->clearSafe();  
252 - return true;  
253 - } else {  
254 - return false;  
255 - }  
256 - }  
257 - }  
258 - } else {  
259 - $this->addError('comment_id', 'You can`t delete this post');  
260 - return false;  
261 - }  
262 - }  
263 -  
264 - public function checkCreate()  
265 - {  
266 - if($this->getGuestComment()) {  
267 - return true;  
268 - } else {  
269 - return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [  
270 - 'model' => $this->model,  
271 - 'model_id' => $this->model_id,  
272 - 'comment_model' => $this,  
273 - ]);  
274 - }  
275 - }  
276 -  
277 - public function checkUpdate()  
278 - {  
279 - if($this->scenario == self::SCENARIO_GUEST) {  
280 - return false;  
281 - } else {  
282 - return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [  
283 - 'model' => $this->model,  
284 - 'model_id' => $this->model_id,  
285 - 'comment' => $this,  
286 - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [  
287 - 'model' => $this->model,  
288 - 'model_id' => $this->model_id,  
289 - 'comment' => $this,  
290 - ]);  
291 - }  
292 - }  
293 -  
294 - public function checkDelete()  
295 - {  
296 - if($this->scenario == self::SCENARIO_GUEST) {  
297 - return false;  
298 - } else {  
299 - return ( \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [  
300 - 'model' => $this->model,  
301 - 'model_id' => $this->model_id,  
302 - 'comment' => $this,  
303 - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [  
304 - 'model' => $this->model,  
305 - 'model_id' => $this->model_id,  
306 - 'comment' => $this,  
307 - ]) );  
308 - }  
309 - }  
310 -  
311 - public function checkReply()  
312 - {  
313 - if($this->scenario == self::SCENARIO_GUEST) {  
314 - return false;  
315 - } else {  
316 - return $this->allowReply;  
317 - }  
318 - }  
319 -  
320 - protected function clearSafe($setNew = true)  
321 - {  
322 - $safe = $this->safeAttributes();  
323 - $count = count($safe);  
324 - $values = array_fill(0, $count, NULL);  
325 - $result = array_combine($safe, $values);  
326 - $this->setAttributes($result);  
327 - $this->setIsNewRecord($setNew);  
328 - }  
329 -  
330 - public function getParent()  
331 - {  
332 - return $this->hasOne(self::className(), [ 'comment_id' => 'comment_pid' ]);  
333 - }  
334 -  
335 - public function getAuthorName()  
336 - {  
337 - if(!empty( $this->author )) {  
338 - return $this->author->username;  
339 - } else {  
340 - return $this->user_name;  
341 - }  
342 - }  
343 -  
344 - public function getAuthor($guestMark = '')  
345 - {  
346 - if(!empty( $this->user )) {  
347 - return $this->user->username;  
348 - } else {  
349 - $name = $this->user_name;  
350 - if(!empty( $guestMark )) {  
351 - $name .= $guestMark;  
352 - }  
353 - return $name;  
354 - }  
355 - }  
356 -  
357 - public function checkRating()  
358 - {  
359 - $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [  
360 - 'model_id' => 'comment_id',  
361 - ])  
362 - ->andWhere([  
363 - 'model' => $this->className(),  
364 - ])  
365 - ->one();  
366 - if(!$rating instanceof \common\modules\comment\models\Rating && !empty( $this->primaryKey )) {  
367 - $rating = new \common\modules\comment\models\Rating([  
368 - 'model' => $this->className(),  
369 - 'model_id' => $this->comment_id,  
370 - 'user_id' => $this->user_id,  
371 - ]);  
372 - $rating->save();  
373 - }  
374 - }  
375 -  
376 - public function getRating()  
377 - {  
378 - $this->checkRating();  
379 - return $this->hasOne(\common\modules\comment\models\Rating::className(), [  
380 - 'model_id' => 'comment_id',  
381 - ])  
382 - ->andWhere([ 'rating.model' => $this->className() ]);  
383 - }  
384 -  
385 - public function hasRating($return = true)  
386 - {  
387 - $rating = $this->hasOne(\common\modules\comment\models\Rating::className(), [  
388 - 'model_id' => 'comment_id',  
389 - ])  
390 - ->andWhere([ 'model' => $this->className() ])  
391 - ->andWhere([  
392 - 'not',  
393 - [ 'value' => NULL ],  
394 - ])  
395 - ->one();  
396 - if($return) {  
397 - return $rating;  
398 - } else {  
399 - return $rating ? true : false;  
400 - }  
401 - }  
402 -  
403 - public function getUser()  
404 - {  
405 - return $this->hasOne(User::className(), [ 'id' => 'user_id' ]);  
406 - }  
407 -  
408 - public function buildButtons(  
409 - $buttons = [  
410 - 'delete',  
411 - 'update',  
412 - 'reply',  
413 - ]  
414 - ) {  
415 - if(in_array('delete', $buttons)) {  
416 - if($this->checkDelete()) {  
417 - $this->buttons[ 'delete' ] = Url::to([  
418 - 'artbox-comment/delete',  
419 - 'comment_id' => $this->comment_id,  
420 - ]);  
421 - }  
422 - }  
423 - if(in_array('update', $buttons)) {  
424 - if($this->checkUpdate()) {  
425 - $this->buttons[ 'update' ] = Url::to([  
426 - 'artbox-comment/update',  
427 - 'comment_id' => $this->comment_id,  
428 - ]);  
429 - }  
430 - }  
431 - if(in_array('reply', $buttons)) {  
432 - if($this->checkReply()) {  
433 - $this->buttons[ 'reply' ] = Url::to([  
434 - 'artbox-comment/reply',  
435 - 'comment_id' => $this->comment_id,  
436 - ]);  
437 - }  
438 - }  
439 - }  
440 -  
441 - public function getAllowReply()  
442 - {  
443 - return $this->hasAttribute('comment_pid');  
444 - }  
445 -  
446 - }  
common/modules/comment/models/CommentModel.php 0 → 100644
  1 +<?php
  2 + namespace common\modules\comment\models;
  3 +
  4 + use common\modules\comment\behaviors\ParentBehavior;
  5 + use common\modules\comment\models\interfaces\CommentInterface;
  6 + use common\modules\comment\Module;
  7 + use yii\base\InvalidConfigException;
  8 + use yii\behaviors\AttributeBehavior;
  9 + use yii\behaviors\BlameableBehavior;
  10 + use yii\behaviors\TimestampBehavior;
  11 + use yii\data\ActiveDataProvider;
  12 + use yii\db\ActiveRecord;
  13 + use yii\helpers\Json;
  14 +
  15 + /**
  16 + * Class CommentModel
  17 + * @property int $artbox_comment_id
  18 + * @property string $text
  19 + * @property int $user_id
  20 + * @property string $username
  21 + * @property string $email
  22 + * @property int $date_add
  23 + * @property int $date_update
  24 + * @property int $date_delete
  25 + * @property int $status
  26 + * @property int $artbox_comment_pid
  27 + * @property int $related_id
  28 + * @property string $ip
  29 + * @property string $info
  30 + * @property string $entity
  31 + * @property int $entity_id
  32 + * @package common\modules\comment\models
  33 + */
  34 + class CommentModel extends ActiveRecord implements CommentInterface
  35 + {
  36 +
  37 + const STATUS_ACTIVE = 1;
  38 + const STATUS_HIDDEN = 0;
  39 + const STATUS_DELETED = 2;
  40 +
  41 + public $encryptedEntity;
  42 +
  43 + public static function tableName()
  44 + {
  45 + return '{{%artbox_comment}}';
  46 + }
  47 +
  48 + public function rules()
  49 + {
  50 + return [
  51 + [
  52 + [
  53 + 'text',
  54 + 'entity',
  55 + 'entity_id',
  56 + ],
  57 + 'required',
  58 + ],
  59 + [
  60 + [
  61 + 'text',
  62 + 'entity',
  63 + ],
  64 + 'string',
  65 + ],
  66 + [
  67 + [ 'entity_id', 'artbox_comment_pid' ],
  68 + 'integer',
  69 + ],
  70 + [
  71 + [ 'status' ],
  72 + 'default',
  73 + 'value' => 0,
  74 + ],
  75 + [
  76 + ['artbox_comment_pid'],
  77 + 'exist',
  78 + 'targetAttribute' => 'artbox_comment_id',
  79 + 'skipOnError' => true,
  80 + ],
  81 + ];
  82 + }
  83 +
  84 + public function behaviors()
  85 + {
  86 + return [
  87 + [
  88 + 'class' => TimestampBehavior::className(),
  89 + 'createdAtAttribute' => 'date_add',
  90 + 'updatedAtAttribute' => 'date_update',
  91 + ],
  92 + [
  93 + 'class' => BlameableBehavior::className(),
  94 + 'createdByAttribute' => 'user_id',
  95 + 'updatedByAttribute' => false,
  96 + ],
  97 + [
  98 + 'class' => AttributeBehavior::className(),
  99 + 'attributes' => [
  100 + ActiveRecord::EVENT_BEFORE_INSERT => 'ip',
  101 + ],
  102 + 'value' => function($event) {
  103 + return \Yii::$app->request->userIP;
  104 + },
  105 + ],
  106 + [
  107 + 'class' => ParentBehavior::className(),
  108 + ],
  109 + ];
  110 + }
  111 +
  112 + public function attributeLabels()
  113 + {
  114 + return [
  115 + 'artbox_comment_id' => \Yii::t('artbox-comment', 'ID'),
  116 + 'text' => \Yii::t('artbox-comment', 'Text'),
  117 + 'user_id' => \Yii::t('artbox-comment', 'User'),
  118 + 'username' => \Yii::t('artbox-comment', 'Username'),
  119 + 'email' => 'Email',
  120 + 'date_add' => \Yii::t('artbox-comment', 'Date add'),
  121 + 'date_update' => \Yii::t('artbox-comment', 'Date update'),
  122 + 'date_delete' => \Yii::t('artbox-comment', 'Date delete'),
  123 + 'status' => \Yii::t('artbox-comment', 'Status'),
  124 + 'artbox_comment_pid' => \Yii::t('artbox-comment', 'Comment parent'),
  125 + 'related_id' => \Yii::t('artbox-comment', 'Comment related'),
  126 + 'ip' => 'IP',
  127 + 'entity' => \Yii::t('artbox-comment', 'Entity'),
  128 + 'info' => \Yii::t('artbox-comment', 'Info'),
  129 + 'entity_id' => \Yii::t('artbox-comment', 'Entity ID'),
  130 + ];
  131 + }
  132 +
  133 + function setEntity(string $entity)
  134 + {
  135 + $this->entity = $entity;
  136 + }
  137 +
  138 + function getEntity(): string
  139 + {
  140 + return $this->entity;
  141 + }
  142 +
  143 + static function getTree(string $entity, int $entityId): ActiveDataProvider
  144 + {
  145 + return new ActiveDataProvider([
  146 + 'query' => self::find()
  147 + ->with([
  148 + 'children',
  149 + 'user',
  150 + 'children.user',
  151 + ])
  152 + ->where([
  153 + 'entity' => $entity,
  154 + 'entity_id' => $entityId,
  155 + 'status' => 1,
  156 + 'artbox_comment_pid' => NULL,
  157 + ]),
  158 + 'pagination' => [
  159 + 'pageSize' => 20,
  160 + ],
  161 + 'sort' => [
  162 + 'defaultOrder' => [
  163 + 'date_add' => SORT_DESC,
  164 + ],
  165 + ],
  166 + ]);
  167 + }
  168 +
  169 + function deleteComment(): bool {
  170 + if(\Yii::$app->user->id != NULL && \Yii::$app->user->id == $this->user_id) {
  171 + if($this->delete()) {
  172 + return true;
  173 + }
  174 + }
  175 + return false;
  176 + }
  177 +
  178 + function setEntityId(int $entityId)
  179 + {
  180 + $this->entityId = $entityId;
  181 + }
  182 +
  183 + function getEntityId(): int
  184 + {
  185 + return $this->entityId;
  186 + }
  187 +
  188 + function getChildren()
  189 + {
  190 + return $this->hasMany(self::className(), [ 'artbox_comment_pid' => 'artbox_comment_id' ])
  191 + ->andFilterWhere(['status' => self::STATUS_ACTIVE])
  192 + ->inverseOf('parent');
  193 + }
  194 +
  195 + function getParent()
  196 + {
  197 + return $this->hasOne(self::className(), [ 'artbox_comment_id' => 'artbox_comment_pid' ])
  198 + ->inverseOf('children');
  199 + }
  200 +
  201 + function getUser()
  202 + {
  203 + $module = \Yii::$app->getModule('artbox-comment');
  204 + return $this->hasOne($module->userIdentityClass, [ 'id' => 'user_id' ]);
  205 + }
  206 +
  207 + function getRating()
  208 + {
  209 + return $this->hasOne(RatingModel::className(), ['model_id' => 'artbox_comment_id'])->andWhere(['or', ['artbox_comment_rating.model' => NULL], ['artbox_comment_rating.model' => self::className()] ]);
  210 + }
  211 + }
0 \ No newline at end of file 212 \ No newline at end of file
common/modules/comment/models/CommentModelSearch.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\modules\comment\models;
  4 +
  5 + use Yii;
  6 + use yii\base\Model;
  7 + use yii\data\ActiveDataProvider;
  8 + use common\modules\comment\models\CommentModel;
  9 +
  10 + /**
  11 + * CommentModelSearch represents the model behind the search form about
  12 + * `common\modules\comment\models\CommentModel`.
  13 + */
  14 + class CommentModelSearch extends CommentModel
  15 + {
  16 +
  17 + public $rating_value;
  18 +
  19 + public $children_count;
  20 +
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + [
  28 + [
  29 + 'artbox_comment_id',
  30 + 'date_add',
  31 + 'date_update',
  32 + 'date_delete',
  33 + 'status',
  34 + 'artbox_comment_pid',
  35 + 'related_id',
  36 + 'entity_id',
  37 + ],
  38 + 'integer',
  39 + ],
  40 + [
  41 + [
  42 + 'children_count',
  43 + ],
  44 + 'integer',
  45 + 'min' => 0,
  46 + ],
  47 + [
  48 + [
  49 + 'rating_value',
  50 + ],
  51 + 'number',
  52 + 'min' => 1,
  53 + 'max' => 5,
  54 + ],
  55 + [
  56 + [
  57 + 'user_id',
  58 + 'text',
  59 + 'username',
  60 + 'email',
  61 + 'ip',
  62 + 'entity',
  63 + 'info',
  64 + ],
  65 + 'safe',
  66 + ],
  67 + ];
  68 + }
  69 +
  70 + public function attributeLabels()
  71 + {
  72 + return array_merge(parent::attributeLabels(), [
  73 + 'rating_value' => 'Рейтинг',
  74 + 'children_count' => 'Количество ответов',
  75 + ]);
  76 + }
  77 +
  78 + /**
  79 + * @inheritdoc
  80 + */
  81 + public function scenarios()
  82 + {
  83 + // bypass scenarios() implementation in the parent class
  84 + return Model::scenarios();
  85 + }
  86 +
  87 + /**
  88 + * Creates data provider instance with search query applied
  89 + *
  90 + * @param array $params
  91 + *
  92 + * @return ActiveDataProvider
  93 + */
  94 + public function search($params)
  95 + {
  96 + $query = CommentModel::find()
  97 + ->joinWith([
  98 + 'rating',
  99 + 'user',
  100 + ]);
  101 +
  102 + // add conditions that should always apply here
  103 +
  104 + $dataProvider = new ActiveDataProvider([
  105 + 'query' => $query,
  106 + 'sort' => [
  107 + 'attributes' => [
  108 + 'rating_value' => [
  109 + 'asc' => [ 'artbox_comment_rating.value' => SORT_ASC ],
  110 + 'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ],
  111 + ],
  112 + 'artbox_comment_id',
  113 + 'date_add',
  114 + 'text',
  115 + 'user_id',
  116 + 'status',
  117 + 'entity',
  118 + 'entity_id',
  119 + ],
  120 + 'defaultOrder' => [
  121 + 'date_add' => SORT_DESC,
  122 + ],
  123 + ],
  124 + ]);
  125 +
  126 + $this->load($params);
  127 +
  128 + if(!$this->validate()) {
  129 + // uncomment the following line if you do not want to return any records when validation fails
  130 + // $query->where('0=1');
  131 + return $dataProvider;
  132 + }
  133 +
  134 + // grid filtering conditions
  135 + $query->andFilterWhere([
  136 + 'artbox_comment_id' => $this->artbox_comment_id,
  137 + 'date_add' => $this->date_add,
  138 + 'date_update' => $this->date_update,
  139 + 'date_delete' => $this->date_delete,
  140 + 'artbox_comment.status' => $this->status,
  141 + 'artbox_comment_pid' => $this->artbox_comment_pid,
  142 + 'related_id' => $this->related_id,
  143 + 'entity_id' => $this->entity_id,
  144 + ]);
  145 +
  146 + $query->andFilterWhere([
  147 + 'like',
  148 + 'text',
  149 + $this->text,
  150 + ])
  151 + ->andFilterWhere([
  152 + 'like',
  153 + 'username',
  154 + $this->username,
  155 + ])
  156 + ->andFilterWhere([
  157 + 'like',
  158 + 'email',
  159 + $this->email,
  160 + ])
  161 + ->andFilterWhere([
  162 + 'like',
  163 + 'ip',
  164 + $this->ip,
  165 + ])
  166 + ->andFilterWhere([
  167 + 'like',
  168 + 'entity',
  169 + $this->entity,
  170 + ])
  171 + ->andFilterWhere([
  172 + 'like',
  173 + 'info',
  174 + $this->info,
  175 + ])
  176 + ->andFilterWhere([
  177 + 'artbox_comment_rating.value' => $this->rating_value,
  178 + ]);
  179 +
  180 + if(!empty( $this->user_id )) {
  181 + $query->andWhere([
  182 + 'or',
  183 + [ 'artbox_comment.user_id' => (int) $this->user_id ],
  184 + [
  185 + 'like',
  186 + 'user.username',
  187 + $this->user_id,
  188 + ],
  189 + [
  190 + 'like',
  191 + 'artbox_comment.username',
  192 + $this->user_id,
  193 + ],
  194 + [
  195 + 'like',
  196 + 'artbox_comment.email',
  197 + $this->user_id,
  198 + ],
  199 + ]);
  200 + }
  201 +
  202 + return $dataProvider;
  203 + }
  204 + }
common/modules/comment/models/CommentProject.php deleted
1 -<?php  
2 - namespace common\modules\comment\models;  
3 -  
4 - use common\models\Currency;  
5 - use common\models\File;  
6 - use common\models\Project;  
7 - use common\models\User;  
8 - use yii\db\ActiveQuery;  
9 - use yii\db\ActiveRecord;  
10 - use yii\web\UploadedFile;  
11 -  
12 - /**  
13 - * Class Comment  
14 - * @property bool $guestComment  
15 - * @property integer $comment_id  
16 - * @property string $text  
17 - * @property int $user_id  
18 - * @property int $status  
19 - * @property string $date_add  
20 - * @property string $date_update  
21 - * @property string $date_delete  
22 - * @property string $model  
23 - * @property int $model_id  
24 - * @property string $files  
25 - * @property float $budget_from  
26 - * @property float $budget_to  
27 - * @property int $term_from  
28 - * @property int $term_to  
29 - * @property int $state  
30 - * @property Currency $currency  
31 - * @property Project $project  
32 - * @package common\modules\comment\models  
33 - */  
34 - class CommentProject extends \yii\db\ActiveRecord  
35 - implements \common\modules\comment\interfaces\CommentInterface  
36 - {  
37 -  
38 - const STATUS_HIDDEN = 0;  
39 - const STATUS_DELETED = 2;  
40 - const STATUS_ACTIVE = 1;  
41 - const STATUS_PERSONAL = 3;  
42 - const STATUS_ANONYMOUS = 4;  
43 -  
44 - const STATE_NEW = 1;  
45 - const STATE_CANDIDATE = 2;  
46 - const STATE_PERFORMER = 3;  
47 - const STATE_DENY = 4;  
48 - const STATE_TRASH = 5;  
49 -  
50 - const SCENARIO_USER = 'user';  
51 - const SCENARIO_GUEST = 'guest';  
52 - const SCENARIO_STATE = 'state';  
53 - const SCENARIO_OWNER = 'owner';  
54 -  
55 - /**  
56 - * @var bool  
57 - */  
58 - public $guestComment = false;  
59 -  
60 - public $file;  
61 -  
62 - public function rules()  
63 - {  
64 - return [  
65 - [  
66 - [  
67 - 'text',  
68 - 'budget_from',  
69 - 'budget_to',  
70 - 'term_from',  
71 - 'term_to',  
72 - 'budget_currency',  
73 - ],  
74 - 'required',  
75 - ],  
76 - [  
77 - [  
78 - 'budget_currency',  
79 - ],  
80 - 'integer',  
81 - ],  
82 - [  
83 - [  
84 - 'budget_from',  
85 - 'budget_to',  
86 - 'term_from',  
87 - 'term_to',  
88 - ],  
89 - 'integer',  
90 - 'min' => 0,  
91 - ],  
92 - [  
93 - [  
94 - 'budget_currency',  
95 - ],  
96 - 'default',  
97 - 'value' => 3,  
98 - ],  
99 - [  
100 - [ 'budget_currency' ],  
101 - 'exist',  
102 - 'targetClass' => Currency::className(),  
103 - 'targetAttribute' => 'currency_id',  
104 - ],  
105 - [  
106 - [  
107 - 'files',  
108 - ],  
109 - 'string',  
110 - ],  
111 - [  
112 - [  
113 - 'file',  
114 - ],  
115 - 'safe',  
116 - ],  
117 - [  
118 - [ 'status' ],  
119 - 'default',  
120 - 'value' => 1,  
121 - ],  
122 - [  
123 - [ 'state' ],  
124 - 'integer',  
125 - 'max' => 4,  
126 - 'min' => 1,  
127 - 'on' => self::SCENARIO_STATE,  
128 - ],  
129 - [  
130 - [ 'state' ],  
131 - 'required',  
132 - 'on' => self::SCENARIO_STATE,  
133 - ],  
134 - [  
135 - [ 'state' ],  
136 - 'required',  
137 - 'on' => self::SCENARIO_OWNER,  
138 - ],  
139 - [  
140 - [ 'state' ],  
141 - 'in',  
142 - 'range' => [  
143 - 1,  
144 - 5,  
145 - ],  
146 - 'on' => self::SCENARIO_OWNER,  
147 - ],  
148 - ];  
149 - }  
150 -  
151 - public function scenarios()  
152 - {  
153 - return [  
154 - self::SCENARIO_USER => [  
155 - 'text',  
156 - 'budget_from',  
157 - 'budget_to',  
158 - 'budget_currency',  
159 - 'term_from',  
160 - 'term_to',  
161 - 'file',  
162 - ],  
163 - self::SCENARIO_GUEST => [  
164 -  
165 - ],  
166 - self::SCENARIO_STATE => [  
167 - 'state',  
168 - ],  
169 - self::SCENARIO_OWNER => [  
170 - 'state',  
171 - ],  
172 - ];  
173 - }  
174 -  
175 - /**  
176 - * @inheritdoc  
177 - */  
178 - public function behaviors()  
179 - {  
180 - return [  
181 - [  
182 - 'class' => \yii\behaviors\TimestampBehavior::className(),  
183 - 'createdAtAttribute' => 'date_add',  
184 - 'updatedAtAttribute' => 'date_update',  
185 - 'value' => new \yii\db\Expression('NOW()'),  
186 - ],  
187 - ];  
188 - }  
189 -  
190 - public static function tableName()  
191 - {  
192 - return '{{%comment_project}}';  
193 - }  
194 -  
195 - /**  
196 - * @inheritdoc  
197 - */  
198 - public function attributeLabels()  
199 - {  
200 - return [  
201 - 'text' => \Yii::t('app', 'Текст ответа'),  
202 - 'budget_from' => \Yii::t('app', 'от'),  
203 - 'budget_to' => \Yii::t('app', 'до'),  
204 - 'term_from' => \Yii::t('app', 'от'),  
205 - 'term_to' => \Yii::t('app', 'до'),  
206 - ];  
207 - }  
208 -  
209 - public function getGuestComment()  
210 - {  
211 - return $this->guestComment;  
212 - }  
213 -  
214 - // public function setGuestComment($value)  
215 - // {  
216 - // $this->guestComment = $value;  
217 - // }  
218 -  
219 - /**  
220 - * @param string $model  
221 - * @param integer $model_id  
222 - *  
223 - * @return ActiveQuery  
224 - */  
225 - public static function getComments($model, $model_id)  
226 - {  
227 - /**  
228 - * @var User $user  
229 - */  
230 - $user = \Yii::$app->user->identity;  
231 - if(!empty($user)) {  
232 - $project = Project::findOne($model_id);  
233 - if(!empty($project) && $user->id == $project->user_id) {  
234 - return self::find()  
235 - ->where([  
236 - 'comment_project.model' => $model,  
237 - 'comment_project.model_id' => $model_id,  
238 - 'comment_project.status' => [self::STATUS_ANONYMOUS, self::STATUS_ACTIVE, self::STATUS_PERSONAL],  
239 - ])  
240 - ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments');  
241 - }  
242 - }  
243 - $query = self::find()  
244 - ->where([  
245 - 'comment_project.model' => $model,  
246 - 'comment_project.model_id' => $model_id,  
247 - ])  
248 - ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments');  
249 - if(!empty($user)) {  
250 - $query->andWhere(['or', ['comment_project.status' => self::STATUS_ACTIVE], ['comment_project.status' => self::STATUS_ANONYMOUS, 'comment_project.user_id' => $user->id]]);  
251 - } else {  
252 - $query->andWhere(['comment_project.status' => 1]);  
253 - }  
254 - return $query;  
255 - }  
256 -  
257 - public function postComment()  
258 - {  
259 - if($this->checkCreate()) {  
260 - if(!empty( \Yii::$app->request->post($this->formName())[ 'anonymous' ] )) {  
261 - $this->status = self::STATUS_ANONYMOUS;  
262 - }  
263 - $this->file = UploadedFile::getInstances($this, 'file');  
264 - if(!empty( $this->file )) {  
265 - $file_id = [ ];  
266 - if(is_array($this->file)) {  
267 - foreach($this->file as $file) {  
268 - if($file instanceof UploadedFile) {  
269 - $file_model = new File();  
270 - $file_id[] = $file_model->saveFile($file);  
271 - }  
272 - }  
273 - } else {  
274 - if($this->file instanceof UploadedFile) {  
275 - $file_model = new File();  
276 - $file_id[] = $file_model->saveFile($this->file);  
277 - }  
278 - }  
279 - $this->files = json_encode($file_id);  
280 - }  
281 - if($this->insert()) {  
282 - $this->clearSafe();  
283 - return true;  
284 - } else {  
285 - return false;  
286 - }  
287 - } else {  
288 - $this->addError('comment_id', 'You can`t post comment here');  
289 - return false;  
290 - }  
291 - }  
292 -  
293 - public function updateComment()  
294 - {  
295 - if($this->checkUpdate()) {  
296 - if(empty( $this->comment_id )) {  
297 - $this->addError('comment_id', 'Comment ID not found');  
298 - return false;  
299 - } else {  
300 - if($this->update()) {  
301 - $this->clearSafe();  
302 - return true;  
303 - } else {  
304 - return false;  
305 - }  
306 - }  
307 - } else {  
308 - $this->addError('comment_id', 'You can`t update this post');  
309 - return false;  
310 - }  
311 - }  
312 -  
313 - public function deleteComment()  
314 - {  
315 - if($this->checkDelete()) {  
316 - if(empty( $this->comment_id )) {  
317 - $this->addError('comment_id', 'Comment ID not found');  
318 - return false;  
319 - } else {  
320 - if($this->status == self::STATUS_DELETED) {  
321 - return false;  
322 - }  
323 - $this->status = self::STATUS_DELETED;  
324 - if($this->update()) {  
325 - $this->clearSafe();  
326 - return true;  
327 - } else {  
328 - return false;  
329 - }  
330 - }  
331 - } else {  
332 - $this->addError('comment_id', 'You can`t delete this post');  
333 - return false;  
334 - }  
335 - }  
336 -  
337 - public function checkCreate()  
338 - {  
339 - if($this->getGuestComment()) {  
340 - return true;  
341 - } else {  
342 - return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [  
343 - 'model' => $this->model,  
344 - 'model_id' => $this->model_id,  
345 - 'comment_model' => $this->className(),  
346 - ]);  
347 - }  
348 - }  
349 -  
350 - public function checkUpdate()  
351 - {  
352 - if($this->scenario == self::SCENARIO_GUEST) {  
353 - return false;  
354 - } else {  
355 - return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [  
356 - 'model' => $this->model,  
357 - 'model_id' => $this->model_id,  
358 - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [  
359 - 'model' => $this->model,  
360 - 'model_id' => $this->model_id,  
361 - ]);  
362 - }  
363 - }  
364 -  
365 - public function checkDelete()  
366 - {  
367 - if($this->scenario == self::SCENARIO_GUEST) {  
368 - return false;  
369 - } else {  
370 - return \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [  
371 - 'model' => $this->model,  
372 - 'model_id' => $this->model_id,  
373 - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [  
374 - 'model' => $this->model,  
375 - 'model_id' => $this->model_id,  
376 - ]);  
377 - }  
378 - }  
379 -  
380 - protected function clearSafe($setNew = true)  
381 - {  
382 - $safe = $this->safeAttributes();  
383 - $count = count($safe);  
384 - $values = array_fill(0, $count, NULL);  
385 - $result = array_combine($safe, $values);  
386 - $this->setAttributes($result);  
387 - $this->setIsNewRecord($setNew);  
388 - }  
389 -  
390 - public function getAuthor()  
391 - {  
392 - // if($this->user_id != NULL) {  
393 - return $this->hasOne(\common\models\User::className(), [ 'id' => 'user_id' ]);  
394 - // } else {  
395 - // return ['firstname' => $this->user_name, 'email' => $this->user_email];  
396 - // }  
397 - }  
398 -  
399 - /**  
400 - * @return ActiveQuery  
401 - */  
402 - public function getCurrency()  
403 - {  
404 - return $this->hasOne(Currency::className(), [ 'currency_id' => 'budget_currency' ]);  
405 - }  
406 -  
407 - /**  
408 - * @return File[]  
409 - */  
410 - public function getFilesList()  
411 - {  
412 - $files = json_decode($this->files);  
413 - if(!empty( $files )) {  
414 - return File::findAll($files);  
415 - } else {  
416 - return [ ];  
417 - }  
418 - }  
419 -  
420 - /**  
421 - * @return ActiveRecord  
422 - * @throws \TypeError  
423 - */  
424 - public function getOwner()  
425 - {  
426 - $model = new $this->model();  
427 - if($model instanceof ActiveRecord) {  
428 - return $model->findOne($this->model_id);  
429 - } else {  
430 - throw new \TypeError('Model must extends Active Record Class');  
431 - }  
432 - }  
433 -  
434 - public function getProject()  
435 - {  
436 - return $this->hasOne(Project::className(), [ 'project_id' => 'model_id' ]);  
437 - }  
438 -  
439 - /**  
440 - * @return User  
441 - */  
442 - public function getUser()  
443 - {  
444 - return $this->hasOne(User::className(), [ 'id' => 'user_id' ]);  
445 - }  
446 -  
447 - public function changeState()  
448 - {  
449 - if($this->isAttributeChanged('state')) {  
450 - if($this->save()) {  
451 - return true;  
452 - } else {  
453 - return false;  
454 - }  
455 - } else {  
456 - return true;  
457 - }  
458 - }  
459 -  
460 - }  
common/modules/comment/models/CommentProjectAnswer.php deleted
1 -<?php  
2 - namespace common\modules\comment\models;  
3 -  
4 - use common\models\Project;  
5 - use common\models\User;  
6 - use yii\db\ActiveQuery;  
7 - use yii\helpers\Url;  
8 -  
9 - /**  
10 - * Class Comment  
11 - * @property bool $guestComment  
12 - * @property integer $comment_id  
13 - * @property string $text  
14 - * @property int $user_id  
15 - * @property string $user_name  
16 - * @property string $user_email  
17 - * @property int $comment_pid  
18 - * @property int $status  
19 - * @property string $date_add  
20 - * @property string $date_update  
21 - * @property string $date_delete  
22 - * @property string $model  
23 - * @property int $model_id  
24 - * @property Rating $rating  
25 - * @property User $user  
26 - * @property User $author  
27 - * @package common\modules\comment\models  
28 - */  
29 - class CommentProjectAnswer extends Comment  
30 - {  
31 -  
32 - public function rules()  
33 - {  
34 - return [  
35 - [  
36 - [  
37 - 'text',  
38 - 'user_name',  
39 - 'user_email',  
40 - ],  
41 - 'required',  
42 - ],  
43 - [  
44 - [  
45 - 'rating',  
46 - ],  
47 - 'safe',  
48 - ],  
49 - [  
50 - [ 'user_email' ],  
51 - 'email',  
52 - ],  
53 - [  
54 - [ 'user_name' ],  
55 - 'string',  
56 - ],  
57 - [  
58 - [  
59 - 'comment_id',  
60 - 'comment_pid',  
61 - ],  
62 - 'integer',  
63 - ],  
64 - [  
65 - [ 'status' ],  
66 - 'default',  
67 - 'value' => 1,  
68 - ],  
69 - [  
70 - [ 'comment_pid' ],  
71 - 'exist',  
72 - 'targetAttribute' => 'comment_id',  
73 - 'filter' => [  
74 - 'model' => $this->model,  
75 - 'model_id' => $this->model_id,  
76 - ],  
77 - ],  
78 - [  
79 - ['comment_pid'],  
80 - 'required',  
81 - 'when' => function($model, $attribute) {  
82 - /**  
83 - * @var CommentProjectAnswer $model  
84 - * @var string $attribute  
85 - */  
86 - if(!empty(\Yii::$app->user->id) && $model->isNewRecord && !empty($model->model) && !empty($model->model_id)) {  
87 - $project = Project::findOne($model->model_id);  
88 - if(!empty($project) && $project->user_id == \Yii::$app->user->id) {  
89 - return true;  
90 - }  
91 - }  
92 - return false;  
93 - }  
94 - ],  
95 - ];  
96 - }  
97 -  
98 - /**  
99 - * @param string $model  
100 - * @param integer $model_id  
101 - *  
102 - * @return ActiveQuery  
103 - */  
104 - public static function getComments($model, $model_id)  
105 - {  
106 - $query = self::find()  
107 - ->where([  
108 - 'comment.model' => $model,  
109 - 'comment.model_id' => $model_id,  
110 - 'comment.status' => 1,  
111 - 'comment.comment_pid' => NULL,  
112 - ])  
113 - ->with('parent');  
114 - $project = Project::findOne($model_id);  
115 - $user = \Yii::$app->user;  
116 - if(empty( $user ) || $project->user_id != $user->id) {  
117 - $query->innerJoin([ 'child' => 'comment' ], 'comment.comment_id = child.comment_pid')  
118 - ->andWhere([  
119 - 'not',  
120 - [ 'child.comment_id' => NULL ],  
121 - ]);  
122 - }  
123 - return $query;  
124 - }  
125 -  
126 - public function beforeDelete()  
127 - {  
128 - if(!empty($this->child)) {  
129 - $this->child->delete();  
130 - }  
131 - return parent::beforeDelete(); // TODO: Change the autogenerated stub  
132 - }  
133 -  
134 - public function checkCreate()  
135 - {  
136 - if($this->getGuestComment()) {  
137 - return true;  
138 - } else {  
139 - return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [  
140 - 'model' => $this->model,  
141 - 'model_id' => $this->model_id,  
142 - 'comment_model' => $this,  
143 - ]);  
144 - }  
145 - }  
146 -  
147 - public function checkUpdate()  
148 - {  
149 - if($this->scenario == self::SCENARIO_GUEST) {  
150 - return false;  
151 - } else {  
152 - if(!empty($this->comment_pid) && $this->user_id == \Yii::$app->user->id) {  
153 - return true;  
154 - }  
155 - }  
156 - return false;  
157 - }  
158 -  
159 - public function checkDelete()  
160 - {  
161 - if($this->scenario == self::SCENARIO_GUEST) {  
162 - return false;  
163 - } else {  
164 - return ( \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [  
165 - 'model' => $this->model,  
166 - 'model_id' => $this->model_id,  
167 - 'comment' => $this,  
168 - ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [  
169 - 'model' => $this->model,  
170 - 'model_id' => $this->model_id,  
171 - 'comment' => $this,  
172 - ]) );  
173 - }  
174 - }  
175 -  
176 - public function checkReply()  
177 - {  
178 - if($this->scenario != self::SCENARIO_GUEST) {  
179 - if(!$this->isNewRecord && empty( $this->comment_pid )) {  
180 - $project = Project::findOne($this->model_id);  
181 - if($project->user_id == \Yii::$app->user->id && empty($this->child)) {  
182 - return true;  
183 - }  
184 - } elseif($this->isNewRecord && !empty($this->comment_pid)) {  
185 - $parent = self::findOne($this->comment_pid);  
186 - if(!empty($parent) && $parent->checkReply()) {  
187 - return true;  
188 - }  
189 - }  
190 - }  
191 - return false;  
192 - }  
193 -  
194 - public function getChild()  
195 - {  
196 - return $this->hasOne($this->className(), [ 'comment_pid' => 'comment_id' ]);  
197 - }  
198 -  
199 - }  
common/modules/comment/models/CommentProjectSearch.php deleted
1 -<?php  
2 - namespace common\modules\comment\models;  
3 -  
4 - use common\models\Currency;  
5 - use common\models\File;  
6 - use common\models\User;  
7 - use yii\data\ActiveDataProvider;  
8 - use yii\db\ActiveQuery;  
9 - use yii\db\ActiveRecord;  
10 - use yii\web\UploadedFile;  
11 -  
12 - /**  
13 - * Class Comment  
14 - * @property bool $guestComment  
15 - * @property integer $comment_id  
16 - * @property string $text  
17 - * @property int $user_id  
18 - * @property int $status  
19 - * @property string $date_add  
20 - * @property string $date_update  
21 - * @property string $date_delete  
22 - * @property string $model  
23 - * @property int $model_id  
24 - * @property string $files  
25 - * @property float $budget_from  
26 - * @property float $budget_to  
27 - * @property int $term_from  
28 - * @property int $term_to  
29 - * @property int $state  
30 - * @property Currency $currency  
31 - * @package common\modules\comment\models  
32 - */  
33 - class CommentProjectSearch extends CommentProject  
34 - {  
35 -  
36 - const SCENARIO_SEARCH = 'search';  
37 -  
38 - public function rules()  
39 - {  
40 - return [  
41 - [  
42 - [  
43 - 'state',  
44 - ],  
45 - 'integer',  
46 - 'max' => 5,  
47 - 'min' => 1,  
48 - ],  
49 - [  
50 - [  
51 - 'state',  
52 - ],  
53 - 'default',  
54 - 'value' => self::STATE_NEW,  
55 - ],  
56 - ];  
57 - }  
58 -  
59 - public function scenarios()  
60 - {  
61 - return array_merge(parent::scenarios(), [  
62 - self::SCENARIO_SEARCH => [  
63 - 'state',  
64 - ],  
65 - ]);  
66 - }  
67 -  
68 - public function search($params)  
69 - {  
70 - $query = CommentProject::find()  
71 - ->with('project')  
72 - ->with('project.budgetCurrency')  
73 - ->with('project.comments')  
74 - ->where([ 'user_id' => \Yii::$app->user->getId() ]);  
75 -  
76 - $dataProvider = new ActiveDataProvider([  
77 - 'query' => $query,  
78 - ]);  
79 -  
80 - $this->load($params);  
81 -  
82 - if(!$this->validate()) {  
83 - $query->andWhere('0=1');  
84 - return $dataProvider;  
85 - }  
86 -  
87 - $query->andWhere([ 'state' => $this->state ]);  
88 -  
89 - return $dataProvider;  
90 - }  
91 -  
92 - }  
common/modules/comment/models/LikeModel.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\modules\comment\models;
  4 +
  5 + use yii\db\ActiveRecord;
  6 +
  7 + /**
  8 + * Class LikeModel
  9 + * @package common\modules\comment\models
  10 + */
  11 + class LikeModel extends ActiveRecord
  12 + {
  13 +
  14 + }
0 \ No newline at end of file 15 \ No newline at end of file
common/modules/comment/models/Rating.php renamed to common/modules/comment/models/RatingModel.php
@@ -3,11 +3,13 @@ @@ -3,11 +3,13 @@
3 namespace common\modules\comment\models; 3 namespace common\modules\comment\models;
4 4
5 use Yii; 5 use Yii;
  6 +use yii\behaviors\BlameableBehavior;
  7 +use yii\behaviors\TimestampBehavior;
6 8
7 /** 9 /**
8 - * This is the model class for table "rating". 10 + * This is the model class for table "artbox_comment_rating".
9 * 11 *
10 - * @property integer $rating_id 12 + * @property integer $artbox_comment_rating_id
11 * @property string $date_add 13 * @property string $date_add
12 * @property string $date_update 14 * @property string $date_update
13 * @property integer $user_id 15 * @property integer $user_id
@@ -17,16 +19,14 @@ use Yii; @@ -17,16 +19,14 @@ use Yii;
17 * 19 *
18 * @property \common\models\User $user 20 * @property \common\models\User $user
19 */ 21 */
20 -class Rating extends \yii\db\ActiveRecord 22 +class RatingModel extends \yii\db\ActiveRecord
21 { 23 {
22 -  
23 - public $rating;  
24 /** 24 /**
25 * @inheritdoc 25 * @inheritdoc
26 */ 26 */
27 public static function tableName() 27 public static function tableName()
28 { 28 {
29 - return 'rating'; 29 + return 'artbox_comment_rating';
30 } 30 }
31 31
32 /** 32 /**
@@ -35,10 +35,27 @@ class Rating extends \yii\db\ActiveRecord @@ -35,10 +35,27 @@ class Rating extends \yii\db\ActiveRecord
35 public function rules() 35 public function rules()
36 { 36 {
37 return [ 37 return [
38 - [['value'], 'integer'], 38 + [['value'], 'required'],
  39 + [['value'], 'number', 'min' => 0.5, 'max' => 5],
39 ]; 40 ];
40 } 41 }
41 - 42 +
  43 + public function behaviors()
  44 + {
  45 + return [
  46 + [
  47 + 'class' => TimestampBehavior::className(),
  48 + 'createdAtAttribute' => 'date_add',
  49 + 'updatedAtAttribute' => 'date_update',
  50 + ],
  51 + [
  52 + 'class' => BlameableBehavior::className(),
  53 + 'createdByAttribute' => 'user_id',
  54 + 'updatedByAttribute' => false,
  55 + ],
  56 + ];
  57 + }
  58 +
42 /** 59 /**
43 * @inheritdoc 60 * @inheritdoc
44 */ 61 */
@@ -61,4 +78,10 @@ class Rating extends \yii\db\ActiveRecord @@ -61,4 +78,10 @@ class Rating extends \yii\db\ActiveRecord
61 { 78 {
62 return $this->hasOne(\common\models\User::className(), ['id' => 'user_id']); 79 return $this->hasOne(\common\models\User::className(), ['id' => 'user_id']);
63 } 80 }
  81 +
  82 + public function getModel()
  83 + {
  84 + $model = $this->model;
  85 + return $this->hasOne($model, [$model::primaryKey() => 'model_id']);
  86 + }
64 } 87 }
common/modules/comment/models/interfaces/CommentInterface.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\modules\comment\models\interfaces;
  4 +
  5 + use yii\data\ActiveDataProvider;
  6 +
  7 + /**
  8 + * Interface CommentInterface
  9 + * @package common\modules\comment\models\interfaces
  10 + */
  11 + interface CommentInterface
  12 + {
  13 + function setEntity(string $entity);
  14 +
  15 + function getEntity(): string;
  16 +
  17 + function setEntityId(int $entityId);
  18 +
  19 + function getEntityId(): int;
  20 +
  21 + static function getTree(string $entity, int $entityId): ActiveDataProvider;
  22 +
  23 + }
0 \ No newline at end of file 24 \ No newline at end of file
common/modules/comment/rbac/ArtboxCommentCreateRule.php deleted
1 -<?php  
2 -  
3 - namespace common\modules\comment\rbac;  
4 -  
5 - use common\modules\comment\models\CommentProject;  
6 - use yii\rbac\Rule;  
7 -  
8 - class ArtboxCommentCreateRule extends Rule  
9 - {  
10 -  
11 - public $name = 'canCommentCreateArtbox';  
12 -  
13 - public function execute($user, $item, $params)  
14 - {  
15 - if($params[ 'model' ] == \common\models\Project::className() && !empty($params['comment_model']) && $params['comment_model'] == CommentProject::className()) {  
16 - return $this->checkProject($user, $item, $params);  
17 - }  
18 - return true;  
19 - }  
20 -  
21 - public function checkProject($user, $item, $params)  
22 - {  
23 - $project = \common\models\Project::findOne($params['model_id']);  
24 - if($project->user_id == $user) {  
25 - return false;  
26 - }  
27 - $comment = \common\modules\comment\models\CommentProject::find()  
28 - ->where([ 'model' => $params[ 'model' ],  
29 - 'model_id' => $params[ 'model_id' ],  
30 - 'user_id' => $user,  
31 - ])->one();  
32 - if(empty($comment)) {  
33 - return true;  
34 - } else {  
35 - return false;  
36 - }  
37 - }  
38 -  
39 - }  
40 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/rbac/ArtboxCommentDeleteOwnRule.php deleted
1 -<?php  
2 -  
3 - namespace common\modules\comment\rbac;  
4 -  
5 - use yii\rbac\Rule;  
6 -  
7 - class ArtboxCommentDeleteOwnRule extends Rule  
8 - {  
9 -  
10 - public $name = 'canCommentDeleteOwnArtbox';  
11 -  
12 - public function execute($user, $item, $params)  
13 - {  
14 - if(!empty($params['comment'])) {  
15 - if($params['comment']->user_id == \Yii::$app->user->id) {  
16 - return true;  
17 - }  
18 - }  
19 - return false;  
20 - }  
21 -  
22 - }  
23 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/rbac/ArtboxCommentDeleteRule.php deleted
1 -<?php  
2 -  
3 - namespace common\modules\comment\rbac;  
4 -  
5 - use common\models\User;  
6 - use yii\db\ActiveRecord;  
7 - use yii\rbac\Rule;  
8 -  
9 - class ArtboxCommentDeleteRule extends Rule  
10 - {  
11 -  
12 - public $name = 'canCommentDeleteArtbox';  
13 -  
14 - public function execute($user, $item, $params)  
15 - {  
16 - /**  
17 - * @var ActiveRecord $model  
18 - */  
19 - if(!empty($params['model']) && !empty($params['model_id'])) {  
20 - $model = new $params['model'];  
21 - if($model instanceof ActiveRecord) {  
22 - $model = $model::findOne($params['model_id']);  
23 - if($model->hasAttribute('user_id') && $model->user_id == \Yii::$app->user->id) {  
24 - return true;  
25 - } elseif($model instanceof User && $model->id == \Yii::$app->user->id) {  
26 - return true;  
27 - }  
28 - }  
29 - }  
30 - return false;  
31 - }  
32 -  
33 - }  
34 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php deleted
1 -<?php  
2 -  
3 - namespace common\modules\comment\rbac;  
4 -  
5 - use yii\rbac\Rule;  
6 -  
7 - class ArtboxCommentUpdateOwnRule extends Rule  
8 - {  
9 -  
10 - public $name = 'canCommentUpdateOwnArtbox';  
11 -  
12 - public function execute($user, $item, $params)  
13 - {  
14 - if($params['comment']->user_id == \Yii::$app->user->id) {  
15 - return true;  
16 - }  
17 - return false;  
18 - }  
19 -  
20 - }  
21 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/rbac/ArtboxCommentUpdateRule.php deleted
1 -<?php  
2 -  
3 - namespace common\modules\comment\rbac;  
4 -  
5 - use yii\rbac\Rule;  
6 -  
7 - class ArtboxCommentUpdateRule extends Rule  
8 - {  
9 -  
10 - public $name = 'canCommentUpdateArtbox';  
11 -  
12 - public function execute($user, $item, $params)  
13 - {  
14 - return false;  
15 - }  
16 -  
17 - }  
18 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/resources/artbox_comment.css 0 → 100644
common/modules/comment/resources/artbox_comment.js 0 → 100644
  1 +/**
  2 + * Artbox comment plugin
  3 + */
  4 +(function($)
  5 +{
  6 +
  7 + $.fn.artbox_comment = function(method)
  8 + {
  9 + if(methods[method])
  10 + {
  11 + return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  12 + } else if(typeof method === 'object' || !method)
  13 + {
  14 + return methods.init.apply(this, arguments);
  15 + } else
  16 + {
  17 + $.error('Method ' + method + ' does not exist on jQuery.comment');
  18 + return false;
  19 + }
  20 + };
  21 +
  22 + // Default settings
  23 + var defaults = {
  24 + formContainerSelector : '.artbox_form_container',
  25 + formSelector : '#artbox-comment-form',
  26 + listContainerSelector : '.artbox_list_container',
  27 + listSelector : '#artbox-comment-list',
  28 + itemContainerSelector : '.artbox_item_container',
  29 + itemInfoSelector : '.artbox_item_info',
  30 + itemToolsSelector : '.artbox_item_tools',
  31 + itemReplySelector : '.artbox_item_reply',
  32 + childrenContainerSelector : '.artbox_children_container',
  33 + childContainerSelector : '.artbox_child_container',
  34 + childInfoSelector : '.artbox_child_info',
  35 + childToolsSelector : '.artbox_child_tools',
  36 + childReplySelector : '.artbox_child_reply',
  37 + replyContainerSelector : '.artbox_comment_reply_container',
  38 + widgetContainerSelector : '.artbox_comment_container'
  39 + };
  40 +
  41 + // Methods
  42 + var methods = {
  43 + init : function(options)
  44 + {
  45 + return this.each(
  46 + function()
  47 + {
  48 + var $commentForm = $(this);
  49 + if($commentForm.data('artbox_comment'))
  50 + {
  51 + return;
  52 + }
  53 + var settings = $.extend({}, defaults, options || {});
  54 + $commentForm.data('artbox_comment', settings);
  55 + //Add events
  56 + var eventParams = {commentForm : $commentForm};
  57 + $commentForm.on('beforeSubmit.artbox_comment', eventParams, beforeSubmitForm);
  58 + $(settings.listSelector).on('beforeSubmit.artbox_comment', settings.formSelector + '-reply', eventParams, reply);
  59 + $(settings.listSelector).on('click.artbox_comment', settings.itemToolsSelector + ' [data-action="reply"]', eventParams, replyInit);
  60 + $(settings.listSelector).on('click.artbox_comment', settings.itemToolsSelector + ' [data-action="reply-cancel"]', eventParams, replyCancel);
  61 + $(settings.listSelector).on('click.artbox_comment', settings.itemToolsSelector + ' [data-action="delete"]', eventParams, deleteComment);
  62 + $(settings.listSelector).on('click.artbox_comment', settings.itemToolsSelector + ' [data-action="like"]', eventParams, like);
  63 + $(settings.listSelector).on('click.artbox_comment', settings.itemToolsSelector + ' [data-action="dislike"]', eventParams, dislike);
  64 + $(settings.listSelector).on('click.artbox_comment', settings.childToolsSelector + ' [data-action="reply"]', eventParams, replyChildInit);
  65 + $(settings.listSelector).on('click.artbox_comment', settings.childToolsSelector + ' [data-action="reply-cancel"]', eventParams, replyCancel);
  66 + $(settings.listSelector).on('click.artbox_comment', settings.childToolsSelector + ' [data-action="delete"]', eventParams, deleteChild);
  67 + $(settings.listSelector).on('click.artbox_comment', settings.childToolsSelector + ' [data-action="like"]', eventParams, likeChild);
  68 + $(settings.listSelector).on('click.artbox_comment', settings.childToolsSelector + ' [data-action="dislike"]', eventParams, dislikeChild);
  69 + }
  70 + );
  71 + },
  72 + data : function()
  73 + {
  74 + return this.data('artbox_comment');
  75 + }
  76 + };
  77 +
  78 + /**
  79 + * Submit reply form
  80 + *
  81 + * @param event
  82 + */
  83 + function reply(event)
  84 + {
  85 + /**
  86 + * @todo Implement
  87 + */
  88 + event.preventDefault();
  89 + var $replyForm = $(this);
  90 + var $commentForm = event.data.commentForm;
  91 + settings = $commentForm.data('artbox_comment');
  92 + $replyForm.find(':submit').prop('disabled', true).text('Loading...');
  93 + $.post(
  94 + $replyForm.attr("action"), $replyForm.serialize(), function(data)
  95 + {
  96 + if(data.status == 'success')
  97 + {
  98 + hideForm($commentForm);
  99 + $(settings.listSelector).load(
  100 + ' ' + settings.listSelector, function(data)
  101 + {
  102 + $replyForm.find(':submit').prop('disabled', false).text('Submit');
  103 + $replyForm.trigger("reset");
  104 + }
  105 + );
  106 + }
  107 + else
  108 + {
  109 + if(data.hasOwnProperty('errors'))
  110 + {
  111 + $replyForm.yiiActiveForm('updateMessages', data.errors, true);
  112 + } else
  113 + {
  114 + $replyForm.yiiActiveForm('updateAttribute', 'commentmodel-text-reply', [data.message]);
  115 + }
  116 + $replyForm.find(':submit').prop('disabled', false).text('Submit');
  117 + }
  118 + }
  119 + );
  120 + return false;
  121 + }
  122 +
  123 + /**
  124 + * Submit comment form
  125 + *
  126 + * @param event
  127 + */
  128 + function beforeSubmitForm(event)
  129 + {
  130 + event.preventDefault();
  131 + var $commentForm = $(this), settings = $commentForm.data('artbox_comment');
  132 + $commentForm.find(':submit').prop('disabled', true).text('Loading...');
  133 + $.post(
  134 + $commentForm.attr("action"), $commentForm.serialize(), function(data)
  135 + {
  136 + if(data.status == 'success')
  137 + {
  138 + hideForm($commentForm);
  139 + $(settings.listSelector).load(
  140 + ' ' + settings.listSelector, function(data)
  141 + {
  142 + $commentForm.find(':submit').prop('disabled', false).text('Submit');
  143 + $commentForm.trigger("reset");
  144 + }
  145 + );
  146 + }
  147 + else
  148 + {
  149 + if(data.hasOwnProperty('errors'))
  150 + {
  151 + $commentForm.yiiActiveForm('updateMessages', data.errors, true);
  152 + } else
  153 + {
  154 + $commentForm.yiiActiveForm('updateAttribute', 'commentmodel-text', [data.message]);
  155 + }
  156 + $commentForm.find(':submit').prop('disabled', false).text('Submit');
  157 + }
  158 + }
  159 + );
  160 + return false;
  161 + }
  162 +
  163 + /**
  164 + * Init reply form
  165 + *
  166 + * @param event
  167 + */
  168 + function replyInit(event)
  169 + {
  170 + event.preventDefault();
  171 + var data = event.data.commentForm.data('artbox_comment');
  172 + var form = $(data.formSelector + '-reply');
  173 + var button = this;
  174 + var item = $(button).parents(data.itemContainerSelector);
  175 + var item_id = $(item).data('key');
  176 + $(form).find('#commentmodel-artbox_comment_pid-reply').val(item_id);
  177 + $(item).find(data.itemReplySelector).append(form);
  178 + }
  179 +
  180 + /**
  181 + * Init reply form
  182 + *
  183 + * @param event
  184 + */
  185 + function replyCancel(event)
  186 + {
  187 + event.preventDefault();
  188 + hideForm(event.data.commentForm);
  189 + }
  190 +
  191 + /**
  192 + * Init reply form
  193 + *
  194 + * @param event
  195 + */
  196 + function deleteComment(event)
  197 + {
  198 + event.preventDefault();
  199 + var data = event.data.commentForm.data('artbox_comment');
  200 + hideForm(event.data.commentForm);
  201 + var button = this;
  202 + var item = $(button).parents(data.itemContainerSelector);
  203 + $.post($(button).data('url'), function(data) {
  204 + if(data.status == 'success')
  205 + {
  206 + $(item).text(data.message);
  207 + }
  208 + else
  209 + {
  210 + console.log(data.message);
  211 + }
  212 + });
  213 + }
  214 +
  215 + /**
  216 + * Init reply form
  217 + *
  218 + * @param event
  219 + */
  220 + function like(event)
  221 + {
  222 + event.preventDefault();
  223 + /**
  224 + * @todo Implement
  225 + */
  226 + }
  227 +
  228 + /**
  229 + * Init reply form
  230 + *
  231 + * @param event
  232 + */
  233 + function dislike(event)
  234 + {
  235 + event.preventDefault();
  236 + /**
  237 + * @todo Implement
  238 + */
  239 + }
  240 +
  241 + /**
  242 + * Init reply form
  243 + *
  244 + * @param event
  245 + */
  246 + function replyChildInit(event)
  247 + {
  248 + event.preventDefault();
  249 + var data = event.data.commentForm.data('artbox_comment');
  250 + var form = $(data.formSelector + '-reply');
  251 + var button = this;
  252 + var item = $(button).parents(data.childContainerSelector);
  253 + var item_id = $(item).data('key');
  254 + $(form).find('#commentmodel-artbox_comment_pid-reply').val(item_id);
  255 + $(item).find(data.childReplySelector).append(form);
  256 + }
  257 +
  258 + /**
  259 + * Init reply form
  260 + *
  261 + * @param event
  262 + */
  263 + function deleteChild(event)
  264 + {
  265 + event.preventDefault();
  266 + var data = event.data.commentForm.data('artbox_comment');
  267 + hideForm(event.data.commentForm);
  268 + var button = this;
  269 + var item = $(button).parents(data.childContainerSelector);
  270 + $.post($(button).data('url'), function(data) {
  271 + if(data.status == 'success')
  272 + {
  273 + $(item).text(data.message);
  274 + }
  275 + else
  276 + {
  277 + console.log(data.message);
  278 + }
  279 + });
  280 + }
  281 +
  282 + /**
  283 + * Init reply form
  284 + *
  285 + * @param event
  286 + */
  287 + function likeChild(event)
  288 + {
  289 + event.preventDefault();
  290 + /**
  291 + * @todo Implement
  292 + */
  293 + }
  294 +
  295 + /**
  296 + * Init reply form
  297 + *
  298 + * @param event
  299 + */
  300 + function dislikeChild(event)
  301 + {
  302 + event.preventDefault();
  303 + /**
  304 + * @todo Implement
  305 + */
  306 + }
  307 +
  308 + function hideForm(commentForm)
  309 + {
  310 + var data = $(commentForm).data('artbox_comment');
  311 + var form = $(data.formSelector+'-reply');
  312 + $(form).parents(data.widgetContainerSelector).find(data.replyContainerSelector).append(form);
  313 + form.trigger('reset');
  314 + }
  315 +
  316 +})(window.jQuery);
common/modules/comment/resources/comment.css deleted
1 -.artbox_comment_reply_author, .artbox_comment_update_reply {  
2 - position: relative;  
3 - width: 25%;  
4 -}  
5 -.artbox_comment_update_reply {  
6 - width: 25%;  
7 - float: none;  
8 -}  
9 -.artbox_comment_reply_author:after, .artbox_comment_update_reply:after {  
10 - content: '';  
11 - background-image: url('delete-ico.png');  
12 - display: block;  
13 - position: absolute;  
14 - right: -13px;  
15 - width: 13px;  
16 - height: 13px;  
17 - top: 0;  
18 - cursor: pointer;  
19 -}  
20 -.removeable {  
21 - color: #a94442;  
22 - background-color: #f2dede;  
23 - border-color: #ebccd1;  
24 - border-radius: 4px;  
25 - padding: 15px;  
26 - padding-right: 35px;  
27 - position: relative;  
28 -}  
29 -.removeable::after {  
30 - content: ' ';  
31 - display: block;  
32 - position: absolute;  
33 - right: 5px;  
34 - top: 5px;  
35 - width: 15px;  
36 - height: 15px;  
37 - background: url('delete-ico.png');  
38 - background-size: cover;  
39 - cursor: pointer;  
40 -}  
41 -  
42 -/* For default styling */  
43 -.new-portf-comments-wr {  
44 - margin-top: 28px  
45 -}  
46 -  
47 -.new-portf-comm-count {  
48 - font-size: 18px  
49 -}  
50 -  
51 -.input-blocks-comm {  
52 - width: 230px;  
53 - float: left;  
54 - margin-left: 34px;  
55 - position: relative;  
56 -}  
57 -  
58 -.input-blocks-comm:first-child {  
59 - margin-left: 0  
60 -}  
61 -  
62 -.new-portf-add-comm {  
63 - padding: 24px 20px 30px 20px;  
64 - box-sizing: border-box;  
65 - margin-top: 10px;  
66 - background: #f1f1f1;  
67 -}  
68 -  
69 -.input-blocks-comm.area-comm {  
70 - width: 680px;  
71 - margin-left: 0;  
72 - margin-top: 10px;  
73 - position: relative;  
74 -}  
75 -  
76 -.tender_questions_ .input-blocks-comm.area-comm {  
77 - margin-top: 15px;  
78 -}  
79 -  
80 -.custom-input-4 {  
81 - width: 230px;  
82 - height: 32px;  
83 - border: 0;  
84 - box-sizing: border-box;  
85 - outline: none;  
86 - color: #333;  
87 - font-size: 13px;  
88 - line-height: 29px;  
89 - padding-left: 8px;  
90 - margin-top: 5px;  
91 -}  
92 -  
93 -.custom-area-4 {  
94 - min-height: 142px;  
95 - max-height: 142px;  
96 - resize: none;  
97 - width: 100%;  
98 - max-width: 100%;  
99 - border: 0;  
100 - box-sizing: border-box;  
101 - outline: none;  
102 - color: #636363;  
103 - font-size: 13px;  
104 - padding-left: 8px;  
105 - padding-top: 8px;  
106 - margin-top: 5px;  
107 -}  
108 -  
109 -.input-blocks-comm label {  
110 - font-size: 13px;  
111 - color: #454545;  
112 - font-weight: 700;  
113 -}  
114 -  
115 -.custom-area-4:focus, .custom-input-4:focus {  
116 - box-shadow: 1px 2px 2px 0px rgba(215, 215, 215, 0.75) inset;  
117 - transition: 0.1s;  
118 - outline: none  
119 -}  
120 -  
121 -.input-blocks-comm-button {  
122 - text-align: right;  
123 - margin-top: 16px  
124 -}  
125 -  
126 -.input-blocks-comm-button button {  
127 - background: #0072bc;  
128 - color: #fff;  
129 - font-size: 13px;  
130 - height: 27px;  
131 - outline: none;  
132 - cursor: pointer;  
133 - border-radius: 4px;  
134 - padding: 0 17px;  
135 - border: 1px solid #0072bc;  
136 -}  
137 -  
138 -.input-blocks-comm-button button:hover {  
139 - background: none;  
140 - color: #0072bc;  
141 - transition: 0.2s;  
142 -}  
143 -  
144 -.input-blocks-comm-button button:focus, .input-blocks-comm-button button:active {  
145 - background: #035b94;  
146 - color: #fff  
147 -}  
148 -  
149 -.new-portf-comm-read-wr {  
150 - margin-top: 29px  
151 -}  
152 -  
153 -.new-portf-comm-read {  
154 - width: 100%;  
155 - float: left;  
156 - padding-bottom: 13px;  
157 - border-bottom: 1px solid #dcdcdc;  
158 - margin-top: 30px;  
159 -}  
160 -  
161 -.new-portf-comm-read:first-child {  
162 - /*margin-top: 0*/  
163 -}  
164 -  
165 -.new-prof-wrapper-read {  
166 - float: left;  
167 - margin-left: 13px;  
168 -}  
169 -  
170 -.new-portf-comm-read-title a {  
171 - font-size: 13px;  
172 - text-decoration: none;  
173 - color: #0072bc;  
174 -}  
175 -  
176 -.new-portf-comm-read-title a:hover {  
177 - text-decoration: underline  
178 -}  
179 -  
180 -.new-portf-comm-read-title {  
181 - margin-top: -5px;  
182 -}  
183 -  
184 -.new-portf-comm-read-rating {  
185 - height: 30px;  
186 - box-sizing: border-box;  
187 - padding-top: 1px  
188 -}  
189 -  
190 -.new-portf-comm-read-rating .rating {  
191 - margin-top: 8px  
192 -}  
193 -  
194 -.new-portf-comm-read-rating .vote-stars, .new-portf-comm-read-rating .vote-active, .new-portfolio-rating .vote-stars, .new-portfolio-rating .vote-active {  
195 - cursor: pointer !important;  
196 -}  
197 -  
198 -.new-portf-answer {  
199 - width: 100%;  
200 - float: left;  
201 - font-size: 13px;  
202 - line-height: 20px;  
203 - margin-top: 10px;  
204 -}  
205 -  
206 -.new-portf-answer p {  
207 - width: 100%;  
208 - float: left;  
209 - font-size: 13px;  
210 - line-height: 20px;  
211 -}  
212 -  
213 -.new-portf-answer p:first-child {  
214 - margin-top: 0  
215 -}  
216 -.style {  
217 - width: 100%;  
218 - float: left;  
219 -}  
220 -  
221 -/***proektant_comments***/  
222 -ul.proektant-comments {  
223 - margin-top: 15px;  
224 - padding-left: 0;  
225 -}  
226 -  
227 -.proektant-comments li {  
228 - width: 100%;  
229 - float: left;  
230 - list-style: none;  
231 - border-bottom: 1px solid #dcdcdc;  
232 - padding-bottom: 20px;  
233 - margin-top: 27px;  
234 -}  
235 -  
236 -.proektant-comments .pagination li {  
237 - width: auto;  
238 - margin-top: 0;  
239 - float: none;  
240 - border-bottom: none;  
241 -}  
242 -  
243 -.proektant-comments li:first-child {  
244 - margin-top: 0  
245 -}  
246 -  
247 -.proektant-comments li > div {  
248 - float: left;  
249 - width: 100%;  
250 - font-size: 13px  
251 -}  
252 -  
253 -.comments-name {  
254 - font-weight: 700  
255 -}  
256 -  
257 -.comments-project-link a {  
258 - color: #0073bc;  
259 - text-decoration: underline;  
260 -  
261 -}  
262 -  
263 -.comments-status span {  
264 - color: #0072bc;  
265 - border-bottom: 1px dashed #0072bc;  
266 -}  
267 -  
268 -.comments-status, .comments-date, .proektant-comments .rating {  
269 - margin-top: 3px  
270 -}  
271 -  
272 -.comments-content {  
273 - line-height: 18px;  
274 - margin-top: 11px  
275 -}  
276 -  
277 -.comments-project-link {  
278 - margin-top: 19px  
279 -}  
common/modules/comment/resources/comment.js deleted
1 -$(function() {  
2 -  
3 - function addRemoveBlocks(data)  
4 - {  
5 - $('#overlay, .succses_comm').remove();  
6 - $('body').append('<div id="overlay" style="top:0; left:0;"></div>').append('<div class="succses_comm"><div class="closed-form"></div><div class="succses_comm-txt">'+data.text+'</div></div>');  
7 - $('#overlay').fadeIn(  
8 - 400, function()  
9 - {  
10 - $('.succses_comm').css({display : 'block'}).animate({opacity : 1, top : '50%'}, 200);  
11 - }  
12 - );  
13 - function closeSuccsescomm() {  
14 - $('.succses_comm')  
15 - .animate(  
16 - {opacity : 0, top : '30%'}, 200, function()  
17 - {  
18 - $(this).css('display', 'none')  
19 - $('#overlay').fadeOut(  
20 - 400, function()  
21 - {  
22 - $('#overlay, .succses_comm').remove()  
23 - }  
24 - )  
25 - }  
26 - )  
27 - }  
28 - $('body').on('click', '.closed-form, #overlay', function() {  
29 - closeSuccsescomm()  
30 - }  
31 - );  
32 -  
33 - setTimeout(closeSuccsescomm, 4000)  
34 - }  
35 -  
36 - $(document).on('click', '.artbox_comment_container .removeable', function(e) {  
37 - e.preventDefault();  
38 - $(this).parent().remove();  
39 -// var container = $(this).parents('.artbox_comment_container');  
40 -// $(container).remove();  
41 - });  
42 -  
43 - $(document).on(  
44 - 'click', '.artbox_comment_delete', function(e)  
45 - {  
46 - e.preventDefault();  
47 - var container = $(this).parents('.artbox_comment_container');  
48 - var comment_id = $(container).data('key');  
49 - var form_name = $(container).data('form');  
50 - if(confirm("Уверены, что хотите удалить комментарий?"))  
51 - {  
52 - $.post(  
53 - '/artbox-comment/delete', {  
54 - Comment : {  
55 - comment_id : comment_id  
56 - }  
57 - }, function(data, textStatus, jqXHR)  
58 - {  
59 - if(!data.error)  
60 - {  
61 - {  
62 - $(container).remove();  
63 - addRemoveBlocks(data)  
64 - // $(container).append('<p class="removeable">' + data.text + '</p>');  
65 - }  
66 - } else  
67 - {  
68 - $(container).prepend('<p class="removeable error_message">' + data.error + '</p>')  
69 - }  
70 - }  
71 - );  
72 - }  
73 - }  
74 - );  
75 -  
76 - $(document).on(  
77 - 'click', '.artbox_comment_reply', function(e)  
78 - {  
79 - e.preventDefault();  
80 - var container = $(this).parents('.artbox_comment_container').first();  
81 - var comment_id = $(container).data('key');  
82 - var form_name = $(container).data('form');  
83 - var author = $(container).find('.artbox_comment_author').first().text();  
84 - var comment_form = $(container).parents('.artbox_comment_widget').find('.artbox_comment_form').first();  
85 - var offset = $(comment_form).offset();  
86 - var reply_block = $(comment_form).find('.artbox_comment_reply_block').first();  
87 - $(reply_block).empty();  
88 - $(reply_block).append('<input type="hidden" name="' + form_name + '[comment_pid]" value="' + comment_id + '">');  
89 - $(reply_block).append('<p class="artbox_comment_reply_author">' + author + '</p>');  
90 - $('html, body').animate(  
91 - {  
92 - scrollTop : offset.top - 50,  
93 - }  
94 - );  
95 - }  
96 - );  
97 -  
98 - $(document).on(  
99 - 'click', '.artbox_comment_reply_author', function()  
100 - {  
101 - $(this).parents('.artbox_comment_reply_block').first().empty();  
102 - }  
103 - );  
104 -  
105 - $(document).on(  
106 - 'click', '.artbox_comment_update', function(e)  
107 - {  
108 - e.preventDefault();  
109 - var container = $(this).parents('.artbox_comment_container').first();  
110 - var comment_id = $(container).data('key');  
111 - var form_name = $(container).data('form');  
112 - var object = {};  
113 - object[form_name] = {comment_id : comment_id};  
114 - $.post(  
115 - '/artbox-comment/form', object, function(data, textStatus, jqXHR)  
116 - {  
117 - $(container).empty();  
118 - $(container).append(data.result.form);  
119 - }  
120 - );  
121 - }  
122 - );  
123 -  
124 - // @TODO What is this  
125 - $(document).on(  
126 - 'click', '.artbox_comment_update_reply', function()  
127 - {  
128 - $(this).remove();  
129 - }  
130 - );  
131 -  
132 - $(document).on(  
133 - 'click', '.artbox_comment_update_submit', function(e)  
134 - {  
135 - e.preventDefault();  
136 - var container = $(this).parents('.artbox_comment_container').first();  
137 - $.post(  
138 - '/artbox-comment/update', $(container).find('form').serialize(), function(data)  
139 - {  
140 - $(container).empty();  
141 - if(!data.error)  
142 - {  
143 - $(container).append('<p>'+data.result.text+'</p>');  
144 - $(container).append(data.result.html);  
145 - } else {  
146 - $(container).append(data.form);  
147 - }  
148 - }  
149 - )  
150 - }  
151 - );  
152 -  
153 - $(document).on(  
154 - 'click', '.artbox_comment_update_answer', function(e)  
155 - {  
156 - e.preventDefault();  
157 - var container = $(this).parents('.artbox_comment_container').first();  
158 - var comment_id = $(container).data('key');  
159 - var form_name = $(container).data('form');  
160 - var object = {};  
161 - object[form_name] = {comment_id : comment_id};  
162 - $.post(  
163 - '/artbox-comment/form-answer', object, function(data, textStatus, jqXHR)  
164 - {  
165 - $(container).empty();  
166 - $(container).append(data.result.form);  
167 - }  
168 - );  
169 - }  
170 - );  
171 -  
172 - $(document).on(  
173 - 'click', '.artbox_comment_update_answer_submit', function(e)  
174 - {  
175 - e.preventDefault();  
176 - var container = $(this).parents('.artbox_comment_container').first();  
177 - $.post(  
178 - '/artbox-comment/update-answer', $(container).find('form').serialize(), function(data)  
179 - {  
180 - $(container).empty();  
181 - if(!data.error)  
182 - {  
183 - $(container).append('<p>'+data.result.text+'</p>');  
184 - $(container).append(data.result.html);  
185 - } else {  
186 - $(container).append(data.form);  
187 - }  
188 - }  
189 - )  
190 - }  
191 - );  
192 -  
193 - $(document).on(  
194 - 'click', '.artbox_comment_delete_answer', function(e)  
195 - {  
196 - e.preventDefault();  
197 - var container = $(this).parents('.artbox_comment_container');  
198 - var comment_id = $(container).data('key');  
199 - var form_name = $(container).data('form');  
200 - if(confirm("Уверены, что хотите удалить вопрос?"))  
201 - {  
202 - $.post(  
203 - '/artbox-comment/delete-answer', {  
204 - CommentProjectAnswer : {  
205 - comment_id : comment_id  
206 - }  
207 - }, function(data, textStatus, jqXHR)  
208 - {  
209 - if(!data.error)  
210 - {  
211 - $(container).remove();  
212 - addRemoveBlocks(data)  
213 - } else  
214 - {  
215 - $(container).prepend('<p class="removeable error_message">' + data.error + '</p>')  
216 - }  
217 - }  
218 - );  
219 - }  
220 - }  
221 - );  
222 -  
223 - $(document).on('click', '.artbox_comment_reply_answer', function(e) {  
224 - e.preventDefault();  
225 - var widget = $(this).parents('.artbox_comment_widget');  
226 - var form = $(widget).find('.artbox_comment_form');  
227 - $(form).removeClass('hidden');  
228 - $(widget).find('.artbox_comment_answer_label').text('Ответ');  
229 - });  
230 -  
231 - $(document).on('click', '.artbox_comment_reply_answer_block', function(e) {  
232 - var form = $(this).parents('.artbox_comment_form');  
233 - $(form).addClass('hidden');  
234 - $(form).find('.artbox_comment_answer_label').text('Вопрос');  
235 - });  
236 -  
237 -});  
common/modules/comment/resources/delete-ico.png deleted

368 Bytes

common/modules/comment/todo 0 → 100644
  1 +Сделать:
  2 +1. Реализовать действия.
  3 +2. Добавить RBAC.
  4 +3. Добавить рейтинг.
  5 +4. Добавить модерацию.
  6 +5. Добавить соц сети.
  7 +6. Добавить "пожаловаться".
  8 +7. Добавить установщик.
  9 +8. Добавить PJAX.
  10 +9. Добавить приколы.
  11 +10. Добавить возможность бана.
  12 +11. Предусмотреть удаление пользователя (что делать с его комментариями).
  13 +12. Добавить базовую верстку bootstrap / nonbootstrap.
  14 +13. Добавить возможность использования кастомной модели комментариев.
  15 +14. Реализовать мультиязычность.
  16 +15. Добавить возможность изменения макета (layout) функцией (Вместо "{form}{list}" добавить возможность function($parts, $view ...)).
  17 +16. Добавить сортировку.
  18 +17. Сделать навигацию по ссылкам related как на Youtube.
  19 +
  20 +Действия:
  21 +1. Добавить
  22 +2. Редактировать
  23 +3. Ответить
  24 +4. Like / dislike
  25 +5. Удалить
  26 +
  27 +Таблица (artbox_comment):
  28 +artbox_comment_id primary_key
  29 +text text
  30 +user_id int foreign key
  31 +username string
  32 +email string
  33 +date_add int notNull
  34 +date_update int notNull
  35 +date_delete int notNull
  36 +status int notNull default(1)
  37 +comment_pid int foreign_key
  38 +related_id int foreign key
  39 +ip string notNull
  40 +info text
  41 +
  42 +Таблица (artbox_comment_like):
  43 +artbox_comment_like_id primary_key
  44 +artbox_comment_id int foreign key
  45 +user_id int foreign key
  46 +date_add int notNull
  47 +is_like int notNull default(1)
  48 +
  49 +Приколы:
  50 +1. Рандомная генерация изображений
  51 +2. Смайлы
0 \ No newline at end of file 52 \ No newline at end of file
common/modules/comment/views/artbox_comment_form.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\CommentModel;
  3 + use common\modules\comment\models\RatingModel;
  4 + use yii\base\Model;
  5 + use yii\helpers\Html;
  6 + use yii\helpers\Url;
  7 + use yii\web\View;
  8 + use yii\widgets\ActiveForm;
  9 +
  10 + /**
  11 + * @var CommentModel $comment_model
  12 + * @var array $form_params
  13 + * @var Model $model
  14 + * @var string $formId
  15 + * @var View $this
  16 + * @var RatingModel|NULL $rating_model
  17 + */
  18 + $form = ActiveForm::begin([
  19 + 'id' => $formId,
  20 + 'action' => Url::to([
  21 + 'artbox-comment/default/create',
  22 + 'entity' => $comment_model->encryptedEntity,
  23 + ]),
  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();
0 \ No newline at end of file 45 \ No newline at end of file
common/modules/comment/views/artbox_comment_item.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\CommentModel;
  3 + use yii\helpers\Url;
  4 + use yii\widgets\ListView;
  5 +
  6 + /**
  7 + * @var CommentModel $model
  8 + * @var mixed $key
  9 + * @var int $index
  10 + * @var ListView $widget
  11 + */
  12 +?>
  13 +<div class="artbox_item_info">
  14 + <div>
  15 + <span>Пользователь:</span>
  16 + <span>
  17 + <?php
  18 + if(!empty( $model->user )) {
  19 + echo $model->user->username;
  20 + } else {
  21 + echo $model->username . ' (' . $model->email . ')';
  22 + }
  23 + ?>
  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>
  47 + <?php
  48 + echo $model->text;
  49 + ?>
  50 + </span>
  51 + </div>
  52 +</div>
  53 +<div class="artbox_item_tools">
  54 + <ul>
  55 + <?php
  56 + if(!\Yii::$app->user->isGuest) {
  57 + ?>
  58 + <li><a href="" data-action="reply">Ответить</a></li>
  59 + <?php
  60 + }
  61 + if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $model->user_id) {
  62 + ?>
  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>
  67 + <?php
  68 + }
  69 + // Like / dislike to be done
  70 + /*
  71 + ?>
  72 + <li><a href="" data-action="like" data-url="<?php echo Url::to([
  73 + 'artbox-comment/default/like',
  74 + 'id' => $model->artbox_comment_id,
  75 + ]); ?>">Like</a></li>
  76 + <li><a href="" data-action="dislike" data-url="<?php echo Url::to([
  77 + 'artbox-comment/default/dislike',
  78 + 'id' => $model->artbox_comment_id,
  79 + ]); ?>">Dislike</a></li>
  80 + <?php
  81 + */
  82 + ?>
  83 + </ul>
  84 + <div class="artbox_item_reply"></div>
  85 +</div>
  86 +<div class="artbox_children_container">
  87 + <?php
  88 + if(!empty( $model->children )) {
  89 + foreach($model->children as $index => $child) {
  90 + ?>
  91 + <div class="artbox_child_container">
  92 + <div class="artbox_child_info">
  93 + <div>
  94 + <span>Пользователь:</span>
  95 + <span>
  96 + <?php
  97 + if(!empty( $child->user )) {
  98 + echo $child->user->username;
  99 + } else {
  100 + echo $child->username . ' (' . $child->email . ')';
  101 + }
  102 + ?>
  103 + </span>
  104 + </div>
  105 + <div>
  106 + <span>Дата: </span>
  107 + <span>
  108 + <?php
  109 + echo date('d.m.Y', $child->date_add);
  110 + ?>
  111 + </span>
  112 + </div>
  113 + <div>
  114 + <span>Сообщение: </span>
  115 + <span>
  116 + <?php
  117 + echo $child->text;
  118 + ?>
  119 + </span>
  120 + </div>
  121 + </div>
  122 + <div class="artbox_child_tools">
  123 + <ul>
  124 + <?php
  125 + if(!\Yii::$app->user->isGuest) {
  126 + ?>
  127 + <li><a href="" data-action="reply">Ответить</a></li>
  128 + <?php
  129 + }
  130 + if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $child->user_id) {
  131 + ?>
  132 + <li>
  133 + <a href="" data-action="delete" data-url="<?php echo Url::to([
  134 + 'artbox-comment/default/delete',
  135 + 'id' => $child->artbox_comment_id,
  136 + ]); ?>">Удалить</a></li>
  137 + <?php
  138 + }
  139 + /* Like /dislike to be done
  140 + ?>
  141 + <li><a href="" data-action="like" data-url="<?php echo Url::to([
  142 + 'artbox-comment/default/like',
  143 + 'id' => $child->artbox_comment_id,
  144 + ]); ?>">Like</a></li>
  145 + <li><a href="" data-action="dislike" data-url="<?php echo Url::to([
  146 + 'artbox-comment/default/dislike',
  147 + 'id' => $child->artbox_comment_id,
  148 + ]); ?>">Dislike</a></li>
  149 + <?php
  150 + */
  151 + ?>
  152 + </ul>
  153 + <div class="artbox_child_reply"></div>
  154 + </div>
  155 + </div>
  156 + <?php
  157 + }
  158 + }
  159 + ?>
  160 +</div>
  161 +
common/modules/comment/views/artbox_comment_list.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\Comment;
  3 + use yii\base\Model;
  4 + use yii\data\ActiveDataProvider;
  5 + use yii\helpers\Html;
  6 + use yii\web\View;
  7 + use yii\widgets\ListView;
  8 + use yii\widgets\Pjax;
  9 +
  10 + /**
  11 + * @var Comment $comment_model
  12 + * @var array $list_params
  13 + * @var array $item_options
  14 + * @var string $item_view
  15 + * @var Model $model
  16 + * @var ActiveDataProvider $comments
  17 + * @var View $this
  18 + */
  19 + //Pjax::begin();
  20 + if(($success = \Yii::$app->session->getFlash('artbox_comment_success')) != null) {
  21 + echo Html::tag('p', $success);
  22 + }
  23 + echo ListView::widget([
  24 + 'dataProvider' => $comments,
  25 + 'itemOptions' => $item_options,
  26 + 'itemView' => $item_view,
  27 + ]);
  28 + //Pjax::end();
  29 +
0 \ No newline at end of file 30 \ No newline at end of file
common/modules/comment/views/artbox_comment_reply.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\CommentModel;
  3 + use yii\base\Model;
  4 + use yii\helpers\Html;
  5 + use yii\helpers\Url;
  6 + use yii\web\View;
  7 + use yii\widgets\ActiveForm;
  8 +
  9 + /**
  10 + * @var CommentModel $comment_model
  11 + * @var array $form_params
  12 + * @var Model $model
  13 + * @var string $formId
  14 + * @var View $this
  15 + */
  16 + $text_input_id = Html::getInputId($comment_model, 'text') . '-reply';
  17 + $artbox_comment_pid_input_id = Html::getInputId($comment_model, 'artbox_comment_pid') . '-reply';
  18 + $text_input_selectors = [
  19 + 'container' => '.field-' . $text_input_id,
  20 + 'input' => '#' . $text_input_id,
  21 + ];
  22 + $artbox_comment_pid_input_selectors = [
  23 + 'container' => '.field-' . $artbox_comment_pid_input_id,
  24 + 'input' => '#' . $artbox_comment_pid_input_id,
  25 + ];
  26 + $form = ActiveForm::begin([
  27 + 'id' => $formId . '-reply',
  28 + 'action' => Url::to([
  29 + 'artbox-comment/default/create',
  30 + 'entity' => $comment_model->encryptedEntity,
  31 + ]),
  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();
0 \ No newline at end of file 55 \ No newline at end of file
common/modules/comment/views/comment_form.php deleted
1 -<?php  
2 - /**  
3 - * @var \common\modules\comment\models\Comment $model  
4 - */  
5 - use yii\widgets\ActiveForm;  
6 -  
7 - $form = ActiveForm::begin();  
8 -  
9 -?>  
10 -<?php  
11 - echo $form->field($model, 'comment_id')  
12 - ->label(false)  
13 - ->hiddenInput();  
14 - if(!empty( $model->parent )) {  
15 - ?>  
16 - <div class="artbox_comment_update_reply">  
17 - <?php  
18 - echo "<span>";  
19 - if(!empty( $model->parent->author )) {  
20 - echo $model->parent->author->firstname . ' ' . $model->parent->author->lastname;  
21 - } else {  
22 - echo $model->parent->user_name;  
23 - }  
24 - echo "</span>";  
25 - echo $form->field($model, 'comment_pid')  
26 - ->label(false)  
27 - ->hiddenInput();  
28 - ?>  
29 - </div>  
30 - <?php  
31 - }  
32 - echo $form->field($model, 'text')  
33 - ->label(false)  
34 - ->textarea();  
35 -?>  
36 -<?php  
37 - $form->end();  
38 -?>  
39 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/views/manage/index.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\CommentModelSearch;
  3 + use yii\data\ActiveDataProvider;
  4 + use yii\grid\GridView;
  5 + use yii\helpers\Html;
  6 + use yii\widgets\Pjax;
  7 +
  8 + /**
  9 + * @var ActiveDataProvider $dataProvider
  10 + * @var CommentModelSearch $searchModel
  11 + * @var string $commentModel
  12 + */
  13 + $statuses = [
  14 + $searchModel::STATUS_ACTIVE => 'Активный',
  15 + $searchModel::STATUS_HIDDEN => 'Скрытый',
  16 + $searchModel::STATUS_DELETED => 'Удаленный',
  17 + ];
  18 + Pjax::begin();
  19 + if(($success = \Yii::$app->session->getFlash('artbox_comment_success')) != null) {
  20 + echo Html::tag('p', $success);
  21 + }
  22 + echo GridView::widget([
  23 + 'dataProvider' => $dataProvider,
  24 + 'filterModel' => $searchModel,
  25 + 'columns' => [
  26 + [
  27 + 'class' => 'yii\grid\ActionColumn',
  28 + 'template' => '{update} {delete}',
  29 + ],
  30 + [
  31 + 'attribute' => 'artbox_comment_id',
  32 + 'label' => 'Идентификатор',
  33 + ],
  34 + [
  35 + 'attribute' => 'date_add',
  36 + 'format' => ['date', 'php:d.m.Y'],
  37 + 'filter' => false,
  38 + ],
  39 + 'text:text',
  40 + [
  41 + 'attribute' => 'user_id',
  42 + 'value' => function($model) {
  43 + if(!empty($model->user_id)) {
  44 + return $model->user->username . ' (id:' . $model->user->id . ')';
  45 + } else {
  46 + return $model->username.' '.$model->email.' (Гость)';
  47 + }
  48 + }
  49 + ],
  50 + [
  51 + 'attribute' => 'status',
  52 + 'filter' => $statuses,
  53 + 'value' => function($model) use($statuses) {
  54 + return $statuses[$model->status];
  55 + }
  56 + ],
  57 + [
  58 + 'attribute' => 'rating_value',
  59 + 'label' => $searchModel->getAttributeLabel('rating_value'),
  60 + 'value' => function($model) {
  61 + if(!empty($model->rating)) {
  62 + return $model->rating->value;
  63 + }
  64 + return NULL;
  65 + }
  66 + ],
  67 + 'entity',
  68 + 'entity_id',
  69 + [
  70 + 'attribute' => 'children_count',
  71 + 'label' => $searchModel->getAttributeLabel('children_count'),
  72 + 'value' => function($model) {
  73 + return count($model->children);
  74 + }
  75 + ],
  76 + ],
  77 + ]);
  78 + Pjax::end();
0 \ No newline at end of file 79 \ No newline at end of file
common/modules/comment/views/manage/update.php 0 → 100644
  1 +<?php
  2 + use common\modules\comment\models\CommentModel;
  3 + use yii\helpers\Html;
  4 + use yii\widgets\ActiveForm;
  5 +
  6 + /**
  7 + * @var CommentModel $model
  8 + */
  9 + $statuses = [
  10 + $model::STATUS_ACTIVE => 'Активный',
  11 + $model::STATUS_HIDDEN => 'Скрытый',
  12 + $model::STATUS_DELETED => 'Удаленный',
  13 + ];
  14 + $form = ActiveForm::begin();
  15 + echo $form->field($model, 'text')->textarea();
  16 + echo $form->field($model, 'status')->dropDownList($statuses);
  17 + echo Html::submitButton('Обновить');
  18 + $form->end();
0 \ No newline at end of file 19 \ No newline at end of file
common/modules/comment/widgets/CommentWidget.php
1 <?php 1 <?php
  2 +
2 namespace common\modules\comment\widgets; 3 namespace common\modules\comment\widgets;
3 -  
4 - use yii\data\Sort;  
5 - use \yii\helpers\ArrayHelper;  
6 - use \yii\helpers\Html;  
7 -  
8 - class CommentWidget extends \yii\base\Widget 4 +
  5 + use common\modules\comment\assets\CommentAsset;
  6 + use common\modules\comment\models\interfaces\CommentInterface;
  7 + use common\modules\comment\models\RatingModel;
  8 + use common\modules\comment\Module;
  9 + use Yii;
  10 + use yii\base\InvalidConfigException;
  11 + use yii\base\Widget;
  12 + use yii\data\ActiveDataProvider;
  13 + use yii\helpers\ArrayHelper;
  14 + use yii\helpers\Html;
  15 + use yii\helpers\Json;
  16 +
  17 + /**
  18 + * Class CommentWidget
  19 + * @property \yii\base\Model $model Model, to which comment attached
  20 + * @package common\modules\comment\widgets
  21 + */
  22 + class CommentWidget extends Widget
9 { 23 {
10 - 24 +
11 /** 25 /**
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 26 + * Model, to which comment attached
  27 + * @var \yii\base\Model Model
22 */ 28 */
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', 29 + //public $model;
  30 +
  31 + /**
  32 + * Options
  33 + * @var array
  34 + */
  35 + public $options = [ 'class' => 'artbox_comment_container' ];
  36 +
  37 + /**
  38 + * @var string the view file that will render comment form.
  39 + */
  40 + public $formView = '@artbox-comment/views/artbox_comment_form';
  41 +
  42 + /**
  43 + * Form options
  44 + * @var array
  45 + */
  46 + public $formOptions = [
  47 + 'class' => 'artbox_form_container',
34 ]; 48 ];
35 - 49 +
36 /** 50 /**
37 - * @var null|\yii\web\View 51 + * Params to be passed to form
  52 + * @var array
38 */ 53 */
39 - public $context = NULL;  
40 - 54 + public $formParams = [ ];
  55 +
41 /** 56 /**
42 - * @var array Parts of widgets that can be rendered 57 + * @var string the view file that will render comments list.
43 */ 58 */
44 - public $parts = [ ];  
45 -  
46 - public $rating_class = NULL;  
47 -  
48 - public $rating_options = [ ];  
49 - 59 + public $listView = '@artbox-comment/views/artbox_comment_list';
  60 +
50 /** 61 /**
51 - * @var string|\common\modules\comment\models\Comment 62 + * List options
  63 + * @var array
52 */ 64 */
53 - public $comment_class;  
54 - 65 + public $listOptions = [
  66 + 'class' => 'artbox_list_container',
  67 + ];
  68 +
55 /** 69 /**
  70 + * List params
56 * @var array 71 * @var array
57 */ 72 */
58 - public $class_options = [ ];  
59 -  
60 - public $provider_options = [ ];  
61 - 73 + public $listParams = [ ];
  74 +
62 /** 75 /**
63 - * @var bool Wheather to display comment list 76 + * Reply options
  77 + * @var array
64 */ 78 */
65 - public $display_comment_list = true;  
66 - 79 + public $replyOptions = [
  80 + 'style' => 'display: none;',
  81 + 'class' => 'artbox_comment_reply_container',
  82 + ];
  83 +
67 /** 84 /**
68 - * @var bool Whether to display comment form 85 + * Reply view
  86 + * @var string
69 */ 87 */
70 - public $display_comment_form = true;  
71 - 88 + public $replyView = '@artbox-comment/views/artbox_comment_reply';
  89 +
72 /** 90 /**
73 - * @var bool Whether to display success text 91 + * Comment form ID. If you have multiple forms on the same page, please use unique IDs.
  92 + * @var string Form ID
74 */ 93 */
75 - public $display_comment_success = true;  
76 - 94 + public $formId = 'artbox-comment-form';
  95 +
77 /** 96 /**
78 - * @var bool Whether to allow one user post multiple comments 97 + * Comment list ID. If you have multiple forms on the same page, please use unique IDs.
  98 + * @var string List ID
79 */ 99 */
80 - public $allow_multiple = true;  
81 -  
82 - public $allow_reply = true;  
83 - 100 + public $listId = 'artbox-comment-list';
  101 +
84 /** 102 /**
85 - * @var array Options sent to list part 103 + * Item view
  104 + * @var string
86 */ 105 */
87 - public $list_options = [  
88 - 'tag' => 'div',  
89 - 'view' => 'list-comment',  
90 - 'class' => 'test-class',  
91 - ];  
92 - 106 + public $itemView = '@artbox-comment/views/artbox_comment_item';
  107 +
93 /** 108 /**
94 - * @var array Options sent to success part 109 + * Item options
  110 + * @var array
95 */ 111 */
96 - public $success_options = [  
97 - 'tag' => 'div',  
98 - 'content' => NULL,  
99 - 'class' => 'test-class-success', 112 + public $itemOptions = [
  113 + 'class' => 'artbox_item_container',
100 ]; 114 ];
101 - 115 +
102 /** 116 /**
103 - * @var array Options sent to form part 117 + * Entity ID attribute, default to primaryKey() if ActiveRecord and throws exception if not
  118 + * set
  119 + * @var string entity id attribute
104 */ 120 */
105 - public $form_options = [  
106 - 'tag' => 'div',  
107 - 'view' => 'form-comment',  
108 - 'class' => 'test-class-form',  
109 - ];  
110 - 121 + public $entityIdAttribute;
  122 +
  123 + /**
  124 + * Info to be passed to Comment Model
  125 + * @var string $info Additional info
  126 + */
  127 + public $info = NULL;
  128 +
111 /** 129 /**
112 - * @var bool Indicates whether any successful action happened 130 + * Client options to be passed to JS
  131 + * @var array comment widget client options
113 */ 132 */
114 - protected $isSuccess = false;  
115 -  
116 - public $success_text = 'Comment successfully added';  
117 - 133 + public $clientOptions = [ ];
  134 +
118 /** 135 /**
119 - * @var string $model Model, to which comments attached 136 + * @todo Check if needed
  137 + * @var string pjax container id
120 */ 138 */
121 - public $model;  
122 - 139 + public $pjaxContainerId;
  140 +
  141 + public $layout = "{form} {reply_form} {list}";
  142 +
123 /** 143 /**
124 - * @var integer $model_id Model id, to which comments attached 144 + * Model fully namespaced classname
  145 + * @var string Model namespace
125 */ 146 */
126 - public $model_id;  
127 - 147 + protected $entity;
  148 +
128 /** 149 /**
129 - * @var string Template of the widget. You may use <code>{success}, {form}, {list}</code>  
130 - * to render particular parts. You are also able to use common HTML here. 150 + * Entity ID for attached model
  151 + * @var integer Entity ID
131 */ 152 */
132 - public $template = "{success}\n{form}\n{list}";  
133 - 153 + protected $entityId;
  154 +
134 /** 155 /**
135 - * @var array Widget options 156 + * Encrypted data to be passed to Controller. Consist of:
  157 + * * Model::className()
  158 + * * entityId
  159 + * * info (optional)
  160 + * @var string encrypted entity key
136 */ 161 */
137 - public $options = [ ];  
138 - 162 + protected $encryptedEntityKey;
  163 +
139 /** 164 /**
140 - * @var \yii\data\DataProviderInterface Data provider of comments 165 + * Parts for widget
  166 + * @var array $parts
141 */ 167 */
142 - public $dataProvider;  
143 - 168 + protected $parts;
  169 +
144 /** 170 /**
145 - * @inheritdoc 171 + * Initializes the widget params.
146 */ 172 */
147 public function init() 173 public function init()
148 { 174 {
149 - parent::init();  
150 - \common\modules\comment\assets\CommentAsset::register($this->view);  
151 - if(is_string($this->comment_class)) {  
152 - $this->comment_class = new $this->comment_class($this->class_options);  
153 - } else {  
154 - throw new \yii\base\InvalidConfigException(__CLASS__ . '->comment_class must be defined as object full class name string.'); 175 + // Module init
  176 + Yii::$app->getModule(Module::$name);
  177 + // Model init
  178 + $model = $this->getModel();
  179 +
  180 + /**
  181 + * @todo Check if needed
  182 + */
  183 + if(empty( $this->pjaxContainerId )) {
  184 + $this->pjaxContainerId = 'comment-pjax-container-' . $this->getId();
155 } 185 }
156 - if(!empty( $this->rating_class ) && is_string($this->rating_class)) {  
157 - $this->rating_class = new $this->rating_class($this->rating_options);  
158 - } elseif(!empty( $this->rating_class )) {  
159 - throw new \yii\base\InvalidConfigException(__CLASS__ . '->rating_class must be defined as object full class name string.'); 186 +
  187 + $this->entity = $model::className();
  188 + // Entity ID init
  189 + if(!empty( $this->entityIdAttribute ) && $this->model->hasProperty($this->entityIdAttribute)) {
  190 + $this->entityId = $this->model->{$this->entityIdAttribute};
  191 + } else {
  192 + if($this->model instanceof \yii\db\ActiveRecord && !empty( $this->model->getPrimaryKey() )) {
  193 + $this->entityId = (int) $this->model->getPrimaryKey();
  194 + } else {
  195 + throw new InvalidConfigException(/*Yii::t('artbox-comment', 'The "entityIdAttribute" value for widget model cannot be empty.')*/);
  196 + }
160 } 197 }
161 - $this->comment_class->model = $this->model;  
162 - $this->comment_class->model_id = $this->model_id;  
163 - $this->createDataProvider();  
164 - $this->process();  
165 - ob_start(); 198 +
  199 + // Generate encryptedEntityKey
  200 + $this->encryptedEntityKey = $this->generateEntityKey();
  201 +
  202 + $this->registerAssets();
166 } 203 }
167 - 204 +
168 /** 205 /**
169 - * @inheritdoc  
170 - * @return string 206 + * Executes the widget.
  207 + * @return string the result of widget execution to be outputted.
171 */ 208 */
172 public function run() 209 public function run()
173 { 210 {
174 - $content = ob_get_clean();  
175 - $this->createParts(); 211 + /* @var Module $module */
  212 + $module = Yii::$app->getModule(Module::$name);
  213 + $commentModelClass = $module->commentModelClass;
  214 + $commentModel = $this->createModel($commentModelClass, [
  215 + 'entity' => $this->entity,
  216 + 'entityId' => $this->entityId,
  217 + 'encryptedEntity' => $this->encryptedEntityKey,
  218 + ]);
  219 + if($module::$enableRating) {
  220 + $ratingModelClass = $module->ratingModelClass;
  221 + $ratingModel = $this->createRating($ratingModelClass);
  222 + } else {
  223 + $ratingModel = NULL;
  224 + }
  225 +
  226 + $comments = $commentModelClass::getTree($this->entity, $this->entityId);
  227 +
  228 + $this->buildParts($commentModel, $comments, $ratingModel);
  229 +
176 return $this->renderWidget(); 230 return $this->renderWidget();
177 } 231 }
178 -  
179 - public function createParts() 232 +
  233 + /**
  234 + * Register assets.
  235 + */
  236 + protected function registerAssets()
180 { 237 {
181 - if($this->display_comment_success && ($this->isSuccess || \Yii::$app->session->getFlash('comment-success'))) {  
182 - $tag = ArrayHelper::remove($this->success_options, 'tag', 'div');  
183 - if(is_callable($this->success_options[ 'content' ])) {  
184 - $result = call_user_func(ArrayHelper::remove($this->success_options, 'content'), $this->success_text);  
185 - } elseif($this->success_options[ 'content' ] != NULL) {  
186 - $result = Html::encode(ArrayHelper::remove($this->success_options, 'content', $this->success_text));  
187 - } else {  
188 - $result = Html::encode($this->success_text);  
189 - }  
190 - $this->parts[ 'success' ] = Html::tag($tag, $result, $this->success_options);  
191 - unset( $tag, $result );  
192 - }  
193 -  
194 - if($this->display_comment_list) {  
195 - $tag = ArrayHelper::remove($this->list_options, 'tag', 'div');  
196 - $view = ArrayHelper::remove($this->list_options, 'view');  
197 - $this->parts[ 'list' ] = Html::tag($tag, $this->renderItems($view), $this->list_options);  
198 - }  
199 -  
200 - if($this->display_comment_form && $this->comment_class->checkCreate()) {  
201 - $tag = ArrayHelper::remove($this->form_options, 'tag', 'div');  
202 - $view = ArrayHelper::remove($this->form_options, 'view');  
203 - if(!empty( $this->form_options[ 'class' ] )) {  
204 - $this->form_options[ 'class' ] .= ' ' . self::$baseClass[ 'form_container' ];  
205 - } else {  
206 - $this->form_options[ 'class' ] = self::$baseClass[ 'form_container' ];  
207 - }  
208 - $this->parts[ 'form' ] = Html::tag($tag, $this->renderForm($view), $this->form_options);  
209 - } 238 + $this->clientOptions[ 'formSelector' ] = '#' . $this->formId;
  239 + $this->clientOptions[ 'listSelector' ] = '#' . $this->listId;
  240 + $options = Json::encode($this->clientOptions);
  241 + $view = $this->getView();
  242 + CommentAsset::register($view);
  243 + $view->registerJs("jQuery('#{$this->formId}').artbox_comment({$options})", $view::POS_END);
210 } 244 }
211 -  
212 - public function createDataProvider() 245 +
  246 + /**
  247 + * Get encrypted entity key
  248 + * @return string
  249 + */
  250 + protected function generateEntityKey()
213 { 251 {
214 - $this->dataProvider = new \yii\data\ActiveDataProvider([  
215 - 'query' => ArrayHelper::remove($this->provider_options, 'query', $this->comment_class->getComments($this->model, $this->model_id)),  
216 - 'sort' => ArrayHelper::remove($this->provider_options, 'sort', new Sort([  
217 - 'defaultOrder' => [  
218 - 'date_add' => SORT_DESC,  
219 - ],  
220 - ])),  
221 - 'pagination' => ArrayHelper::remove($this->provider_options, 'pagination', [  
222 - 'pageSize' => 10,  
223 - ]),  
224 - ]); 252 + return Yii::$app->getSecurity()
  253 + ->encryptByKey(Json::encode([
  254 + 'entity' => $this->entity,
  255 + 'entity_id' => $this->entityId,
  256 + 'info' => $this->info,
  257 + ]), Module::$encryptionKey);
225 } 258 }
226 -  
227 - public function renderItems($view) 259 +
  260 + /**
  261 + * Create comment model
  262 + *
  263 + * @param string $className Full namespaced model
  264 + * @param array $config Init config
  265 + *
  266 + * @return CommentInterface Comment model
  267 + * @throws InvalidConfigException If object not instance of \yii\base\Model
  268 + */
  269 + protected function createModel(string $className, array $config = [ ]): CommentInterface
228 { 270 {
229 - if(empty( $view )) {  
230 - throw new \yii\base\InvalidConfigException("list_options[view] must be set"); 271 + $options = array_merge($config, [ 'class' => $className ]);
  272 + $object = Yii::createObject($options);
  273 + if($object instanceof CommentInterface) {
  274 + return $object;
231 } 275 }
232 - return $this->render($view, [  
233 - 'dataProvider' => $this->dataProvider,  
234 - 'commentClass' => $this->comment_class,  
235 - ]); 276 + throw new InvalidConfigException(/*Yii::t(\'artbox-comment\', \'Comment model must be instance of CommentInterface.\')*/);
236 } 277 }
237 -  
238 - public function renderForm($view) 278 +
  279 + /**
  280 + * Create rating model
  281 + *
  282 + * @param string $className Full namespaced model
  283 + * @param array $config Init config
  284 + *
  285 + * @return CommentInterface Comment model
  286 + * @throws InvalidConfigException If object not instance of \yii\base\Model
  287 + */
  288 + protected function createRating(string $className, array $config = [ ]): RatingModel
239 { 289 {
240 - if(empty( $view )) {  
241 - throw new \yii\base\InvalidConfigException("form_options[view] must be set"); 290 + $options = array_merge($config, [ 'class' => $className ]);
  291 + $object = Yii::createObject($options);
  292 + if($object instanceof RatingModel) {
  293 + return $object;
242 } 294 }
243 - if($this->comment_class->guestComment || !empty( \Yii::$app->user->identity )) {  
244 - return $this->render($view, [  
245 - 'model' => $this->comment_class,  
246 - 'rating' => $this->rating_class,  
247 - 'user' => \Yii::$app->user->identity,  
248 - 'dataProvider' => $this->dataProvider,  
249 - ]);  
250 - } else {  
251 - return ''; 295 + throw new InvalidConfigException(/*Yii::t(\'artbox-comment\', \'Comment model must be instance of RatingModel.\')*/);
  296 + }
  297 +
  298 + /**
  299 + * Build parts for rendering widget
  300 + *
  301 + * @param CommentInterface $commentModel
  302 + * @param ActiveDataProvider $comments
  303 + */
  304 + protected function buildParts(CommentInterface $commentModel, ActiveDataProvider $comments, $ratingModel = NULL)
  305 + {
  306 + $form_options = $this->formOptions;
  307 + $this->parts[ 'form' ] = Html::tag(ArrayHelper::remove($form_options, 'tag', 'div'), $this->render($this->formView, [
  308 + 'comment_model' => $commentModel,
  309 + 'form_params' => $this->formParams,
  310 + 'model' => $this->getModel(),
  311 + 'formId' => $this->formId,
  312 + 'rating_model' => $ratingModel,
  313 + ]), $form_options);
  314 +
  315 + if(!\Yii::$app->user->isGuest) {
  316 + $reply_options = $this->replyOptions;
  317 + $this->parts[ 'reply_form' ] = Html::tag(ArrayHelper::remove($reply_options, 'tag', 'div'), $this->render($this->replyView, [
  318 + 'comment_model' => $commentModel,
  319 + 'form_params' => $this->formParams,
  320 + 'model' => $this->getModel(),
  321 + 'formId' => $this->formId,
  322 + ]), $reply_options);
252 } 323 }
  324 +
  325 + $list_options = array_merge($this->listOptions, [ 'id' => $this->listId ]);
  326 + $this->parts[ 'list' ] = Html::tag(ArrayHelper::remove($list_options, 'tag', 'div'), $this->render($this->listView, [
  327 + 'comment_model' => $commentModel,
  328 + 'list_params' => $this->listParams,
  329 + 'model' => $this->getModel(),
  330 + 'comments' => $comments,
  331 + 'item_options' => $this->itemOptions,
  332 + 'item_view' => $this->itemView,
  333 + ]), $list_options);
253 } 334 }
254 -  
255 - public function renderWidget() 335 +
  336 + /**
  337 + * @return string
  338 + */
  339 + protected function renderWidget(): string
256 { 340 {
257 - $template = $this->template; 341 + $layout = $this->layout;
258 $parts = $this->parts; 342 $parts = $this->parts;
259 $options = $this->options; 343 $options = $this->options;
260 - $template = preg_replace('/{success}/', ArrayHelper::remove($parts, 'success', ''), $template);  
261 - $template = preg_replace('/{list}/', ArrayHelper::remove($parts, 'list', ''), $template);  
262 - $template = preg_replace('/{form}/', ArrayHelper::remove($parts, 'form', ''), $template); 344 + $layout = preg_replace('/{list}/', ArrayHelper::getValue($parts, 'list', ''), $layout);
  345 + $layout = preg_replace('/{form}/', ArrayHelper::getValue($parts, 'form', ''), $layout);
  346 + $layout = preg_replace('/{reply_form}/', ArrayHelper::getValue($parts, 'reply_form', ''), $layout);
263 $tag = ArrayHelper::remove($options, 'tag', 'div'); 347 $tag = ArrayHelper::remove($options, 'tag', 'div');
264 - if(!empty( $options[ 'class' ] )) {  
265 - $options[ 'class' ] .= ' ' . self::$baseClass[ 'widget_container' ];  
266 - } else {  
267 - $options[ 'class' ] = self::$baseClass[ 'widget_container' ];  
268 - }  
269 - return Html::tag($tag, $template, $options); 348 + return Html::tag($tag, $layout, $options);
270 } 349 }
271 -  
272 - public function process() 350 +
  351 + public function setModel(\yii\base\Model $model)
273 { 352 {
274 - $data = \Yii::$app->request->post();  
275 - if($this->comment_class->load($data) && $this->comment_class->postComment()) {  
276 - if(is_object($this->rating_class)) {  
277 - $this->comment_class->checkRating();  
278 - if($this->comment_class->rating->load($data) && $this->comment_class->rating->save()) {  
279 - $this->isSuccess = true;  
280 - \Yii::$app->session->setFlash('comment-success', $this->success_text);  
281 - \Yii::$app->response->redirect('');  
282 - }  
283 - } else {  
284 - $this->isSuccess = true;  
285 - } 353 + $this->model = $model;
  354 + }
  355 +
  356 + public function getModel(): \yii\base\Model
  357 + {
  358 + if(!empty( $this->model )) {
  359 + return $this->model;
286 } 360 }
  361 + throw new InvalidConfigException(/*Yii::t(\'artbox-comment\', \'The "model" property must be set.\')*/);
287 } 362 }
288 -  
289 } 363 }
290 \ No newline at end of file 364 \ No newline at end of file
common/modules/comment/widgets/views/_project_comment_view.php deleted
1 -<?php  
2 - use common\models\User;  
3 - use kartik\rating\StarRating;  
4 - use yii\helpers\Html;  
5 -  
6 - /**  
7 - * @var \common\modules\comment\models\CommentProject $model Current comment model  
8 - * @var integer $key ID of current comment  
9 - * @var integer $index index of current element according  
10 - * to current page, starting from 0  
11 - * @var \yii\widgets\ListView $widget current ListView instance  
12 - * @var User $user  
13 - */  
14 - $user = $model->user;  
15 -?>  
16 -<div class="performer-vacancy-sidebar-left-wr">  
17 - <div class="performer-vacancy-sidebar-left">  
18 - <div class="performer-vacancy-sidebar-img style">  
19 - <?php  
20 - if(!empty( $user->userInfo->image )) {  
21 - echo Html::img($user->userInfo->image);  
22 - } else {  
23 - echo Html::img('/images/avatar-bg.png');  
24 - }  
25 - ?>  
26 - </div>  
27 - <div class="performer-vacancy-sidebar-all style">  
28 - <div class="performer-vacancy-sidebar-soc style">  
29 - <ul>  
30 - <?php  
31 - if(!empty( $user->userInfo->social_fb )) {  
32 - echo '<li>' . Html::a(Html::img('/images/ico-fb.png'), $user->userInfo->social_fb, [ 'target' => '_blank' ]) . '</li>';  
33 - }  
34 - ?>  
35 - <?php  
36 - if(!empty( $user->userInfo->social_t )) {  
37 - echo '<li>' . Html::a(Html::img('/images/ico-tw.png'), $user->userInfo->social_t, [ 'target' => '_blank' ]) . '</li>';  
38 - }  
39 - ?>  
40 - <?php  
41 - if(!empty( $user->userInfo->social_in )) {  
42 - echo '<li>' . Html::a(Html::img('/images/ico-in.png'), $user->userInfo->social_in, [ 'target' => '_blank' ]) . '</li>';  
43 - }  
44 - ?>  
45 - <?php  
46 - if(!empty( $user->userInfo->social_vk )) {  
47 - echo '<li>' . Html::a(Html::img('/images/ico-vk.png'), $user->userInfo->social_vk, [ 'target' => '_blank' ]) . '</li>';  
48 - }  
49 - ?>  
50 - </ul>  
51 - </div>  
52 - <div class="performer-vacancy-sidebar-views style">  
53 - <ul class="style">  
54 - <li><img src="/images/sidebar-ico/ico-1.png" alt="">  
55 - <div class="sidebarvievstxt"><?= $user->userInfo->view_count ?></div>  
56 - </li>  
57 - <li><img src="/images/sidebar-ico/ico-9.png" alt="">  
58 - <div class="sidebarvievstxt">  
59 - <span class="sidebar-views-txt">Статус: </span><?= ( empty( $user->userInfo->busy ) ? 'Свободен' : 'Занят' ) ?>  
60 - </div>  
61 - </li>  
62 - <li><img src="/images/sidebar-ico/ico-2.png" alt="">  
63 - <div class="sidebarvievstxt">  
64 - <span class="sidebar-views-txt">На сайте: </span><?= $user->liveTime ?>  
65 - </div>  
66 - </li>  
67 - <li><img src="/images/sidebar-ico/ico-3.png" alt="">  
68 - <div class="sidebarvievstxt"><span class="sidebar-views-txt">Последний визит:<br></span><?= $user->lastVisit ?>  
69 - </div>  
70 - </li>  
71 - </ul>  
72 - <?= Html::a('Посмотреть профиль', $user->link, [ 'class' => 'tender-see-profile style',  
73 - 'target' => '_blank',  
74 - ]) ?>  
75 - </div>  
76 - </div>  
77 - </div>  
78 -</div>  
79 -<div class="tender-offer-proj-block-right-wr">  
80 - <div class="tender-offer-proj-block-right">  
81 - <div class="tender-offer-proj-min-blocks">  
82 - <span><?= $model->budget_from . '-' . $model->budget_to . ' ' . $model->currency->label ?></span>  
83 - </div>  
84 - <div class="tender-offer-proj-min-blocks">  
85 - <span><?= $model->term_from . '-' . $model->term_to ?> ДНЯ</span></div>  
86 - </div>  
87 - <div class="tender-offer-proj-block-left">  
88 - <div class="search-worker-blocks-title-wr">  
89 - <div class="search-worker-blocks-title-title"><?= $user->name ?></div>  
90 - <?php  
91 - echo StarRating::widget([  
92 - 'name' => 'rating_review_comment',  
93 - 'value' => $user->userInfo->rating,  
94 - 'pluginOptions' => [  
95 - 'displayOnly' => true,  
96 - 'size' => 'xxs',  
97 - 'min' => 0,  
98 - 'max' => 10,  
99 - 'stars' => 10,  
100 - ],  
101 - ]);  
102 - ?>  
103 - <?= Html::a(count($user->comments) . ' мнений', $user->getLink('review'), [ 'class' => 'link-to-comm' ]) ?>  
104 - </div>  
105 - <div class="tender-offer-proj-txt">  
106 - <?= $model->text ?>  
107 - </div>  
108 - <ul class="download-list-files">  
109 - <?php  
110 - foreach($model->getFilesList() as $file) {  
111 - ?>  
112 - <li>  
113 - <span></span>  
114 - <?= Html::a($file->name, $file->dir, [  
115 - 'class' => 'download-link-file',  
116 - 'download' => 'download',  
117 - ]) ?>  
118 - <?= Html::a('Скачать', $file->dir, [  
119 - 'class' => 'download-link',  
120 - 'download' => 'download',  
121 - ]) ?>  
122 - </li>  
123 - <?php  
124 - }  
125 - ?>  
126 - </ul>  
127 - </div>  
128 - <div class="tender-more-buttons-wr">  
129 - <?= Html::a('Портфолио', $user->getLink('portfolio'), [ 'class' => 'get-project-new' ]) ?>  
130 - <?= Html::a('Контакты', $user->link, [ 'class' => 'get-list-new' ]) ?>  
131 -  
132 - <?php  
133 - if($model->status == $model::STATUS_ANONYMOUS) {  
134 - echo Html::tag('div', 'Анонимное предложение', [ 'class' => 'project_status' ]);  
135 - }  
136 - if(\Yii::$app->user->getId() == $model->owner->user_id) {  
137 - ?>  
138 - <div class="project_owner_state">  
139 - <p>  
140 - <?php  
141 - switch($model->state) {  
142 - case 1:  
143 - echo 'Предложение не рассмотрено';  
144 - break;  
145 - case 2:  
146 - echo 'Исполнитель поставлен на рассмотрение';  
147 - break;  
148 - case 3:  
149 - echo 'Исполнитель назначен исполнителем';  
150 - break;  
151 - case 4:  
152 - echo 'Вы отказали данному исполнителю';  
153 - break;  
154 - case 5:  
155 - echo 'Исполнитель отказался от данного предложения';  
156 - break;  
157 - }  
158 - ?>  
159 - </p>  
160 - </div>  
161 - <?php  
162 - if($model->state != $model::STATE_TRASH) {  
163 - ?>  
164 - <div class="project_owner_control">  
165 - <span>Отметить как: </span>  
166 - <p class="new_mark_"></p>  
167 - <div>  
168 - <?php  
169 - echo Html::a('новый', [ '#' ], [  
170 - 'data-project-id' => $model->owner->project_id,  
171 - 'data-comment-id' => $model->comment_id,  
172 - 'class' => 'artbox_project_make_new' . ( ( $model->state == $model::STATE_NEW ) ? ' active' : '' ),  
173 - ]);  
174 - echo Html::a('кандидат', [ '#' ], [  
175 - 'data-project-id' => $model->owner->project_id,  
176 - 'data-comment-id' => $model->comment_id,  
177 - 'class' => 'artbox_project_make_candidate' . ( ( $model->state == $model::STATE_CANDIDATE ) ? ' active' : '' ),  
178 - ]);  
179 - echo Html::a('исполнитель', [ '#' ], [  
180 - 'data-project-id' => $model->owner->project_id,  
181 - 'data-comment-id' => $model->comment_id,  
182 - 'class' => 'artbox_project_make_performer' . ( ( $model->state == $model::STATE_PERFORMER ) ? ' active' : '' ),  
183 - ]);  
184 - echo Html::a('отказать', [ '#' ], [  
185 - 'data-project-id' => $model->owner->project_id,  
186 - 'data-comment-id' => $model->comment_id,  
187 - 'class' => 'artbox_project_make_deny' . ( ( $model->state == $model::STATE_DENY ) ? ' active' : '' ),  
188 - ]);  
189 - ?>  
190 - </div>  
191 - </div>  
192 - <?php  
193 - }  
194 - }  
195 - ?>  
196 - </div>  
197 -  
198 -  
199 -</div>  
common/modules/comment/widgets/views/_question_comment_view.php deleted
1 -<?php  
2 - use common\models\User;  
3 - use common\modules\comment\widgets\CommentWidget;  
4 - use yii\helpers\Html;  
5 - use yii\web\View;  
6 -  
7 - /**  
8 - * @var View $this  
9 - * @var \common\modules\comment\models\Comment $model Current comment model  
10 - * @var integer $key ID of current comment  
11 - * @var integer $index index of current element according  
12 - * to current page, starting from 0  
13 - * @var \yii\widgets\ListView $widget current ListView instance  
14 - * @var User $user  
15 - */  
16 - $user = $model->user;  
17 - if(empty( $model->comment_pid )) {  
18 - $model->buildButtons([  
19 - 'reply',  
20 - 'delete',  
21 - ]);  
22 - }  
23 -?>  
24 - <div class="<?= ( ( !empty( $model->child ) ) ? 'has-child' : '' ) ?>">  
25 - <div class="header-cabinet-foto" style="background: none;"><?= Html::img(( !empty( $model->user ) && !empty( $model->user->userInfo->image ) ) ? $model->user->minImg($model->user->userInfo->image, 48, 48) : '/images/ico-profile.png') ?></div>  
26 - <div style="width: 500px; float: left; margin-left: 12px;">  
27 - <div class="comments-name style <?= CommentWidget::$baseClass[ 'comment_author' ] ?>">  
28 - <a href="/"><?= $model->getAuthor(' (Гость)') ?></a>  
29 -  
30 - </div>  
31 -  
32 - <?php  
33 - /* == STATUS PRO ==  
34 - ?>  
35 - <div class="comments-status"><span>Pro</span></div>  
36 - <?php  
37 - */  
38 - ?>  
39 - <div class="blog-post-date style">  
40 - <span></span>  
41 - <p><?= \Yii::$app->formatter->asDate($model->date_add, 'php:d.m.Y') ?></p>  
42 - </div>  
43 - <!-- <div class="comments-date style">--><? //= \Yii::$app->formatter->asDate($model->date_add, 'php:d.m.Y') ?><!--</div>-->  
44 - </div>  
45 - <div class="comments-content">  
46 - <div class="style" style="font-weight: 700;">Вопрос</div>  
47 - <div class="style" style="margin-top: 2px"><?= $model->text ?></div>  
48 - </div>  
49 - <?php  
50 - if(!empty( $model->child )) {  
51 - echo Html::tag('div', $this->render('@common/modules/comment/widgets/views/_question_comment_view', [  
52 - 'model' => $model->child,  
53 - 'key' => $key,  
54 - 'index' => $index,  
55 - 'widget' => $widget,  
56 - ]), [  
57 - 'class' => CommentWidget::$baseClass[ 'comment_container' ],  
58 - 'data' => [  
59 - 'key' => $model->child->comment_id,  
60 - 'form' => $model->formName(),  
61 - ],  
62 - ]);  
63 - }  
64 - ?>  
65 - <?php  
66 - if(array_filter($model->buttons)) {  
67 - ?>  
68 - <div class="buutons_comm style" style="margin-top: 15px">  
69 - <?php  
70 - if(!empty( $model->buttons[ 'delete' ] )) {  
71 - echo Html::a(( $model->user_id != NULL && $model->user_id == \Yii::$app->user->id ) ? 'Удалить' : 'Пожаловаться ', $model->buttons[ 'delete' ], [ 'class' => 'artbox_comment_delete_answer' ]);  
72 - }  
73 - if(!empty( $model->buttons[ 'update' ] )) {  
74 - echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => 'artbox_comment_update_answer' ]);  
75 - }  
76 - if(!empty( $model->buttons[ 'reply' ] )) {  
77 - echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] . ' artbox_comment_reply_answer' ]);  
78 - }  
79 - ?>  
80 - </div>  
81 - <?php  
82 - }  
83 - ?>  
84 - </div>  
85 -<?php  
86 - /* == PROJECT INFO ==  
87 - ?>  
88 - <div class="comments-project-link">Проект: <a href="#">Ремонт спальни</a></div>  
89 - <?php  
90 - */  
91 -?>  
92 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/_review_comment_view.php deleted
1 -<?php  
2 - use common\models\User;  
3 - use common\modules\comment\widgets\CommentWidget;  
4 - use yii\helpers\Html;  
5 - use yii\web\View;  
6 -  
7 - /**  
8 - * @var View $this  
9 - * @var \common\modules\comment\models\Comment $model Current comment model  
10 - * @var integer $key ID of current comment  
11 - * @var integer $index index of current element according  
12 - * to current page, starting from 0  
13 - * @var \yii\widgets\ListView $widget current ListView instance  
14 - * @var User $user  
15 - */  
16 - $user = $model->user;  
17 - $model->buildButtons([ 'delete' ]);  
18 -?>  
19 - <div class="comments-name <?= CommentWidget::$baseClass[ 'comment_author' ] ?>">  
20 - <?= $model->getAuthor(' (Гость)') ?>  
21 - </div>  
22 -<?php  
23 - /* == STATUS PRO ==  
24 - ?>  
25 - <div class="comments-status"><span>Pro</span></div>  
26 - <?php  
27 - */  
28 -?>  
29 - <div class="comments-date"><?= \Yii::$app->formatter->asDate($model->date_add, 'php:d.m.Y') ?></div>  
30 -<?php  
31 - if(!empty( $model->rating ) && $model->rating->value > 0) {  
32 - ?>  
33 - <div class="rateit" data-rateit-value="<?php echo $model->rating->value; ?>" data-rateit-readonly="true" data-rateit-ispreset="true"></div>  
34 - <?php  
35 - }  
36 -?>  
37 - <div class="comments-content">  
38 - <?= $model->text ?>  
39 - </div>  
40 - <div>  
41 - <?php  
42 - if(!empty( $model->buttons[ 'delete' ] )) {  
43 - echo Html::a(( $model->user_id != NULL && $model->user_id == \Yii::$app->user->id ) ? 'Удалить' : 'Пожаловаться ', $model->buttons[ 'delete' ], [ 'class' => CommentWidget::$baseClass[ 'comment_delete' ] ]);  
44 - }  
45 - if(!empty( $model->buttons[ 'update' ] )) {  
46 - echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => CommentWidget::$baseClass[ 'comment_update' ] ]);  
47 - }  
48 - if(!empty( $model->buttons[ 'reply' ] )) {  
49 - echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] ]);  
50 - }  
51 - ?>  
52 - </div>  
53 -<?php  
54 - /* == PROJECT INFO ==  
55 - ?>  
56 - <div class="comments-project-link">Проект: <a href="#">Ремонт спальни</a></div>  
57 - <?php  
58 - */  
59 -?>  
60 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/form-comment-answer.php deleted
1 -<?php  
2 - /**  
3 - * @var \common\modules\comment\models\Comment $model  
4 - * @var \common\models\User $user  
5 - * @var \yii\data\ActiveDataProvider $dataProvider  
6 - * @var null|\common\modules\comment\models\Rating $rating  
7 - */  
8 - use common\models\Project;  
9 - use yii\widgets\ActiveForm;  
10 - use yii\helpers\Html;  
11 -  
12 -?>  
13 -<?php  
14 - if(!empty( $model->model_id )) {  
15 - $project = Project::findOne($model->model_id);  
16 - }  
17 - if(!empty( $project ) && $project->user_id != \Yii::$app->user->id) {  
18 - ?>  
19 - <div class="tender-add-answer-title fix_tender_answer">Задать вопрос</div>  
20 - <?php  
21 - }  
22 -?>  
23 -<div class="new-portf-add-comm style tender_questions_" style="padding-top: 16px">  
24 -  
25 - <?php  
26 - if(!empty( \Yii::$app->user->id )) { ?>  
27 - <div class="form-ico-ded-wr" style="width: 100%">  
28 - <div class="header-cabinet-foto">  
29 - <img src="<?php echo \Yii::$app->user->identity->userInfo->image; ?>" alt="">  
30 - </div>  
31 - <div class="form-value-ded-name"><?php echo \Yii::$app->user->identity->name; ?></div>  
32 - </div>  
33 -  
34 -  
35 - <?php  
36 - }  
37 - $form = ActiveForm::begin(['options' => ['data' => ['pjax' => true]]]);  
38 - if(!$model->isNewRecord) {  
39 - echo $form->field($model, 'comment_id')  
40 - ->hiddenInput()  
41 - ->label(false)  
42 - ->error(false);  
43 - }  
44 - if(!empty( $model->comment_pid )) {  
45 - echo $form->field($model, 'comment_pid')  
46 - ->hiddenInput()  
47 - ->label(false)  
48 - ->error(false);  
49 - }  
50 - if($model->scenario == $model::SCENARIO_GUEST) {  
51 - echo $form->field($model, 'user_name', [  
52 - 'options' => [  
53 - 'class' => 'input-blocks-comm',  
54 - ],  
55 - 'inputOptions' => [  
56 - 'class' => 'custom-input-4',  
57 - ],  
58 - ])  
59 - ->textInput();  
60 - echo $form->field($model, 'user_email', [  
61 - 'options' => [  
62 - 'class' => 'input-blocks-comm',  
63 - ],  
64 - 'inputOptions' => [  
65 - 'class' => 'custom-input-4',  
66 - ],  
67 - ])  
68 - ->textInput();  
69 - }  
70 -  
71 - ?>  
72 - <div class="artbox_comment_reply_block artbox_comment_reply_answer_block"></div>  
73 - <?php  
74 -  
75 - echo $form->field($model, 'text', [  
76 - 'options' => [  
77 - 'class' => 'input-blocks-comm area-comm tender_com_fix_',  
78 - ],  
79 - 'inputOptions' => [  
80 - 'class' => 'custom-area-4',  
81 - ],  
82 - ])  
83 - ->label($model->isNewRecord ? 'Вопрос' : 'Ответ', [ 'class' => 'artbox_comment_answer_label' ])  
84 - ->textarea();  
85 - ?>  
86 - <div class="input-blocks-comm-button style">  
87 - <?php  
88 - if($model->isNewRecord) {  
89 - echo Html::submitButton('Задать вопрос');  
90 - } else {  
91 - echo Html::submitButton('Обновить вопрос', [ 'class' => 'artbox_comment_update_answer_submit' ]);  
92 - }  
93 - ?>  
94 - </div>  
95 - <?php  
96 - $form->end();  
97 - ?>  
98 -</div>  
99 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/form-comment-review.php deleted
1 -<?php  
2 - /**  
3 - * @var View $this  
4 - * @var \common\modules\comment\models\Comment $model  
5 - * @var \common\models\User $user  
6 - * @var \yii\data\ActiveDataProvider $dataProvider  
7 - * @var null|\common\modules\comment\models\Rating $rating  
8 - */  
9 - use common\modules\comment\widgets\CommentWidget;  
10 - use yii\web\View;  
11 - use yii\widgets\ActiveForm;  
12 - use yii\helpers\Html;  
13 -?>  
14 -<div class="new-portf-add-comm style">  
15 - <?php  
16 - $form = ActiveForm::begin();  
17 - if(!$model->isNewRecord) {  
18 - echo $form->field($model, 'comment_id')  
19 - ->hiddenInput()  
20 - ->label(false)  
21 - ->error(false);  
22 - }  
23 - echo $form->field(( !empty( $model->rating ) ? $model->rating : $rating ), 'value')  
24 - ->label(false)  
25 - ->hiddenInput();  
26 - ?>  
27 - <div id="rateit-form"></div>  
28 - <?php  
29 - $js =  
30 - "rateit = $('#rateit-form').rateit({  
31 - step: 1  
32 - });  
33 - $(rateit).bind('rated', function() {  
34 - $('#rating-value').val($(this).rateit('value'));  
35 - });  
36 - $(rateit).bind('reset', function() {  
37 - $('#rating-value').val('');  
38 - });";  
39 - $this->registerJs($js);  
40 - ?>  
41 - <?php  
42 - //rating-value  
43 - if($model->scenario == $model::SCENARIO_GUEST) {  
44 - echo $form->field($model, 'user_name', [  
45 - 'options' => [  
46 - 'class' => 'input-blocks-comm',  
47 - ],  
48 - 'inputOptions' => [  
49 - 'class' => 'custom-input-4',  
50 - ],  
51 - ])  
52 - ->textInput();  
53 - echo $form->field($model, 'user_email', [  
54 - 'options' => [  
55 - 'class' => 'input-blocks-comm',  
56 - ],  
57 - 'inputOptions' => [  
58 - 'class' => 'custom-input-4',  
59 - ],  
60 - ])  
61 - ->textInput();  
62 - }  
63 - if(!empty( $model->comment_pid )) {  
64 - echo Html::tag('div', Html::activeHiddenInput($model, 'comment_pid') . Html::tag('p', $model->parent->author, [ 'class' => 'artbox_comment_reply_author' ]), [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] ]);  
65 - } else {  
66 - echo Html::tag('div', '', [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] . ' test_class' ]);  
67 - }  
68 - echo $form->field($model, 'text', [  
69 - 'options' => [  
70 - 'class' => 'input-blocks-comm area-comm',  
71 - ],  
72 - 'inputOptions' => [  
73 - 'class' => 'custom-area-4',  
74 - ],  
75 - ])  
76 - ->textarea();  
77 - ?>  
78 - <div class="input-blocks-comm-button style">  
79 - <?php  
80 - if($model->isNewRecord) {  
81 - echo Html::submitButton('Добавить комментарий');  
82 - } else {  
83 - echo Html::submitButton('Обновить комментарий', [ 'class' => CommentWidget::$baseClass[ 'comment_update_submit' ] ]);  
84 - }  
85 - ?>  
86 - </div>  
87 - <?php  
88 - $form->end();  
89 - ?>  
90 -</div>  
91 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/form-comment.php deleted
1 -<?php  
2 - /**  
3 - * @var \common\modules\comment\models\Comment $model  
4 - * @var \common\models\User $user  
5 - * @var \yii\data\ActiveDataProvider $dataProvider  
6 - * @var null|\common\modules\comment\models\Rating $rating  
7 - */  
8 - use kartik\rating\StarRating;  
9 - use yii\widgets\ActiveForm;  
10 - use yii\helpers\Html;  
11 -  
12 -?>  
13 -<div class="new-portf-comm-count">Комментарии: <?= $dataProvider->totalCount ?></div>  
14 -  
15 -<div class="new-portf-add-comm style">  
16 -  
17 - <?php  
18 - $form = ActiveForm::begin();  
19 - if($rating) {  
20 - echo $form->field(( !empty( $model->rating ) ? $model->rating : $rating ), 'value')  
21 - ->label(false)  
22 - ->widget(StarRating::className(), [  
23 - 'pluginOptions' => [  
24 - 'size' => 'xxs',  
25 - 'step' => 1,  
26 - 'value' => 2,  
27 - 'showCaption' => false,  
28 - 'min' => 0,  
29 - 'max' => 10,  
30 - 'stars' => 10,  
31 - ],  
32 - ]);  
33 - }  
34 -  
35 - if($model->scenario == $model::SCENARIO_GUEST) {  
36 - echo $form->field($model, 'user_name', [  
37 - 'options' => [  
38 - 'class' => 'input-blocks-comm fix_marg_',  
39 - ],  
40 - 'inputOptions' => [  
41 - 'class' => 'custom-input-4',  
42 - ],  
43 - ])  
44 - ->textInput();  
45 - echo $form->field($model, 'user_email', [  
46 - 'options' => [  
47 - 'class' => 'input-blocks-comm',  
48 - ],  
49 - 'inputOptions' => [  
50 - 'class' => 'custom-input-4',  
51 - ],  
52 - ])  
53 - ->textInput()  
54 - ->hint('Ваш email не будет доступен к просмотру.');  
55 - }  
56 -  
57 - ?>  
58 - <div class="artbox_comment_reply_block"></div>  
59 - <?php  
60 -  
61 - echo $form->field($model, 'text', [  
62 - 'options' => [  
63 - 'class' => 'input-blocks-comm area-comm',  
64 - ],  
65 - 'inputOptions' => [  
66 - 'class' => 'custom-area-4',  
67 - ],  
68 - ])  
69 - ->textarea();  
70 - ?>  
71 - <div class="input-blocks-comm-button style">  
72 - <?= Html::submitButton('Добавить комментарий') ?>  
73 - </div>  
74 - <?php  
75 - $form->end();  
76 - ?>  
77 -</div>  
78 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/form-project-comment.php deleted
1 -<?php  
2 - /**  
3 - * @var \common\modules\comment\models\CommentProject $model  
4 - * @var \common\models\User $user  
5 - * @var \yii\data\ActiveDataProvider $dataProvider  
6 - */  
7 - use common\models\Currency;  
8 - use yii\widgets\ActiveForm;  
9 - use yii\helpers\Html;  
10 -  
11 - $currencies = Currency::getCurrencyDropdown();  
12 -?>  
13 -<div class="tender-add-answer-title fix_tender_answer"><?= Yii::t('app', 'add_answer') ?></div>  
14 -<div class="new-portf-add-comm style fix-portf_">  
15 -  
16 -  
17 -  
18 - <div class="form-tender-answer _fix_errors_tender style">  
19 - <?php  
20 - $form = ActiveForm::begin([ 'options' => [ 'class' => 'resformsfile MultiFile-intercepted', 'enctype' => 'multipart/form-data', 'data' => ['pjax' => true] ] ]);  
21 - ?>  
22 - <div class="form-value-wr style">  
23 - <div class="form-ico-ded-wr">  
24 - <div class="header-cabinet-foto">  
25 - <?= Html::img(($user->userInfo->image)?:'') ?>  
26 - </div>  
27 - <div class="form-value-ded-name">  
28 - <?= $user->name ?>  
29 - </div>  
30 - </div>  
31 - <div class="form-value-price-wr">  
32 - <div class="form-value-price-title">Стоимость</div>  
33 - <div class="form-price-wr">  
34 - <?= $form->field($model, 'budget_from', [  
35 - 'template' => "{input}\n{error}",  
36 - 'options' => [ 'tag' => 'span' ],  
37 - ])  
38 - ->input('number', [ 'placeholder' => $model->getAttributeLabel('budget_from') ]) ?>  
39 - <?= $form->field($model, 'budget_to', [  
40 - 'template' => "{input}\n{error}",  
41 - 'options' => [ 'tag' => 'span' ],  
42 - ])  
43 - ->input('number', [ 'placeholder' => $model->getAttributeLabel('budget_to') ]) ?>  
44 - <?= $form->field($model, 'budget_currency', [  
45 - 'template' => "{input}<div class='select-after'></div>\n{error}",  
46 - 'options' => [ 'class' => 'blocks-check-list-wrapp check-valuta' ],  
47 - ])  
48 - ->dropDownList($currencies) ?>  
49 - </div>  
50 - </div>  
51 - <div class="form-value-price-wr" style="float: right">  
52 - <div class="form-value-price-title">  
53 - Сроки(<span style="font-weight: normal">в днях</span>)  
54 - </div>  
55 - <div class="form-price-wr">  
56 - <?= $form->field($model, 'term_from', [  
57 - 'template' => "{input}\n{error}",  
58 - 'options' => [ 'tag' => 'span' ],  
59 - ])  
60 - ->input('number', [ 'placeholder' => $model->getAttributeLabel('term_from') ]) ?>  
61 - <?= $form->field($model, 'term_to', [  
62 - 'template' => "{input}\n{error}",  
63 - 'options' => [ 'tag' => 'span' ],  
64 - ])  
65 - ->input('number', [ 'placeholder' => $model->getAttributeLabel('term_to') ]) ?>  
66 - </div>  
67 - </div>  
68 - </div>  
69 - <?= $form->field($model, 'text', [  
70 - 'template' => "{input}\n{error}",  
71 - 'options' => [ 'class' => 'form-tender-txt style' ],  
72 - ])  
73 - ->textarea([ 'placeholder' => $model->getAttributeLabel('text') ]) ?>  
74 - <div class="tender-file-wr">  
75 - <?= $form->field($model, 'file[]')  
76 - ->fileInput([ 'class' => 'multi' ])  
77 - ->label(false) ?>  
78 - <a href="#" class="addfilemulti">Прикрепить файл</a>  
79 - <div class="max-size">Максимальный размер<br/>файла 5 МБ</div>  
80 - </div>  
81 - <div class="tender-form-buttons-wr">  
82 - <?php  
83 - echo Html::submitInput('Подать заявку', [ 'class' => 'get-project-new' ]);  
84 - echo Html::submitInput('ответить анонимно', [  
85 - 'class' => 'get-list-new',  
86 - 'name' => 'CommentProject[anonymous]',  
87 - ]);  
88 - echo Html::a('Очистить', [  
89 - 'tender/view',  
90 - 'tender_id' => \Yii::$app->request->get('tender_id'),  
91 - '#' => 'w1',  
92 - ]);  
93 - ?>  
94 - </div>  
95 - <?php  
96 - $form->end();  
97 - ?>  
98 - </div>  
99 -  
100 -  
101 -</div>  
102 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/list-comment-question.php deleted
1 -<?php  
2 - /**  
3 - * @var \yii\data\DataProviderInterface $dataProvider  
4 - * @var Comment $commentClass  
5 - */  
6 - use common\modules\comment\models\Comment;  
7 - use common\modules\comment\widgets\CommentWidget;  
8 -  
9 -  
10 - if(!empty( $dataProvider )) {  
11 - ?>  
12 - <div class="tender-offer-proj-title-all">Вопросов: (<?= $dataProvider->totalCount ?>)</div>  
13 - <?php  
14 - }  
15 -  
16 -  
17 - echo \yii\widgets\ListView::widget([  
18 - 'dataProvider' => $dataProvider,  
19 - 'itemView' => '_question_comment_view',  
20 - 'options' => [  
21 - 'tag' => 'ul',  
22 - 'class' => 'proektant-comments tender_list_comm_ style',  
23 - ],  
24 - 'itemOptions' => [  
25 - 'tag' => 'li',  
26 - 'class' => CommentWidget::$baseClass[ 'comment_container' ],  
27 - 'data' => [  
28 - 'form' => $commentClass->formName(),  
29 - ],  
30 - ],  
31 - 'layout' => "{items}\n{pager}",  
32 - ]);  
33 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/list-comment-review.php deleted
1 -<?php  
2 - /**  
3 - * @var \yii\data\DataProviderInterface $dataProvider  
4 - * @var Comment $commentClass  
5 - */  
6 - use common\modules\comment\models\Comment;  
7 - use common\modules\comment\widgets\CommentWidget;  
8 - echo \yii\widgets\ListView::widget([  
9 - 'dataProvider' => $dataProvider,  
10 - 'itemView' => '_review_comment_view',  
11 - 'options' => [  
12 - 'tag' => 'ul',  
13 - 'class' => 'proektant-comments style',  
14 - ],  
15 - 'itemOptions' => [  
16 - 'tag' => 'li',  
17 - 'class' => CommentWidget::$baseClass[ 'comment_container' ],  
18 - 'data' => [  
19 - 'form' => $commentClass->formName(),  
20 - ],  
21 - ],  
22 - 'layout' => "{items}\n<div class='navi-buttons-wr style content'>{pager}</div>",  
23 - ]);  
24 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/list-comment.php deleted
1 -<?php  
2 - /**  
3 - * @var \yii\data\DataProviderInterface $dataProvider  
4 - */  
5 -echo \yii\widgets\ListView::widget([  
6 - 'dataProvider' => $dataProvider,  
7 - 'itemView' => 'project_comment_view',  
8 - 'itemOptions' => [  
9 - 'tag' => false,  
10 - ],  
11 - 'summary' => '',  
12 -]);  
13 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/list-project-comment.php deleted
1 -<?php  
2 - /**  
3 - * @var \yii\data\DataProviderInterface $dataProvider  
4 - */  
5 -?>  
6 -<div class="box-wr">  
7 - <div class="box-all">  
8 - <div class="tender-offer-proj-title-all style">Предложения проектантов (<?=$dataProvider->getTotalCount()?>)</div>  
9 - <div class="tender-offer-proj-blocks-wr style">  
10 - <?php  
11 - echo \yii\widgets\ListView::widget([  
12 - 'dataProvider' => $dataProvider,  
13 - 'itemView' => '_project_comment_view',  
14 - 'itemOptions' => [  
15 - 'class' => 'tender-offer-proj-blocks style',  
16 - ],  
17 - 'summary' => '',  
18 - ]);  
19 - ?>  
20 - </div>  
21 - </div>  
22 -</div>  
23 \ No newline at end of file 0 \ No newline at end of file
common/modules/comment/widgets/views/project_comment_view.php deleted
1 -<?php  
2 - use common\models\User;  
3 - use common\modules\comment\widgets\CommentWidget;  
4 - use kartik\rating\StarRating;  
5 - use yii\helpers\Html;  
6 -  
7 - /**  
8 - * @var \common\modules\comment\models\Comment $model Current comment model  
9 - * @var integer $key ID of current comment  
10 - * @var integer $index index of current element according to  
11 - * current page, starting from 0  
12 - * @var \yii\widgets\ListView $widget current ListView instance  
13 - * @var User $user  
14 - */  
15 - $user = NULL;  
16 - if(!empty( $model->user_id )) {  
17 - $user = User::find()  
18 - ->where([ 'id' => $model->user_id ])  
19 - ->with('userInfo')  
20 - ->one();  
21 - }  
22 - $model->buildButtons([ 'delete' ]);  
23 -?>  
24 -<div class="new-portf-comm-read artbox_comment_container" data-key="<?= $model->comment_id ?>" data-form="<?= $model->formName() ?>">  
25 - <div class="style">  
26 - <div class="header-cabinet-foto">  
27 - <?php  
28 - if(!empty( $user ) && !empty( $user->userInfo->image )) {  
29 - echo "<img src='{$user->userInfo->image}' alt=''>";  
30 - } else {  
31 - echo "<img src='/images/ico-profile.png' alt=''>";  
32 - }  
33 - ?>  
34 - </div>  
35 - <div style="width: 500px; float: left; margin-left: 12px;">  
36 - <div class="comments-name style artbox_comment_author">  
37 - <?php  
38 - if(!empty( $user )) {  
39 - echo Html::a('<span class="artbox_comment_author">' . $user->firstname . ' ' . $user->lastname . '</span>', [  
40 - 'performer/common',  
41 - 'performer_id' => $user->id,  
42 - ]);  
43 - } else {  
44 - echo '<span class="artbox_comment_author">' . $model->user_name . '</span>' . '(Гость)';  
45 - }  
46 - ?>  
47 - </div>  
48 - <div class="new-portf-comm-read-rating">  
49 - <?php  
50 - if($rating = $model->hasRating()) {  
51 - echo StarRating::widget([  
52 - 'name' => 'rating_project_comment',  
53 - 'value' => $rating->value,  
54 - 'pluginOptions' => [  
55 - 'displayOnly' => true,  
56 - 'size' => 'xxs',  
57 - 'min' => 0,  
58 - 'max' => 10,  
59 - 'stars' => 10,  
60 - ],  
61 - ]);  
62 - }  
63 - ?>  
64 - </div>  
65 - <div class="blog-post-date style">  
66 - <span></span>  
67 - <p><?= date('d.m.Y', strtotime($model->date_add)) ?></p>  
68 - </div>  
69 - </div>  
70 -  
71 - <div class="new-portf-answer artbox_comment_text">  
72 - <?= Html::encode($model->text) ?>  
73 - </div>  
74 - <div style="clear:both"></div>  
75 - <div>  
76 - <?php  
77 - if(!empty( $model->buttons[ 'delete' ] )) {  
78 - echo Html::a(( $model->user_id != NULL && $model->user_id == \Yii::$app->user->id ) ? 'Удалить' : 'Пожаловаться ', $model->buttons[ 'delete' ], [ 'class' => CommentWidget::$baseClass[ 'comment_delete' ] ]);  
79 - }  
80 - if(!empty( $model->buttons[ 'update' ] )) {  
81 - echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => CommentWidget::$baseClass[ 'comment_update' ] ]);  
82 - }  
83 - if(!empty( $model->buttons[ 'reply' ] )) {  
84 - echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] ]);  
85 - }  
86 - ?>  
87 - </div>  
88 - <?php  
89 - /*  
90 - ?>  
91 - <div class="action_panel">  
92 - <ul>  
93 - <li style="display:inline-block" class="artbox_comment_reply">Ответить</li>  
94 - <li style="display:inline-block" class="artbox_comment_update">Редактировать</li>  
95 - <li style="display:inline-block" class="artbox_comment_delete">Удалить</li>  
96 - </ul>  
97 - </div>  
98 - <?php  
99 - */  
100 - ?>  
101 - </div>  
102 - <div class="style"></div>  
103 -</div>  
104 \ No newline at end of file 0 \ No newline at end of file
console/migrations/m160721_152001_create_product_to_rating.php 100644 → 100755
frontend/components/SeoComponent.php
@@ -10,25 +10,27 @@ class SeoComponent implements BootstrapInterface @@ -10,25 +10,27 @@ class SeoComponent implements BootstrapInterface
10 10
11 public function bootstrap($app) 11 public function bootstrap($app)
12 { 12 {
13 - \Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function($event) {  
14 - $array = ['%21'=>'!','%22'=>'"','%23'=>'#','%24'=>'$','%25'=>'%','%26'=>'&','%27'=>'\'','%28'=>'(','%29'=>')','%2a'=>'*','%2b'=>'+','%2c'=>',','%2d'=>'-','%2e'=>'.','%2f'=>'/','%3a'=>':','%3b'=>';','%3c'=>'<','%3d'=>'=','%3e'=>'>','%3f'=>'?','%40'=>'@','%5b'=>'[','%5c'=>'\\','%5d'=>']','%5e'=>'^','%5f'=>'_','%60'=>'`','%7b'=>'{','%7c'=>'|','%7d'=>'}','%7e'=>'~'];  
15 - $url = mb_strtolower (\Yii::$app->request->url);  
16 -  
17 - $continue = true;  
18 -  
19 - foreach($array as $sym=>$sym_row){  
20 - if(strpos($url, $sym)){  
21 - $url = str_replace($sym, $sym_row, $url);  
22 - $continue = false;  
23 - 13 + if(\Yii::$app->request->isGet) {
  14 + \Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function($event) {
  15 + $array = ['%21'=>'!','%22'=>'"','%23'=>'#','%24'=>'$','%25'=>'%','%26'=>'&','%27'=>'\'','%28'=>'(','%29'=>')','%2a'=>'*','%2b'=>'+','%2c'=>',','%2d'=>'-','%2e'=>'.','%2f'=>'/','%3a'=>':','%3b'=>';','%3c'=>'<','%3d'=>'=','%3e'=>'>','%3f'=>'?','%40'=>'@','%5b'=>'[','%5c'=>'\\','%5d'=>']','%5e'=>'^','%5f'=>'_','%60'=>'`','%7b'=>'{','%7c'=>'|','%7d'=>'}','%7e'=>'~'];
  16 + $url = mb_strtolower (\Yii::$app->request->url);
  17 +
  18 + $continue = true;
  19 +
  20 + foreach($array as $sym=>$sym_row){
  21 + if(strpos($url, $sym)){
  22 + $url = str_replace($sym, $sym_row, $url);
  23 + $continue = false;
  24 +
  25 + }
24 } 26 }
25 - }  
26 -  
27 - if(!$continue){  
28 - \Yii::$app->getResponse()->redirect($url);  
29 - }  
30 -  
31 - }); 27 +
  28 + if(!$continue){
  29 + \Yii::$app->getResponse()->redirect($url);
  30 + }
  31 + });
  32 + }
  33 +
32 return $app; 34 return $app;
33 } 35 }
34 36
frontend/config/main.php
@@ -15,47 +15,47 @@ return [ @@ -15,47 +15,47 @@ return [
15 ], 15 ],
16 'controllerNamespace' => 'frontend\controllers', 16 'controllerNamespace' => 'frontend\controllers',
17 'modules' => [ 17 'modules' => [
18 - 'comment' => [  
19 - 'class' => 'common\modules\comment\Module',  
20 - 'useRbac' => false,  
21 - 'rbac' => [  
22 - 'rules' => [  
23 - \common\modules\comment\rbac\ArtboxCommentCreateRule::className(),  
24 - \common\modules\comment\rbac\ArtboxCommentDeleteRule::className(),  
25 - \common\modules\comment\rbac\ArtboxCommentUpdateRule::className(),  
26 - \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule::className(),  
27 - \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule::className(),  
28 - ],  
29 - 'permissions' => [  
30 - [  
31 - 'name' => common\modules\comment\Permissions::CREATE,  
32 - 'description' => 'Can create comments',  
33 - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentCreateRule())->name,  
34 - ],  
35 - [  
36 - 'name' => common\modules\comment\Permissions::UPDATE,  
37 - 'description' => 'Can update comments',  
38 - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateRule())->name,  
39 - ],  
40 - [  
41 - 'name' => common\modules\comment\Permissions::DELETE,  
42 - 'description' => 'Can delete comments',  
43 - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteRule())->name,  
44 - ],  
45 - [  
46 - 'name' => common\modules\comment\Permissions::UPDATE_OWN,  
47 - 'description' => 'Can update own comments',  
48 - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule())->name,  
49 - ],  
50 - [  
51 - 'name' => common\modules\comment\Permissions::DELETE_OWN,  
52 - 'description' => 'Can delete own comments',  
53 - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule())->name,  
54 - ],  
55 - ],  
56 - ],  
57 -  
58 - ], 18 +// 'comment' => [
  19 +// 'class' => 'common\modules\comment\Module',
  20 +// 'useRbac' => false,
  21 +// 'rbac' => [
  22 +// 'rules' => [
  23 +// \common\modules\comment\rbac\ArtboxCommentCreateRule::className(),
  24 +// \common\modules\comment\rbac\ArtboxCommentDeleteRule::className(),
  25 +// \common\modules\comment\rbac\ArtboxCommentUpdateRule::className(),
  26 +// \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule::className(),
  27 +// \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule::className(),
  28 +// ],
  29 +// 'permissions' => [
  30 +// [
  31 +// 'name' => common\modules\comment\Permissions::CREATE,
  32 +// 'description' => 'Can create comments',
  33 +// 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentCreateRule())->name,
  34 +// ],
  35 +// [
  36 +// 'name' => common\modules\comment\Permissions::UPDATE,
  37 +// 'description' => 'Can update comments',
  38 +// 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateRule())->name,
  39 +// ],
  40 +// [
  41 +// 'name' => common\modules\comment\Permissions::DELETE,
  42 +// 'description' => 'Can delete comments',
  43 +// 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteRule())->name,
  44 +// ],
  45 +// [
  46 +// 'name' => common\modules\comment\Permissions::UPDATE_OWN,
  47 +// 'description' => 'Can update own comments',
  48 +// 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule())->name,
  49 +// ],
  50 +// [
  51 +// 'name' => common\modules\comment\Permissions::DELETE_OWN,
  52 +// 'description' => 'Can delete own comments',
  53 +// 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule())->name,
  54 +// ],
  55 +// ],
  56 +// ],
  57 +//
  58 +// ],
59 ], 59 ],
60 'components' => [ 60 'components' => [
61 61
frontend/controllers/CatalogController.php
@@ -121,8 +121,8 @@ class CatalogController extends \yii\web\Controller @@ -121,8 +121,8 @@ class CatalogController extends \yii\web\Controller
121 /* 121 /*
122 * Greedy search for comments and rating 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 * End of greedy search for rating and comments 127 * End of greedy search for rating and comments
128 */ 128 */
frontend/controllers/SearchController.php 100644 → 100755
frontend/views/catalog/product.php
1 <?php 1 <?php
2 - use common\modules\comment\models\Comment;  
3 - use common\modules\comment\models\Rating; 2 +// use common\modules\comment\models\Comment;
  3 +// use common\modules\comment\models\Rating;
  4 +// use common\modules\comment\widgets\CommentWidget;
4 use common\modules\comment\widgets\CommentWidget; 5 use common\modules\comment\widgets\CommentWidget;
5 use kartik\rating\StarRating; 6 use kartik\rating\StarRating;
  7 + use yii\helpers\Html;
  8 + use yii\widgets\ActiveForm;
6 use yii\widgets\Breadcrumbs; 9 use yii\widgets\Breadcrumbs;
7 use yii\web\View; 10 use yii\web\View;
8 use yii\helpers\Url; 11 use yii\helpers\Url;
@@ -276,34 +279,11 @@ @@ -276,34 +279,11 @@
276 <div class="both"></div> 279 <div class="both"></div>
277 <div class="comment-wrapper"> 280 <div class="comment-wrapper">
278 <?php 281 <?php
279 - /*  
280 echo CommentWidget::widget([ 282 echo CommentWidget::widget([
281 - 'comment_class' => Comment::className(),  
282 - 'rating_class' => Rating::className(),  
283 - 'success_text' => 'Комментарий успешно добавлен и отобразится после проверки модератором',  
284 - 'class_options' => [  
285 - 'scenario' => \Yii::$app->user->isGuest ? Comment::SCENARIO_GUEST : Comment::SCENARIO_USER,  
286 - 'status' => Comment::STATUS_HIDDEN,  
287 - 'user_id' => \Yii::$app->user->isGuest ? NULL : \Yii::$app->user->id,  
288 - ],  
289 - 'model' => $product->className(),  
290 - 'model_id' => $product->product_id,  
291 - 'list_options' => [  
292 - 'view' => 'list-comment-review',  
293 - ],  
294 - 'form_options' => [  
295 - 'view' => 'form-comment-review',  
296 - 'tag' => 'span',  
297 - ],  
298 - 'options' => [  
299 - 'class' => 'proektant-comments-wr style',  
300 - 'id' => 'artbox-comment',  
301 - ], 283 + 'model' => $product,
302 ]); 284 ]);
303 - */  
304 ?> 285 ?>
305 </div> 286 </div>
306 -  
307 <?= \common\modules\product\widgets\similarProducts::widget([ 'product' => $product ]) ?> 287 <?= \common\modules\product\widgets\similarProducts::widget([ 'product' => $product ]) ?>
308 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'promo' ]) ?> 288 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'promo' ]) ?>
309 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'new' ]) ?> 289 <?= \common\modules\product\widgets\specialProducts::widget([ 'type' => 'new' ]) ?>
frontend/views/catalog/product_item.php
1 <?php 1 <?php
2 /** @var \common\modules\product\models\Product $product */ 2 /** @var \common\modules\product\models\Product $product */
3 - use common\modules\comment\assets\CommentAsset; 3 +// use common\modules\comment\assets\CommentAsset;
4 use yii\helpers\Html; 4 use yii\helpers\Html;
5 use yii\helpers\Url; 5 use yii\helpers\Url;
6 6
7 - CommentAsset::register($this); 7 +// CommentAsset::register($this);
8 ?> 8 ?>
9 <li class="item" itemscope itemtype="http://schema.org/Product"> 9 <li class="item" itemscope itemtype="http://schema.org/Product">
10 <div class="boxitem"> 10 <div class="boxitem">