From 4214a8e62808cade3588ae1485dfa806bb753d97 Mon Sep 17 00:00:00 2001 From: timur Date: Mon, 12 Mar 2018 14:40:45 +0200 Subject: [PATCH] admin feedback --- backend/config/main.php | 1 - backend/controllers/FeedbackController.php | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/feedback/_form.php | 33 +++++++++++++++++++++++++++++++++ backend/views/feedback/_search.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ backend/views/feedback/create.php | 21 +++++++++++++++++++++ backend/views/feedback/index.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/feedback/update.php | 23 +++++++++++++++++++++++ backend/views/feedback/view.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 backend/controllers/FeedbackController.php create mode 100644 backend/views/feedback/_form.php create mode 100644 backend/views/feedback/_search.php create mode 100644 backend/views/feedback/create.php create mode 100644 backend/views/feedback/index.php create mode 100644 backend/views/feedback/update.php create mode 100644 backend/views/feedback/view.php diff --git a/backend/config/main.php b/backend/config/main.php index 1c68330..73a499d 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -25,7 +25,6 @@ 'page-category' => 'artbox\core\controllers\PageCategoryController', 'alias' => 'artbox\core\seo\controllers\AliasController', 'seo' => 'artbox\core\controllers\SeoController', - 'feedback' => 'artbox\core\controllers\FeedbackController', 'blog' => 'artbox\weblog\controllers\ArticleController', 'blog-category' => 'artbox\weblog\controllers\CategoryController', 'blog-tag' => 'artbox\weblog\controllers\TagController', diff --git a/backend/controllers/FeedbackController.php b/backend/controllers/FeedbackController.php new file mode 100644 index 0000000..6d4c51d --- /dev/null +++ b/backend/controllers/FeedbackController.php @@ -0,0 +1,192 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Feedback models. + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider( + [ + 'query' => Feedback::find()->orderBy('created_at DESC'), + ] + ); + + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Displays a single Feedback model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + $model = $this->findModel($id); + + $model->status = true; + $model->save(false, [ 'status' ]); + + return $this->render( + 'view', + [ + 'model' => $model, + ] + ); + } + + /** + * Creates a new Feedback model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Feedback(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Feedback 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); + + $model->status = true; + $model->save(false, [ 'status' ]); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Feedback 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 Feedback model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Feedback the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Feedback::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function actionViewed($id) + { + if (Yii::$app->request->isPost) { + $model = $this->findModel($id); + + Yii::$app->response->format = Response::FORMAT_JSON; + + $model->status = true; + if ($model->save(false, [ 'status' ])) { + + $widget = FeedbackWidget::widget(); + + return [ + 'text' => Html::tag( + 'span', + '', + [ + 'class' => 'glyphicon glyphicon-ok', + ] + ), + 'message' => [ + 'title' => Yii::t('core', 'Notification') . ':', + 'text' => Yii::t('core', 'Status changed'), + ], + 'widget' => $widget, + ]; + } + } + return []; + } + +} diff --git a/backend/views/feedback/_form.php b/backend/views/feedback/_form.php new file mode 100644 index 0000000..9052da4 --- /dev/null +++ b/backend/views/feedback/_form.php @@ -0,0 +1,33 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'email')->textInput(['maxlength' => true]) ?> + + field($model, 'phone')->textInput(['maxlength' => true]) ?> + + field($model, 'message')->textarea(['rows' => 6]) ?> + + field($model, 'status')->checkbox() ?> + + field($model, 'topic')->textInput(['maxlength' => true]) ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/feedback/_search.php b/backend/views/feedback/_search.php new file mode 100644 index 0000000..9401a8d --- /dev/null +++ b/backend/views/feedback/_search.php @@ -0,0 +1,47 @@ + + + diff --git a/backend/views/feedback/create.php b/backend/views/feedback/create.php new file mode 100644 index 0000000..ee50797 --- /dev/null +++ b/backend/views/feedback/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Feedback'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/feedback/index.php b/backend/views/feedback/index.php new file mode 100644 index 0000000..8e15166 --- /dev/null +++ b/backend/views/feedback/index.php @@ -0,0 +1,82 @@ +title = Yii::t('app', 'Feedbacks'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'rowOptions' => function (Feedback $model) { + if ($model->status) { + return []; + } else { + return [ + 'class' => 'success', + ]; + } + }, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'topic', + 'name', + 'email:email', + 'phone', + [ + 'attribute' => 'created_at', + 'format' => [ + 'datetime', + 'php:d.m.Y H:i', + ], + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'buttons' => [ + 'viewed' => function (string $url, Feedback $model) { + if ($model->status) { + return Html::tag( + 'span', + '', + [ + 'class' => 'glyphicon glyphicon-ok', + ] + ); + } else { + return Html::a( + Html::tag( + 'span', + '', + [ + 'class' => 'glyphicon glyphicon-flag', + ] + ), + $url, + [ + 'class' => 'viewed-toggle', + ] + ); + } + }, + ], + 'template' => '{viewed} {view} {update} {delete}', + ], + ], + ]); ?> diff --git a/backend/views/feedback/update.php b/backend/views/feedback/update.php new file mode 100644 index 0000000..192e611 --- /dev/null +++ b/backend/views/feedback/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Feedback', +]) . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> + diff --git a/backend/views/feedback/view.php b/backend/views/feedback/view.php new file mode 100644 index 0000000..9ead6a9 --- /dev/null +++ b/backend/views/feedback/view.php @@ -0,0 +1,77 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + -- libgit2 0.21.4