Commit 5531f04daf11e4b1f7deab8f3b1fefd982f592b6
1 parent
dbd3c02f
comments in admin
Showing
4 changed files
with
254 additions
and
0 deletions
Show diff stats
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * Created by PhpStorm. | |
| 4 | + * User: stes | |
| 5 | + * Date: 23.05.18 | |
| 6 | + * Time: 12:55 | |
| 7 | + */ | |
| 8 | + | |
| 9 | + namespace backend\controllers; | |
| 10 | + | |
| 11 | + use artbox\core\admin\actions\Delete; | |
| 12 | + use artbox\core\admin\actions\Index; | |
| 13 | + use artbox\core\admin\actions\View; | |
| 14 | + use artbox\core\admin\widgets\Form; | |
| 15 | + use common\models\Comment; | |
| 16 | + use yii\filters\AccessControl; | |
| 17 | + use yii\filters\VerbFilter; | |
| 18 | + use yii\web\Controller; | |
| 19 | + use yii\web\NotFoundHttpException; | |
| 20 | + | |
| 21 | + class CommentController extends Controller | |
| 22 | + { | |
| 23 | + public function behaviors() | |
| 24 | + { | |
| 25 | + return [ | |
| 26 | + 'verbs' => [ | |
| 27 | + 'class' => VerbFilter::className(), | |
| 28 | + 'actions' => [ | |
| 29 | + 'delete' => [ 'POST' ], | |
| 30 | + ], | |
| 31 | + ], | |
| 32 | + 'access' => [ | |
| 33 | + 'class' => AccessControl::className(), | |
| 34 | + 'rules' => [ | |
| 35 | + [ | |
| 36 | + 'allow' => true, | |
| 37 | + 'roles' => [ '@' ], | |
| 38 | + ], | |
| 39 | + ], | |
| 40 | + ], | |
| 41 | + ]; | |
| 42 | + } | |
| 43 | + public function actions() | |
| 44 | + { | |
| 45 | + return [ | |
| 46 | + 'index' => [ | |
| 47 | + 'class' => Index::className(), | |
| 48 | + 'columns' => [ | |
| 49 | + 'name' => [ | |
| 50 | + 'type' => Index::ACTION_COL, | |
| 51 | + ], | |
| 52 | + 'email' => [ | |
| 53 | + 'type' => Index::STRING_COL | |
| 54 | + ], | |
| 55 | + 'status' => [ | |
| 56 | + 'type' => Index::STATUS_COL, | |
| 57 | + ], | |
| 58 | + 'created_at' => [ | |
| 59 | + 'type' => Index::DATETIME_COL, | |
| 60 | + ] | |
| 61 | + ], | |
| 62 | + 'model' => Comment::className(), | |
| 63 | + 'hasLanguage' => false, | |
| 64 | + 'enableMassDelete' => true, | |
| 65 | + 'modelPrimaryKey' => 'id', | |
| 66 | + 'defaultSort' => [ | |
| 67 | + 'created_at' => 'DESC', | |
| 68 | + ], | |
| 69 | + 'create' => false | |
| 70 | + ], | |
| 71 | + 'view' => [ | |
| 72 | + 'class' => View::className(), | |
| 73 | + 'model' => Comment::className(), | |
| 74 | + 'hasAlias' => false, | |
| 75 | + 'hasGallery' => false, | |
| 76 | + 'languageFields' => [ | |
| 77 | + ], | |
| 78 | + 'fields' => [ | |
| 79 | + [ | |
| 80 | + 'name' => 'name', | |
| 81 | + 'type' => Form::STRING, | |
| 82 | + ], | |
| 83 | + [ | |
| 84 | + 'name' => 'email', | |
| 85 | + 'type' => Form::STRING, | |
| 86 | + ], | |
| 87 | + [ | |
| 88 | + 'name' => 'comment', | |
| 89 | + 'type' => Form::TEXTAREA, | |
| 90 | + ], | |
| 91 | + [ | |
| 92 | + 'name' => 'created_at', | |
| 93 | + 'type' => Form::STRING, | |
| 94 | + ], | |
| 95 | + | |
| 96 | + ], | |
| 97 | + ], | |
| 98 | + 'delete' => [ | |
| 99 | + 'class' => Delete::className(), | |
| 100 | + ], | |
| 101 | + ]; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public function findModel($id) | |
| 105 | + { | |
| 106 | + | |
| 107 | + $model = Comment::find() | |
| 108 | + ->where([ 'id' => $id ]) | |
| 109 | + ->one(); | |
| 110 | + if ($model !== null) { | |
| 111 | + return $model; | |
| 112 | + } else { | |
| 113 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + public function deleteModel($id) | |
| 118 | + { | |
| 119 | + $category = Comment::find() | |
| 120 | + ->where( | |
| 121 | + [ | |
| 122 | + 'id' => $id, | |
| 123 | + ] | |
| 124 | + ) | |
| 125 | + ->one(); | |
| 126 | + | |
| 127 | + | |
| 128 | + return $category->delete(); | |
| 129 | + } | |
| 130 | + | |
| 131 | + public function actionUpdate($id) | |
| 132 | + { | |
| 133 | + $model = $this->findModel($id); | |
| 134 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |
| 135 | + return $this->redirect('index'); | |
| 136 | + } else { | |
| 137 | + return $this->render( | |
| 138 | + 'update', | |
| 139 | + [ | |
| 140 | + 'model' => $model, | |
| 141 | + ] | |
| 142 | + ); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 0 | 146 | \ No newline at end of file | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + use artbox\core\admin\assets\Select2; | |
| 4 | + use artbox\core\admin\assets\Switchery; | |
| 5 | + use yii\helpers\Html; | |
| 6 | + use yii\web\View; | |
| 7 | + use yii\widgets\ActiveForm; | |
| 8 | + | |
| 9 | + /* @var $this yii\web\View */ | |
| 10 | + /* @var $model \common\models\Comment */ | |
| 11 | + /* @var $form yii\widgets\ActiveForm */ | |
| 12 | + Switchery::register($this); | |
| 13 | + $js = <<< JS | |
| 14 | +$('.switchery').each(function(idx, elem) { | |
| 15 | + new Switchery(elem, { | |
| 16 | + color:'#46b749', | |
| 17 | + secondaryColor:'#e2e2e2' | |
| 18 | + }); | |
| 19 | +}); | |
| 20 | + | |
| 21 | +$(".select_service").select2(); | |
| 22 | +JS; | |
| 23 | + | |
| 24 | + Select2::register($this); | |
| 25 | + $this->registerJs($js, View::POS_READY); | |
| 26 | + | |
| 27 | +?> | |
| 28 | + | |
| 29 | +<div class="feedback-form"> | |
| 30 | + | |
| 31 | + <?php $form = ActiveForm::begin(); ?> | |
| 32 | + <?=$model->book->title?> | |
| 33 | + | |
| 34 | + <?= $form->field($model, 'name') | |
| 35 | + ->textInput([ 'maxlength' => true ]) ?> | |
| 36 | + | |
| 37 | + <?= $form->field($model, 'email') | |
| 38 | + ->textInput([ 'maxlength' => true ]) ?> | |
| 39 | + | |
| 40 | + <?= $form->field($model, 'comment') | |
| 41 | + ->textarea([ 'rows' => 6 ]) ?> | |
| 42 | + | |
| 43 | + <?= $form->field($model, 'status') | |
| 44 | + ->checkbox( | |
| 45 | + [ | |
| 46 | + 'class' => 'switchery', | |
| 47 | + ] | |
| 48 | + ) ?> | |
| 49 | + | |
| 50 | + <div class="form-group"> | |
| 51 | + <?= Html::submitButton( | |
| 52 | + $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), | |
| 53 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
| 54 | + ) ?> | |
| 55 | + </div> | |
| 56 | + | |
| 57 | + <?php ActiveForm::end(); ?> | |
| 58 | + | |
| 59 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + use yiister\gentelella\widgets\Panel; | |
| 4 | + | |
| 5 | + /* @var $this yii\web\View */ | |
| 6 | + /* @var $model \common\models\Comment */ | |
| 7 | + | |
| 8 | + $this->title = Yii::t( | |
| 9 | + 'app', | |
| 10 | + 'Update {modelClass}: ', | |
| 11 | + [ | |
| 12 | + 'modelClass' => 'Comment', | |
| 13 | + ] | |
| 14 | + ) . $model->name; | |
| 15 | + $this->params[ 'breadcrumbs' ][] = [ | |
| 16 | + 'label' => Yii::t('app', 'Comments'), | |
| 17 | + 'url' => [ 'index' ], | |
| 18 | + ]; | |
| 19 | + $this->params[ 'breadcrumbs' ][] = [ | |
| 20 | + 'label' => $model->name, | |
| 21 | + 'url' => [ | |
| 22 | + 'view', | |
| 23 | + 'id' => $model->id, | |
| 24 | + ], | |
| 25 | + ]; | |
| 26 | + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); | |
| 27 | +?> | |
| 28 | + | |
| 29 | +<?php $panel = Panel::begin( | |
| 30 | + [ | |
| 31 | + 'header' => $this->title, | |
| 32 | + 'options' => [ | |
| 33 | + 'class' => 'x_panel comment-update', | |
| 34 | + ], | |
| 35 | + ] | |
| 36 | +) ?> | |
| 37 | + | |
| 38 | +<?= $this->render( | |
| 39 | + '_form', | |
| 40 | + [ | |
| 41 | + 'model' => $model, | |
| 42 | + ] | |
| 43 | +) ?> | |
| 44 | + | |
| 45 | +<?php $panel::end(); ?> | ... | ... |