Commit 4214a8e62808cade3588ae1485dfa806bb753d97
1 parent
14bb41a7
admin feedback
Showing
8 changed files
with
475 additions
and
1 deletions
Show diff stats
backend/config/main.php
... | ... | @@ -25,7 +25,6 @@ |
25 | 25 | 'page-category' => 'artbox\core\controllers\PageCategoryController', |
26 | 26 | 'alias' => 'artbox\core\seo\controllers\AliasController', |
27 | 27 | 'seo' => 'artbox\core\controllers\SeoController', |
28 | - 'feedback' => 'artbox\core\controllers\FeedbackController', | |
29 | 28 | 'blog' => 'artbox\weblog\controllers\ArticleController', |
30 | 29 | 'blog-category' => 'artbox\weblog\controllers\CategoryController', |
31 | 30 | 'blog-tag' => 'artbox\weblog\controllers\TagController', | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace backend\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use common\models\Feedback; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use yii\web\Controller; | |
9 | +use yii\web\NotFoundHttpException; | |
10 | +use yii\filters\VerbFilter; | |
11 | +use yii\filters\AccessControl; | |
12 | +use yii\web\Response; | |
13 | +use artbox\core\widgets\FeedbackWidget; | |
14 | +use yii\helpers\Html; | |
15 | + | |
16 | +/** | |
17 | + * FeedbackController implements the CRUD actions for Feedback model. | |
18 | + */ | |
19 | +class FeedbackController extends Controller | |
20 | +{ | |
21 | + /** | |
22 | + * @inheritdoc | |
23 | + */ | |
24 | + public function behaviors() | |
25 | + { | |
26 | + return [ | |
27 | + 'access' => [ | |
28 | + 'class' => AccessControl::className(), | |
29 | + 'rules' => [ | |
30 | + [ | |
31 | + 'actions' => [ | |
32 | + 'login', | |
33 | + 'error', | |
34 | + ], | |
35 | + 'allow' => true, | |
36 | + ], | |
37 | + [ | |
38 | + 'allow' => true, | |
39 | + 'roles' => [ '@' ], | |
40 | + ], | |
41 | + ], | |
42 | + ], | |
43 | + 'verbs' => [ | |
44 | + 'class' => VerbFilter::className(), | |
45 | + 'actions' => [ | |
46 | + 'delete' => ['POST'], | |
47 | + ], | |
48 | + ], | |
49 | + ]; | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * Lists all Feedback models. | |
54 | + * @return mixed | |
55 | + */ | |
56 | + public function actionIndex() | |
57 | + { | |
58 | + $dataProvider = new ActiveDataProvider( | |
59 | + [ | |
60 | + 'query' => Feedback::find()->orderBy('created_at DESC'), | |
61 | + ] | |
62 | + ); | |
63 | + | |
64 | + return $this->render( | |
65 | + 'index', | |
66 | + [ | |
67 | + 'dataProvider' => $dataProvider, | |
68 | + ] | |
69 | + ); | |
70 | + } | |
71 | + | |
72 | + /** | |
73 | + * Displays a single Feedback model. | |
74 | + * @param integer $id | |
75 | + * @return mixed | |
76 | + */ | |
77 | + public function actionView($id) | |
78 | + { | |
79 | + $model = $this->findModel($id); | |
80 | + | |
81 | + $model->status = true; | |
82 | + $model->save(false, [ 'status' ]); | |
83 | + | |
84 | + return $this->render( | |
85 | + 'view', | |
86 | + [ | |
87 | + 'model' => $model, | |
88 | + ] | |
89 | + ); | |
90 | + } | |
91 | + | |
92 | + /** | |
93 | + * Creates a new Feedback model. | |
94 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
95 | + * @return mixed | |
96 | + */ | |
97 | + public function actionCreate() | |
98 | + { | |
99 | + $model = new Feedback(); | |
100 | + | |
101 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
102 | + return $this->redirect(['view', 'id' => $model->id]); | |
103 | + } else { | |
104 | + return $this->render('create', [ | |
105 | + 'model' => $model, | |
106 | + ]); | |
107 | + } | |
108 | + } | |
109 | + | |
110 | + /** | |
111 | + * Updates an existing Feedback model. | |
112 | + * If update is successful, the browser will be redirected to the 'view' page. | |
113 | + * @param integer $id | |
114 | + * @return mixed | |
115 | + */ | |
116 | + public function actionUpdate($id) | |
117 | + { | |
118 | + $model = $this->findModel($id); | |
119 | + | |
120 | + $model->status = true; | |
121 | + $model->save(false, [ 'status' ]); | |
122 | + | |
123 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
124 | + return $this->redirect(['view', 'id' => $model->id]); | |
125 | + } else { | |
126 | + return $this->render('update', [ | |
127 | + 'model' => $model, | |
128 | + ]); | |
129 | + } | |
130 | + } | |
131 | + | |
132 | + /** | |
133 | + * Deletes an existing Feedback model. | |
134 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
135 | + * @param integer $id | |
136 | + * @return mixed | |
137 | + */ | |
138 | + public function actionDelete($id) | |
139 | + { | |
140 | + $this->findModel($id)->delete(); | |
141 | + | |
142 | + return $this->redirect(['index']); | |
143 | + } | |
144 | + | |
145 | + /** | |
146 | + * Finds the Feedback model based on its primary key value. | |
147 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
148 | + * @param integer $id | |
149 | + * @return Feedback the loaded model | |
150 | + * @throws NotFoundHttpException if the model cannot be found | |
151 | + */ | |
152 | + protected function findModel($id) | |
153 | + { | |
154 | + if (($model = Feedback::findOne($id)) !== null) { | |
155 | + return $model; | |
156 | + } else { | |
157 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
158 | + } | |
159 | + } | |
160 | + | |
161 | + public function actionViewed($id) | |
162 | + { | |
163 | + if (Yii::$app->request->isPost) { | |
164 | + $model = $this->findModel($id); | |
165 | + | |
166 | + Yii::$app->response->format = Response::FORMAT_JSON; | |
167 | + | |
168 | + $model->status = true; | |
169 | + if ($model->save(false, [ 'status' ])) { | |
170 | + | |
171 | + $widget = FeedbackWidget::widget(); | |
172 | + | |
173 | + return [ | |
174 | + 'text' => Html::tag( | |
175 | + 'span', | |
176 | + '', | |
177 | + [ | |
178 | + 'class' => 'glyphicon glyphicon-ok', | |
179 | + ] | |
180 | + ), | |
181 | + 'message' => [ | |
182 | + 'title' => Yii::t('core', 'Notification') . ':', | |
183 | + 'text' => Yii::t('core', 'Status changed'), | |
184 | + ], | |
185 | + 'widget' => $widget, | |
186 | + ]; | |
187 | + } | |
188 | + } | |
189 | + return []; | |
190 | + } | |
191 | + | |
192 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Feedback */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="feedback-form"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin(); ?> | |
14 | + | |
15 | + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | |
16 | + | |
17 | + <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?> | |
18 | + | |
19 | + <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?> | |
20 | + | |
21 | + <?= $form->field($model, 'message')->textarea(['rows' => 6]) ?> | |
22 | + | |
23 | + <?= $form->field($model, 'status')->checkbox() ?> | |
24 | + | |
25 | + <?= $form->field($model, 'topic')->textInput(['maxlength' => true]) ?> | |
26 | + | |
27 | + <div class="form-group"> | |
28 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
29 | + </div> | |
30 | + | |
31 | + <?php ActiveForm::end(); ?> | |
32 | + | |
33 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\ObjectkbSearchFeedback */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="feedback-search"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin([ | |
14 | + 'action' => ['index'], | |
15 | + 'method' => 'get', | |
16 | + ]); ?> | |
17 | + | |
18 | + <?= $form->field($model, 'id') ?> | |
19 | + | |
20 | + <?= $form->field($model, 'name') ?> | |
21 | + | |
22 | + <?= $form->field($model, 'email') ?> | |
23 | + | |
24 | + <?= $form->field($model, 'phone') ?> | |
25 | + | |
26 | + <?= $form->field($model, 'message') ?> | |
27 | + | |
28 | + <?php // echo $form->field($model, 'created_at') ?> | |
29 | + | |
30 | + <?php // echo $form->field($model, 'ip') ?> | |
31 | + | |
32 | + <?php // echo $form->field($model, 'url') ?> | |
33 | + | |
34 | + <?php // echo $form->field($model, 'status')->checkbox() ?> | |
35 | + | |
36 | + <?php // echo $form->field($model, 'topic') ?> | |
37 | + | |
38 | + <?php // echo $form->field($model, 'calc_json_info') ?> | |
39 | + | |
40 | + <div class="form-group"> | |
41 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
42 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
43 | + </div> | |
44 | + | |
45 | + <?php ActiveForm::end(); ?> | |
46 | + | |
47 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Feedback */ | |
8 | + | |
9 | +$this->title = Yii::t('app', 'Create Feedback'); | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="feedback-create"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <?= $this->render('_form', [ | |
18 | + 'model' => $model, | |
19 | + ]) ?> | |
20 | + | |
21 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | +use yii\widgets\Pjax; | |
6 | +use common\models\Feedback; | |
7 | +use yiister\gentelella\widgets\Panel; | |
8 | +/* @var $this yii\web\View */ | |
9 | +/* @var $searchModel common\models\ObjectkbSearchFeedback */ | |
10 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
11 | + | |
12 | +$this->title = Yii::t('app', 'Feedbacks'); | |
13 | +$this->params['breadcrumbs'][] = $this->title; | |
14 | +?> | |
15 | +<div class="feedback-index"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
19 | + | |
20 | + <p> | |
21 | + <?= Html::a(Yii::t('app', 'Create Feedback'), ['create'], ['class' => 'btn btn-success']) ?> | |
22 | + </p> | |
23 | + | |
24 | + <?= GridView::widget([ | |
25 | + 'dataProvider' => $dataProvider, | |
26 | + 'rowOptions' => function (Feedback $model) { | |
27 | + if ($model->status) { | |
28 | + return []; | |
29 | + } else { | |
30 | + return [ | |
31 | + 'class' => 'success', | |
32 | + ]; | |
33 | + } | |
34 | + }, | |
35 | + 'columns' => [ | |
36 | + ['class' => 'yii\grid\SerialColumn'], | |
37 | + | |
38 | + 'id', | |
39 | + 'topic', | |
40 | + 'name', | |
41 | + 'email:email', | |
42 | + 'phone', | |
43 | + [ | |
44 | + 'attribute' => 'created_at', | |
45 | + 'format' => [ | |
46 | + 'datetime', | |
47 | + 'php:d.m.Y H:i', | |
48 | + ], | |
49 | + ], | |
50 | + [ | |
51 | + 'class' => 'yii\grid\ActionColumn', | |
52 | + 'buttons' => [ | |
53 | + 'viewed' => function (string $url, Feedback $model) { | |
54 | + if ($model->status) { | |
55 | + return Html::tag( | |
56 | + 'span', | |
57 | + '', | |
58 | + [ | |
59 | + 'class' => 'glyphicon glyphicon-ok', | |
60 | + ] | |
61 | + ); | |
62 | + } else { | |
63 | + return Html::a( | |
64 | + Html::tag( | |
65 | + 'span', | |
66 | + '', | |
67 | + [ | |
68 | + 'class' => 'glyphicon glyphicon-flag', | |
69 | + ] | |
70 | + ), | |
71 | + $url, | |
72 | + [ | |
73 | + 'class' => 'viewed-toggle', | |
74 | + ] | |
75 | + ); | |
76 | + } | |
77 | + }, | |
78 | + ], | |
79 | + 'template' => '{viewed} {view} {update} {delete}', | |
80 | + ], | |
81 | + ], | |
82 | + ]); ?> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model common\models\Feedback */ | |
7 | + | |
8 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
9 | + 'modelClass' => 'Feedback', | |
10 | +]) . $model->name; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; | |
13 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | |
14 | +?> | |
15 | +<div class="feedback-update"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + | |
19 | + <?= $this->render('_form', [ | |
20 | + 'model' => $model, | |
21 | + ]) ?> | |
22 | + | |
23 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | +use common\models\Feedback; | |
6 | + | |
7 | +/* @var $this yii\web\View */ | |
8 | +/* @var $model common\models\Feedback */ | |
9 | + | |
10 | +$this->title = $model->name; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Feedbacks'), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = $this->title; | |
13 | +?> | |
14 | +<div class="feedback-view"> | |
15 | + | |
16 | + <h1><?= Html::encode($this->title) ?></h1> | |
17 | + | |
18 | + <p> | |
19 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
20 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | |
21 | + 'class' => 'btn btn-danger', | |
22 | + 'data' => [ | |
23 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | |
24 | + 'method' => 'post', | |
25 | + ], | |
26 | + ]) ?> | |
27 | + </p> | |
28 | + | |
29 | + <?= DetailView::widget([ | |
30 | + 'model' => $model, | |
31 | + 'attributes' => [ | |
32 | + 'id', | |
33 | + 'name', | |
34 | + 'email:email', | |
35 | + 'phone', | |
36 | + 'message:ntext', | |
37 | + 'created_at', | |
38 | + 'ip', | |
39 | + 'url:url', | |
40 | + 'status:boolean', | |
41 | + 'topic', | |
42 | + [ | |
43 | + 'attribute' => 'calc_json_info', | |
44 | + 'label' => 'calculation info', | |
45 | + 'value' => function(\common\models\Feedback $model, $widget) { | |
46 | + | |
47 | + return json_decode($model->calc_json_info, true); | |
48 | + | |
49 | + }, | |
50 | + ], | |
51 | + ], | |
52 | + 'template' => function ($attribute, $index, $widget){ | |
53 | + if( | |
54 | + $attribute['attribute'] === 'calc_json_info' && | |
55 | + !is_null($attribute['value']) | |
56 | + ){ | |
57 | + $result = ''; | |
58 | + foreach ($attribute['value'] as $attr => $value){ | |
59 | + $result .= "<tr>"; | |
60 | + $result .= "<th>".Feedback::translate_attributes[$attr]."</th>"; | |
61 | + $result .= "<td>{$value}</td>"; | |
62 | + $result .= "</tr>"; | |
63 | + } | |
64 | + | |
65 | + return $result; | |
66 | + | |
67 | + } | |
68 | + elseif ($attribute['attribute'] === 'created_at'){ | |
69 | + return "<tr><th>{$attribute['label']}</th><td>".\yii::$app->formatter->asDatetime($attribute['value'], 'php:d.m.Y H:i')."</td></tr>"; | |
70 | + } | |
71 | + else{ | |
72 | + return "<tr><th>{$attribute['label']}</th><td>{$attribute['value']}</td></tr>"; | |
73 | + } | |
74 | + }, | |
75 | + ]) ?> | |
76 | + | |
77 | +</div> | ... | ... |