diff --git a/.gitignore b/.gitignore index 7773b6d..5ac7134 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/frontend/web/js/Validation.ts +/frontend/web/js/typescript.ts /node_modules # yii console command /yii diff --git a/common/modules/comment/interfaces/CommentInterface.php b/common/modules/comment/interfaces/CommentInterface.php index 471dddf..352c423 100644 --- a/common/modules/comment/interfaces/CommentInterface.php +++ b/common/modules/comment/interfaces/CommentInterface.php @@ -4,7 +4,7 @@ interface CommentInterface { public function load($data, $formName = null); public function formName(); - public function getComments($model, $model_id); + public static function getComments($model, $model_id); public function postComment(); public function deleteComment(); public function updateComment(); diff --git a/common/modules/comment/models/Comment.php b/common/modules/comment/models/Comment.php index 24cf9bb..a1fe7f5 100644 --- a/common/modules/comment/models/Comment.php +++ b/common/modules/comment/models/Comment.php @@ -173,9 +173,9 @@ * * @return ActiveQuery */ - public function getComments($model, $model_id) + public static function getComments($model, $model_id) { - return $this->find() + return self::find() ->where([ 'comment.model' => $model, 'comment.model_id' => $model_id, @@ -258,8 +258,9 @@ return true; } else { return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [ - 'model' => $this->model, - 'model_id' => $this->model_id, + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment_model' => $this, ]); } } @@ -333,11 +334,11 @@ public function getAuthor($guestMark = '') { - if(!empty($this->user)) { + if(!empty( $this->user )) { return $this->user->name; } else { $name = $this->user_name; - if(!empty($guestMark)) { + if(!empty( $guestMark )) { $name .= $guestMark; } return $name; @@ -395,8 +396,13 @@ return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); } - public function buildButtons($buttons = ['delete', 'update', 'reply']) - { + public function buildButtons( + $buttons = [ + 'delete', + 'update', + 'reply', + ] + ) { if(in_array('delete', $buttons)) { if($this->checkDelete()) { $this->buttons[ 'delete' ] = Url::to([ diff --git a/common/modules/comment/models/CommentProject.php b/common/modules/comment/models/CommentProject.php index 20411d9..f1cd1ec 100644 --- a/common/modules/comment/models/CommentProject.php +++ b/common/modules/comment/models/CommentProject.php @@ -222,7 +222,7 @@ * * @return ActiveQuery */ - public function getComments($model, $model_id) + public static function getComments($model, $model_id) { /** * @var User $user @@ -231,7 +231,7 @@ if(!empty($user)) { $project = Project::findOne($model_id); if(!empty($project) && $user->id == $project->user_id) { - return $this->find() + return self::find() ->where([ 'comment_project.model' => $model, 'comment_project.model_id' => $model_id, @@ -240,7 +240,7 @@ ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments'); } } - $query = $this->find() + $query = self::find() ->where([ 'comment_project.model' => $model, 'comment_project.model_id' => $model_id, diff --git a/common/modules/comment/models/CommentProjectAnswer.php b/common/modules/comment/models/CommentProjectAnswer.php new file mode 100644 index 0000000..e8f9ec6 --- /dev/null +++ b/common/modules/comment/models/CommentProjectAnswer.php @@ -0,0 +1,174 @@ + 1, + ], + [ + [ 'comment_pid' ], + 'exist', + 'targetAttribute' => 'comment_id', + 'filter' => [ + 'model' => $this->model, + 'model_id' => $this->model_id, + ], + ], + ]; + } + + /** + * @param string $model + * @param integer $model_id + * + * @return ActiveQuery + */ + public static function getComments($model, $model_id) + { + $query = self::find() + ->where([ + 'comment.model' => $model, + 'comment.model_id' => $model_id, + 'comment.status' => 1, + 'comment.comment_pid' => NULL, + ]) + ->with('parent'); + $project = Project::findOne($model_id); + $user = \Yii::$app->user; + if(empty( $user ) || $project->user_id != $user->id) { + $query->innerJoin([ 'child' => 'comment' ], 'comment.comment_id = child.comment_pid') + ->andWhere([ + 'not', + [ 'child.comment_id' => NULL ], + ]); + } + return $query; + } + + public function checkCreate() + { + if($this->getGuestComment()) { + return true; + } else { + return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, [ + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment_model' => $this, + ]); + } + } + + public function checkUpdate() + { + if($this->scenario == self::SCENARIO_GUEST) { + return false; + } else { + return \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE, [ + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment' => $this, + ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::UPDATE_OWN, [ + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment' => $this, + ]); + } + } + + public function checkDelete() + { + if($this->scenario == self::SCENARIO_GUEST) { + return false; + } else { + return ( \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE, [ + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment' => $this, + ]) || \Yii::$app->user->can(\common\modules\comment\Permissions::DELETE_OWN, [ + 'model' => $this->model, + 'model_id' => $this->model_id, + 'comment' => $this, + ]) ); + } + } + + public function checkReply() + { + if($this->scenario != self::SCENARIO_GUEST) { + if(!$this->isNewRecord && empty( $this->comment_pid )) { + $project = Project::findOne($this->model_id); + if($project->user_id == \Yii::$app->user->id) { + return true; + } + } + } + return false; + } + + public function getChild() + { + return $this->hasOne($this->className(), [ 'comment_pid' => 'comment_id' ]); + } + + } diff --git a/common/modules/comment/rbac/ArtboxCommentCreateRule.php b/common/modules/comment/rbac/ArtboxCommentCreateRule.php index 9dbf0a3..10397bc 100644 --- a/common/modules/comment/rbac/ArtboxCommentCreateRule.php +++ b/common/modules/comment/rbac/ArtboxCommentCreateRule.php @@ -2,6 +2,7 @@ namespace common\modules\comment\rbac; + use common\modules\comment\models\CommentProject; use yii\rbac\Rule; class ArtboxCommentCreateRule extends Rule @@ -11,7 +12,7 @@ public function execute($user, $item, $params) { - if($params[ 'model' ] == \common\models\Project::className()) { + if($params[ 'model' ] == \common\models\Project::className() && !empty($params['comment_model']) && $params['comment_model'] == CommentProject::className()) { return $this->checkProject($user, $item, $params); } return true; diff --git a/common/modules/comment/widgets/CommentWidget.php b/common/modules/comment/widgets/CommentWidget.php index 726bf94..bd7b278 100644 --- a/common/modules/comment/widgets/CommentWidget.php +++ b/common/modules/comment/widgets/CommentWidget.php @@ -57,6 +57,8 @@ */ public $class_options = [ ]; + public $provider_options = [ ]; + /** * @var bool Wheather to display comment list */ @@ -76,6 +78,7 @@ * @var bool Whether to allow one user post multiple comments */ public $allow_multiple = true; + public $allow_reply = true; /** @@ -197,10 +200,10 @@ if($this->display_comment_form && $this->comment_class->checkCreate()) { $tag = ArrayHelper::remove($this->form_options, 'tag', 'div'); $view = ArrayHelper::remove($this->form_options, 'view'); - if(!empty($this->form_options['class'])) { - $this->form_options['class'] .= ' '.self::$baseClass['form_container']; + if(!empty( $this->form_options[ 'class' ] )) { + $this->form_options[ 'class' ] .= ' ' . self::$baseClass[ 'form_container' ]; } else { - $this->form_options['class'] = self::$baseClass['form_container']; + $this->form_options[ 'class' ] = self::$baseClass[ 'form_container' ]; } $this->parts[ 'form' ] = Html::tag($tag, $this->renderForm($view), $this->form_options); } @@ -209,15 +212,15 @@ public function createDataProvider() { $this->dataProvider = new \yii\data\ActiveDataProvider([ - 'query' => $this->comment_class->getComments($this->model, $this->model_id), - 'sort' => new Sort([ + 'query' => ArrayHelper::remove($this->provider_options, 'query', $this->comment_class->getComments($this->model, $this->model_id)), + 'sort' => ArrayHelper::remove($this->provider_options, 'sort', new Sort([ 'defaultOrder' => [ 'date_add' => SORT_DESC, ], - ]), - 'pagination' => [ + ])), + 'pagination' => ArrayHelper::remove($this->provider_options, 'query', [ 'pageSize' => 10, - ], + ]), ]); } @@ -258,10 +261,10 @@ $template = preg_replace('/{list}/', ArrayHelper::remove($parts, 'list', ''), $template); $template = preg_replace('/{form}/', ArrayHelper::remove($parts, 'form', ''), $template); $tag = ArrayHelper::remove($options, 'tag', 'div'); - if(!empty($options['class'])) { - $options['class'] .= ' '.self::$baseClass['widget_container']; + if(!empty( $options[ 'class' ] )) { + $options[ 'class' ] .= ' ' . self::$baseClass[ 'widget_container' ]; } else { - $options['class'] = self::$baseClass['widget_container']; + $options[ 'class' ] = self::$baseClass[ 'widget_container' ]; } return Html::tag($tag, $template, $options); } diff --git a/common/modules/comment/widgets/views/_question_comment_view.php b/common/modules/comment/widgets/views/_question_comment_view.php new file mode 100644 index 0000000..5ec0ceb --- /dev/null +++ b/common/modules/comment/widgets/views/_question_comment_view.php @@ -0,0 +1,61 @@ +user; + $model->buildButtons(['reply']); +?> +
+ getAuthor(' (Гость)') ?> +
+ +
Pro
+ +
formatter->asDate($model->date_add, 'php:d.m.Y') ?>
+
+ text ?> +
+
+ buttons[ 'delete' ] )) { + echo Html::a(($model->user_id != NULL && $model->user_id == \Yii::$app->user->id)?'Удалить':'Пожаловаться ', $model->buttons[ 'delete' ], [ 'class' => CommentWidget::$baseClass[ 'comment_delete' ] ]); + } + if(!empty( $model->buttons[ 'update' ] )) { + echo Html::a('Редактировать', $model->buttons[ 'update' ], [ 'class' => CommentWidget::$baseClass[ 'comment_update' ] ]); + } + if(!empty( $model->buttons[ 'reply' ] )) { + echo Html::a('Ответить', $model->buttons[ 'reply' ], [ 'class' => CommentWidget::$baseClass[ 'comment_reply' ] ]); + } + ?> +
+isNewRecord) { + $this->registerJs("$('div.rating').rating( + { + fx : 'full', readOnly : 'true', url : 'rating.php' + } + );"); + } +?> + + + \ No newline at end of file diff --git a/common/modules/comment/widgets/views/form-comment-answer.php b/common/modules/comment/widgets/views/form-comment-answer.php new file mode 100644 index 0000000..43ec915 --- /dev/null +++ b/common/modules/comment/widgets/views/form-comment-answer.php @@ -0,0 +1,60 @@ + +
Вопросов: totalCount ?>
+ +
+ + scenario == $model::SCENARIO_GUEST) { + echo $form->field($model, 'user_name', [ + 'options' => [ + 'class' => 'input-blocks-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-input-4', + ], + ]) + ->textInput(); + echo $form->field($model, 'user_email', [ + 'options' => [ + 'class' => 'input-blocks-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-input-4', + ], + ]) + ->textInput(); + } + + ?> +
+ field($model, 'text', [ + 'options' => [ + 'class' => 'input-blocks-comm area-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-area-4', + ], + ]) + ->label('Вопрос') + ->textarea(); + ?> +
+ +
+ end(); + ?> +
\ No newline at end of file diff --git a/common/modules/comment/widgets/views/form-comment-review.php b/common/modules/comment/widgets/views/form-comment-review.php index 147c598..727dfbc 100644 --- a/common/modules/comment/widgets/views/form-comment-review.php +++ b/common/modules/comment/widgets/views/form-comment-review.php @@ -38,6 +38,16 @@ 3 => 3, 4 => 4, 5 => 5, + ], [ + 'item' => function($index, $label, $name, $checked, $value) { + $return = '
'; + $return .= ''; + $return .= ''; + $return .= '
'; + return $return; + }, ]); if($model->scenario == $model::SCENARIO_GUEST) { echo $form->field($model, 'user_name', [ @@ -62,7 +72,7 @@ if(!empty( $model->comment_pid )) { echo Html::tag('div', Html::activeHiddenInput($model, 'comment_pid') . Html::tag('p', $model->parent->authorName, [ 'class' => 'artbox_comment_reply_author' ]), [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] ]); } else { - echo Html::tag('div', '', [ 'class' => CommentWidget::$baseClass[ 'reply_block' ] ]); + echo Html::tag('div', '', [ 'class' => CommentWidget::$baseClass[ 'reply_block' ].' test_class' ]); } echo $form->field($model, 'text', [ 'options' => [ diff --git a/common/modules/comment/widgets/views/list-comment-question.php b/common/modules/comment/widgets/views/list-comment-question.php new file mode 100644 index 0000000..0c42b1d --- /dev/null +++ b/common/modules/comment/widgets/views/list-comment-question.php @@ -0,0 +1,23 @@ + $dataProvider, + 'itemView' => '_question_comment_view', + 'options' => [ + 'tag' => 'ul', + 'class' => 'proektant-comments style', + ], + 'itemOptions' => [ + 'tag' => 'li', + 'class' => CommentWidget::$baseClass[ 'comment_container' ], + 'data' => [ + 'form' => $commentClass->formName(), + ], + ], + 'layout' => "{items}\n{pager}", + ]); \ No newline at end of file diff --git a/frontend/views/tender/view.php b/frontend/views/tender/view.php index 0182e55..16491a1 100755 --- a/frontend/views/tender/view.php +++ b/frontend/views/tender/view.php @@ -5,6 +5,7 @@ * @var Project $model */ use common\models\Project; + use common\modules\comment\models\Comment; use \yii\helpers\Html; use yii\helpers\Url; use yii\web\View; @@ -224,6 +225,30 @@ $this->title = 'My Yii Application'; $this, + 'model' => $model->className(), + 'model_id' => $model->project_id, + 'comment_class' => \common\modules\comment\models\CommentProjectAnswer::className(), + 'class_options' => [ + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST, + 'user_id' => \Yii::$app->user->getId(), + 'guestComment' => false, + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE, + ], + 'list_options' => [ + 'view' => 'list-comment-question', + ], + 'form_options' => [ + 'view' => 'form-comment-answer', + 'tag' => 'span', + ], + 'options' => [ + 'class' => 'proektant-comments-wr style', + ], + ]); + ?> + $this, 'model' => $model::className(), 'model_id' => $model->project_id, 'comment_class' => \common\modules\comment\models\CommentProject::className(), -- libgit2 0.21.4