Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 76
SurveyOptionController
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
272.00
0.00% covered (danger)
0.00%
0 / 76
 behaviors
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 20
 actionView
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 5
 actionCreate
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 15
 actionUpdate
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 12
 actionDelete
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
 actionMoveUp
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 5
 actionMoveDown
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 5
 findModel
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
<?php
namespace backend\controllers;
use Yii;
use backend\models\SurveyOptionSearch;
use common\models\SurveyOption;
use common\models\SurveyQuestion;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
/**
 * SurveyOptionController implements the CRUD actions for SurveyOption model.
 */
class SurveyOptionController extends \yii\web\Controller
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['view', 'create', 'update', 'delete'],
                        'allow' => true,
                        'roles' => ['supervisor', 'admin'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }
    /**
     * Displays a single SurveyOption model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }
    /**
     * Creates a new SurveyOption model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate($question)
    {
        if (SurveyQuestion::findOne($question)->survey->answered_quantity > 0)
            throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.'));
        $model = new SurveyOption();
        $model->survey_question_id = $question;
        if ($model->load(Yii::$app->request->post())) {
            $model->survey_question_id = $question;
            if ($model->save()) {
                return $this->redirect(['view', 'id' => $model->id]);
            }
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
    /**
     * Updates an existing SurveyOption model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->surveyQuestion->survey->answered_quantity > 0)
            throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.'));
        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 SurveyOption model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $model = $this->findModel($id);
        if ($model->surveyQuestion->survey->answered_quantity > 0)
            throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.'));
        $model->delete();
        return $this->redirect(['/survey-question/view', 'id' => $model->survey_question_id]);
    }
    /**
     * Deletes an existing SurveyOption model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionMoveUp($id)
    {
        $model = $this->findModel($id);
        $model->moveUpOn();
        return $this->redirect(['/survey-question/view', 'id' => $model->survey_question_id]);
    }
    /**
     * Deletes an existing SurveyOption model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionMoveDown($id)
    {
        $model = $this->findModel($id);
        $model->moveDownOn();
        return $this->redirect(['/survey-question/view', 'id' => $model->survey_question_id]);
    }
    /**
     * Finds the SurveyOption model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return SurveyOption the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = SurveyOption::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}