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 @@ + + +
+ = Html::a(Yii::t('app', 'Create Feedback'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $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'); +?> ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'email:email', + 'phone', + 'message:ntext', + 'created_at', + 'ip', + 'url:url', + 'status:boolean', + 'topic', + [ + 'attribute' => 'calc_json_info', + 'label' => 'calculation info', + 'value' => function(\common\models\Feedback $model, $widget) { + + return json_decode($model->calc_json_info, true); + + }, + ], + ], + 'template' => function ($attribute, $index, $widget){ + if( + $attribute['attribute'] === 'calc_json_info' && + !is_null($attribute['value']) + ){ + $result = ''; + foreach ($attribute['value'] as $attr => $value){ + $result .= "