From 5531f04daf11e4b1f7deab8f3b1fefd982f592b6 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Tue, 19 Jun 2018 17:53:26 +0300 Subject: [PATCH] comments in admin --- backend/controllers/CommentController.php | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/comment/_form.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/comment/update.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ backend/views/layouts/menu_items.php | 5 +++++ 4 files changed, 254 insertions(+), 0 deletions(-) create mode 100644 backend/controllers/CommentController.php create mode 100644 backend/views/comment/_form.php create mode 100644 backend/views/comment/update.php diff --git a/backend/controllers/CommentController.php b/backend/controllers/CommentController.php new file mode 100644 index 0000000..1fc6459 --- /dev/null +++ b/backend/controllers/CommentController.php @@ -0,0 +1,145 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'name' => [ + 'type' => Index::ACTION_COL, + ], + 'email' => [ + 'type' => Index::STRING_COL + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + 'created_at' => [ + 'type' => Index::DATETIME_COL, + ] + ], + 'model' => Comment::className(), + 'hasLanguage' => false, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + 'defaultSort' => [ + 'created_at' => 'DESC', + ], + 'create' => false + ], + 'view' => [ + 'class' => View::className(), + 'model' => Comment::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + ], + 'fields' => [ + [ + 'name' => 'name', + 'type' => Form::STRING, + ], + [ + 'name' => 'email', + 'type' => Form::STRING, + ], + [ + 'name' => 'comment', + 'type' => Form::TEXTAREA, + ], + [ + 'name' => 'created_at', + 'type' => Form::STRING, + ], + + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + + $model = Comment::find() + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function deleteModel($id) + { + $category = Comment::find() + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + + return $category->delete(); + } + + public function actionUpdate($id) + { + $model = $this->findModel($id); + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } else { + return $this->render( + 'update', + [ + 'model' => $model, + ] + ); + } + } + } \ No newline at end of file diff --git a/backend/views/comment/_form.php b/backend/views/comment/_form.php new file mode 100644 index 0000000..268da67 --- /dev/null +++ b/backend/views/comment/_form.php @@ -0,0 +1,59 @@ +registerJs($js, View::POS_READY); + +?> + +
+ + + book->title?> + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'email') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'comment') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'status') + ->checkbox( + [ + 'class' => 'switchery', + ] + ) ?> + +
+ isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + + +
diff --git a/backend/views/comment/update.php b/backend/views/comment/update.php new file mode 100644 index 0000000..0188871 --- /dev/null +++ b/backend/views/comment/update.php @@ -0,0 +1,45 @@ +title = Yii::t( + 'app', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Comment', + ] + ) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Comments'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); +?> + + $this->title, + 'options' => [ + 'class' => 'x_panel comment-update', + ], + ] +) ?> + +render( + '_form', + [ + 'model' => $model, + ] +) ?> + + diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index 4275f83..b81c637 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -55,6 +55,11 @@ 'url' => [ '/author/index' ], ], + [ + 'label' => \Yii::t('app', 'Comments'), + 'url' => [ '/comment/index' ], + + ], ], ], -- libgit2 0.21.4