From ebde7ea615601a0800024e068709123731510edf Mon Sep 17 00:00:00 2001 From: Anastasia Date: Wed, 30 May 2018 15:05:55 +0300 Subject: [PATCH] - forms --- backend/controllers/CommentController.php | 8 +++++++- backend/controllers/QuestionController.php | 6 +++++- backend/views/comment/_form.php | 9 ++++++++- backend/views/comment/update.php | 2 ++ backend/views/question/_form.php | 6 +++++- backend/views/question/update.php | 1 + common/models/Comment.php | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- common/models/Question.php | 6 +++++- frontend/config/main.php | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- frontend/views/layouts/main.php | 3 +-- frontend/views/service/view.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- frontend/web/js/script.js | 14 ++++++++------ 12 files changed, 330 insertions(+), 96 deletions(-) diff --git a/backend/controllers/CommentController.php b/backend/controllers/CommentController.php index 19376a3..1ab8bb2 100644 --- a/backend/controllers/CommentController.php +++ b/backend/controllers/CommentController.php @@ -13,8 +13,10 @@ use artbox\core\admin\actions\View; use artbox\core\admin\widgets\Form; use common\models\Comment; + use common\models\Service; use yii\filters\AccessControl; use yii\filters\VerbFilter; + use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -103,6 +105,7 @@ public function findModel($id) { + $model = Comment::find() ->where([ 'id' => $id ]) ->one(); @@ -122,6 +125,7 @@ ] ) ->one(); + return $category->delete(); } @@ -129,7 +133,8 @@ public function actionUpdate($id) { $model = $this->findModel($id); - + $services = Service::find()->all(); + $data = ArrayHelper::map($services, 'id', 'title'); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } else { @@ -137,6 +142,7 @@ 'update', [ 'model' => $model, + 'services' => $data ] ); } diff --git a/backend/controllers/QuestionController.php b/backend/controllers/QuestionController.php index a02749a..795b6dd 100644 --- a/backend/controllers/QuestionController.php +++ b/backend/controllers/QuestionController.php @@ -13,8 +13,10 @@ use artbox\core\admin\actions\View; use artbox\core\admin\widgets\Form; use common\models\Question; + use common\models\Service; use yii\filters\AccessControl; use yii\filters\VerbFilter; + use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -129,7 +131,8 @@ public function actionUpdate($id) { $model = $this->findModel($id); - + $services = Service::find()->all(); + $data = ArrayHelper::map($services, 'id', 'title'); $model->scenario = Question::SCENARIO_ANSWER; if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); @@ -138,6 +141,7 @@ 'update', [ 'model' => $model, + 'services' => $data ] ); } diff --git a/backend/views/comment/_form.php b/backend/views/comment/_form.php index a25ab7f..e61235f 100644 --- a/backend/views/comment/_form.php +++ b/backend/views/comment/_form.php @@ -1,5 +1,6 @@ registerJs($js, View::POS_READY); + ?>
+ field($model, 'service_id')->dropDownList($services, [ + 'class' => 'select_service' + ])?> field($model, 'name') ->textInput([ 'maxlength' => true ]) ?> diff --git a/backend/views/comment/update.php b/backend/views/comment/update.php index 0188871..f219f1a 100644 --- a/backend/views/comment/update.php +++ b/backend/views/comment/update.php @@ -4,6 +4,7 @@ /* @var $this yii\web\View */ /* @var $model \common\models\Comment */ + /* @var $services \common\models\Service[] */ $this->title = Yii::t( 'app', @@ -39,6 +40,7 @@ '_form', [ 'model' => $model, + 'services' => $services ] ) ?> diff --git a/backend/views/question/_form.php b/backend/views/question/_form.php index d1b8686..df363e7 100644 --- a/backend/views/question/_form.php +++ b/backend/views/question/_form.php @@ -16,6 +16,8 @@ $('.switchery').each(function(idx, elem) { secondaryColor:'#e2e2e2' }); }); + +$(".select_service").select2(); JS; @@ -25,7 +27,9 @@ JS;