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 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 54
BannerController
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
90.00
0.00% covered (danger)
0.00%
0 / 54
 behaviors
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 20
 actionIndex
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 6
 actionUpdate
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 14
 actionDelete
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
 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\BannerUploadForm;
use common\models\Banner;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
/**
 * BannerController implements Banner file manipulation.
 */
class BannerController extends Controller
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['index', 'update', 'delete'],
                        'allow' => true,
                        'roles' => ['supervisor', 'admin'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }
    /**
     * Lists all Banner models.
     * @return mixed
     */
    public function actionIndex()
    {
        $banners = Banner::findAll();
        return $this->render('index', [
            'banners' => $banners,
        ]);
    }
    /**
     * Updates an existing Banner model.
     * If update is successful, the browser will be redirected to the 'index' page.
     * @param string $key
     * @return mixed
     */
    public function actionUpdate($key)
    {
        $banner = $this->findModel($key);
        $model = new BannerUploadForm([
            'banner' => $banner,
        ]);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index']);
        } else {
            return $this->render('update', [
                'model' => $model,
                'banner' => $banner,
            ]);
        }
    }
    /**
     * Deletes an existing Banner model.
     * If update is successful, the browser will be redirected to the 'index' page.
     * @param string $key
     * @return mixed
     */
    public function actionDelete($key)
    {
        $banner = $this->findModel($key);
        if (!$banner->delete()) {
            Yii::$app->session->setFlash('error', Yii::t('app', 'Unable to delete banner, contact technical support.'));
        }
        return $this->redirect(['index']);
    }
    /**
     * Finds the Banner model based on its key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $key
     * @return Banner the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($key)
    {
        if (($model = Banner::findOne($key)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}