diff --git a/backend/config/main.php b/backend/config/main.php index bfbdccd..dd88716 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -158,12 +158,9 @@ return [ 'product/manage/' => 'product/manage/', 'product////' => 'product//', 'product////' => 'product//', - 'product//' => 'product/', 'seo-dynamic///' => 'seo-dynamic/', 'seo-dynamic//' => 'seo-dynamic/', - - ] ] diff --git a/backend/controllers/CommentController.php b/backend/controllers/CommentController.php new file mode 100644 index 0000000..1023d5c --- /dev/null +++ b/backend/controllers/CommentController.php @@ -0,0 +1,159 @@ +[ + 'class' => AccessBehavior::className(), + 'rules' => + ['site' => + [ + [ + 'actions' => ['login', 'error'], + 'allow' => true, + ] + ] + ] + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Comment models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CommentSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $query = $dataProvider->query; + $query->with(['rating', 'user']); + $sort = $dataProvider->sort; + $sort->defaultOrder = [ + 'status' => SORT_ASC, + ]; + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Comment model. + * @param integer $id + * @return mixed + */ +// public function actionView($id) +// { +// return $this->render('view', [ +// 'model' => $this->findModel($id), +// ]); +// } + + /** + * Creates a new Comment model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ +// public function actionCreate() +// { +// $model = new Comment(); +// +// if ($model->load(Yii::$app->request->post()) && $model->save()) { +// return $this->redirect(['view', 'id' => $model->comment_id]); +// } else { +// return $this->render('create', [ +// 'model' => $model, +// ]); +// } +// } + + /** + * Updates an existing Comment model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->comment_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + public function actionApprove($id) { + $model = $this->findModel($id); + $model->status = Comment::STATUS_ACTIVE; + $model->save(false); + + return $this->redirect(['index']); + } + + public function actionDisapprove($id) { + $model = $this->findModel($id); + $model->status = Comment::STATUS_HIDDEN; + $model->save(false); + + return $this->redirect(['index']); + } + + /** + * Deletes an existing Comment model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Comment model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Comment the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Comment::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/CommentSearch.php b/backend/models/CommentSearch.php new file mode 100644 index 0000000..cb831de --- /dev/null +++ b/backend/models/CommentSearch.php @@ -0,0 +1,79 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'comment_id' => $this->comment_id, + 'user_id' => $this->user_id, + 'comment_pid' => $this->comment_pid, + 'status' => $this->status, + 'date_add' => $this->date_add, + 'date_update' => $this->date_update, + 'date_delete' => $this->date_delete, + 'model_id' => $this->model_id, + ]); + + $query->andFilterWhere(['like', 'text', $this->text]) + ->andFilterWhere(['like', 'user_name', $this->user_name]) + ->andFilterWhere(['like', 'user_email', $this->user_email]) + ->andFilterWhere(['like', 'model', $this->model]); + + return $dataProvider; + } +} diff --git a/backend/views/comment/_form.php b/backend/views/comment/_form.php new file mode 100644 index 0000000..efe6e86 --- /dev/null +++ b/backend/views/comment/_form.php @@ -0,0 +1,33 @@ + 'Активный', + Comment::STATUS_HIDDEN => 'Новый', + Comment::STATUS_DELETED => 'Удаленный', + ] +?> + +
+ + + + field($model, 'text') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'status') + ->dropDownList($status_list) ?> + +
+ 'btn btn-primary' ]) ?> +
+ + + +
diff --git a/backend/views/comment/_search.php b/backend/views/comment/_search.php new file mode 100644 index 0000000..a61526e --- /dev/null +++ b/backend/views/comment/_search.php @@ -0,0 +1,49 @@ + + + diff --git a/backend/views/comment/index.php b/backend/views/comment/index.php new file mode 100644 index 0000000..3514c68 --- /dev/null +++ b/backend/views/comment/index.php @@ -0,0 +1,99 @@ +title = 'Комменты'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ + $dataProvider, + 'columns' => [ + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{approve} {update} {delete}', + 'buttons' => [ + 'approve' => function($url, $model, $key) { + /** + * @var Comment $model + */ + $options = array_merge([ + 'title' => "Подтвердить", + 'aria-label' => "Подтвердить", + 'data-confirm' => "Комментарий и оценка отобразится на публичной части сайта, подтвердить?", + 'data-method' => 'post', + 'data-pjax' => '0', + ]); + $glyphicon = 'glyphicon-ok'; + if($model->status == $model::STATUS_ACTIVE) { + $url = Url::to(['comment/disapprove', 'id' => $model->comment_id]); + $glyphicon = 'glyphicon-remove'; + } + return Html::a('', $url, $options); + } + ] + ], + 'comment_id', + [ + 'attribute' => 'rating.value', + 'label' => 'Оценка', + ], + 'text:ntext', + [ + 'content' => function($model) { + /** + * @var Comment $model + */ + if(!empty( $model->user )) { + return $model->user->username . " (ID: " . $model->user->id . ")"; + } else { + return $model->user_name . " (Гость: " . $model->user_email . ")"; + } + }, + 'label' => 'Пользователь', + ], + [ + 'attribute' => 'status', + 'value' => function($model) { + /** + * @var Comment $model + */ + $status = ''; + switch($model->status) { + case Comment::STATUS_ACTIVE: + $status = 'Активный'; + break; + case Comment::STATUS_HIDDEN: + $status = 'Новый'; + break; + case Comment::STATUS_DELETED: + $status = 'Удаленный'; + break; + default: + $status = 'Неизвестно'; + }; + return $status; + }, + ], + 'date_add', + [ + 'attribute' => 'model', + 'value' => function($model) { + /** + * @var Comment $model + */ + return $model->model . " (ID: " . $model->model_id . ")"; + }, + ], + ], + ]); ?> +
diff --git a/backend/views/comment/update.php b/backend/views/comment/update.php new file mode 100644 index 0000000..3c96c8f --- /dev/null +++ b/backend/views/comment/update.php @@ -0,0 +1,21 @@ +title = 'Редактировать коммент: ' . $model->comment_id; +$this->params['breadcrumbs'][] = ['label' => 'Комментарии', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->comment_id, 'url' => ['view', 'id' => $model->comment_id]]; +$this->params['breadcrumbs'][] = 'Редактировать'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/comment/view.php b/backend/views/comment/view.php new file mode 100644 index 0000000..1af38ca --- /dev/null +++ b/backend/views/comment/view.php @@ -0,0 +1,46 @@ +title = $model->comment_id; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->comment_id], ['class' => 'btn btn-primary']) ?> + $model->comment_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'comment_id', + 'text:ntext', + 'user_id', + 'user_name', + 'user_email:email', + 'comment_pid', + 'status', + 'date_add', + 'date_update', + 'date_delete', + 'model', + 'model_id', + ], + ]) ?> + +
diff --git a/common/config/main.php b/common/config/main.php index 5264dff..3dded74 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -353,46 +353,5 @@ return [ ]*/ ] ], - 'comment' => [ - 'class' => 'common\modules\comment\Module', - 'useRbac' => false, - 'rbac' => [ - 'rules' => [ - \common\modules\comment\rbac\ArtboxCommentCreateRule::className(), - \common\modules\comment\rbac\ArtboxCommentDeleteRule::className(), - \common\modules\comment\rbac\ArtboxCommentUpdateRule::className(), - \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule::className(), - \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule::className(), - ], - 'permissions' => [ - [ - 'name' => common\modules\comment\Permissions::CREATE, - 'description' => 'Can create comments', - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentCreateRule())->name, - ], - [ - 'name' => common\modules\comment\Permissions::UPDATE, - 'description' => 'Can update comments', - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateRule())->name, - ], - [ - 'name' => common\modules\comment\Permissions::DELETE, - 'description' => 'Can delete comments', - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteRule())->name, - ], - [ - 'name' => common\modules\comment\Permissions::UPDATE_OWN, - 'description' => 'Can update own comments', - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule())->name, - ], - [ - 'name' => common\modules\comment\Permissions::DELETE_OWN, - 'description' => 'Can delete own comments', - 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule())->name, - ], - ], - ], - - ], ], ]; diff --git a/common/modules/comment/assets/CommentAsset.php b/common/modules/comment/assets/CommentAsset.php index 1167f8d..e330a34 100755 --- a/common/modules/comment/assets/CommentAsset.php +++ b/common/modules/comment/assets/CommentAsset.php @@ -1,26 +1,28 @@ \yii\web\View::POS_HEAD, ]; - + } \ No newline at end of file diff --git a/common/modules/comment/resources/comment.css b/common/modules/comment/resources/comment.css index e1b0a58..e475a3d 100755 --- a/common/modules/comment/resources/comment.css +++ b/common/modules/comment/resources/comment.css @@ -220,7 +220,8 @@ /***proektant_comments***/ ul.proektant-comments { - margin-top: 15px + margin-top: 15px; + padding-left: 0; } .proektant-comments li { @@ -235,6 +236,8 @@ ul.proektant-comments { .proektant-comments .pagination li { width: auto; margin-top: 0; + float: none; + border-bottom: none; } .proektant-comments li:first-child { diff --git a/common/modules/comment/resources/delete.gif b/common/modules/comment/resources/delete.gif new file mode 100644 index 0000000..43c6ca8 Binary files /dev/null and b/common/modules/comment/resources/delete.gif differ diff --git a/common/modules/comment/resources/jquery.rateit.min.js b/common/modules/comment/resources/jquery.rateit.min.js new file mode 100644 index 0000000..08f83d8 --- /dev/null +++ b/common/modules/comment/resources/jquery.rateit.min.js @@ -0,0 +1,7 @@ +/*! RateIt | v1.0.24 / 06/14/2016 + https://github.com/gjunge/rateit.js | Twitter: @gjunge +*/ +(function(n){function t(n){var u=n.originalEvent.changedTouches,t=u[0],i="",r;switch(n.type){case"touchmove":i="mousemove";break;case"touchend":i="mouseup";break;default:return}r=document.createEvent("MouseEvent");r.initMouseEvent(i,!0,!0,window,1,t.screenX,t.screenY,t.clientX,t.clientY,!1,!1,!1,!1,0,null);t.target.dispatchEvent(r);n.preventDefault()}n.rateit={aria:{resetLabel:"reset rating",ratingLabel:"rating"}};n.fn.rateit=function(i,r){var e=1,u={},o="init",s=function(n){return n.charAt(0).toUpperCase()+n.substr(1)},f;if(this.length===0)return this;if(f=n.type(i),f=="object"||i===undefined||i===null)u=n.extend({},n.fn.rateit.defaults,i);else{if(f=="string"&&i!=="reset"&&r===undefined)return this.data("rateit"+s(i));f=="string"&&(o="setvalue")}return this.each(function(){var c=n(this),f=function(n,t){if(t!=null){var i="aria-value"+(n=="value"?"now":n),r=c.find(".rateit-range");r.attr(i)!=undefined&&r.attr(i,t)}return arguments[0]="rateit"+s(n),c.data.apply(c,arguments)},p,w,v,h,b,g,nt,l,y,k,a;if(i=="reset"){p=f("init");for(w in p)c.data(w,p[w]);f("backingfld")&&(h=n(f("backingfld")),h.val(f("value")),h.trigger("change"),h[0].min&&(h[0].min=f("min")),h[0].max&&(h[0].max=f("max")),h[0].step&&(h[0].step=f("step")));c.trigger("reset")}if(c.hasClass("rateit")||c.addClass("rateit"),v=c.css("direction")!="rtl",o=="setvalue"){if(!f("init"))throw"Can't set value before init";i!="readonly"||r!=!0||f("readonly")||(c.find(".rateit-range").unbind(),f("wired",!1));i=="value"&&(r=r==null?f("min"):Math.max(f("min"),Math.min(f("max"),r)));f("backingfld")&&(h=n(f("backingfld")),i=="value"&&h.val(r),i=="min"&&h[0].min&&(h[0].min=r),i=="max"&&h[0].max&&(h[0].max=r),i=="step"&&h[0].step&&(h[0].step=r));f(i,r)}f("init")||(f("min",isNaN(f("min"))?u.min:f("min")),f("max",isNaN(f("max"))?u.max:f("max")),f("step",f("step")||u.step),f("readonly",f("readonly")!==undefined?f("readonly"):u.readonly),f("resetable",f("resetable")!==undefined?f("resetable"):u.resetable),f("backingfld",f("backingfld")||u.backingfld),f("starwidth",f("starwidth")||u.starwidth),f("starheight",f("starheight")||u.starheight),f("value",Math.max(f("min"),Math.min(f("max"),isNaN(f("value"))?isNaN(u.value)?u.min:u.value:f("value")))),f("ispreset",f("ispreset")!==undefined?f("ispreset"):u.ispreset),f("backingfld")&&(h=n(f("backingfld")).hide(),(h.attr("disabled")||h.attr("readonly"))&&f("readonly",!0),h[0].nodeName=="INPUT"&&(h[0].type=="range"||h[0].type=="text")&&(f("min",parseInt(h.attr("min"))||f("min")),f("max",parseInt(h.attr("max"))||f("max")),f("step",parseInt(h.attr("step"))||f("step"))),h[0].nodeName=="SELECT"&&h[0].options.length>1?(f("min",isNaN(f("min"))?Number(h[0].options[0].value):f("min")),f("max",Number(h[0].options[h[0].length-1].value)),f("step",Number(h[0].options[1].value)-Number(h[0].options[0].value)),b=h.find("option[selected]"),b.length==1&&f("value",b.val())):f("value",h.val())),g=c[0].nodeName=="DIV"?"div":"span",e++,nt='