Your IP : 216.73.216.79


Current Path : /var/www/html/dynaweb.blunetdev.com/backend/controllers/frontend/
Upload File :
Current File : /var/www/html/dynaweb.blunetdev.com/backend/controllers/frontend/FrontendSiteController.php

<?php
namespace backend\controllers\frontend;

use Yii;
use backend\models\frontend\FrontendSite;
use backend\models\frontend\FrontendSiteSearch;
// use yii\filters\AccessControl;
use backend\modules\mimin\components\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\components\AccessRule;

/**
 * FrontendSiteController implements the CRUD actions for FrontendSite model.
 */
class FrontendSiteController extends Controller
{

    /**
     *
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                // 'ruleConfig' => [
                //     'class' => AccessRule::className()
                // ],
                // 'rules' => [
                //     [
                //         'actions' => [
                //             'index',
                //             'create',
                //             'update',
                //             'view',
                //             'delete',
                //             'req-content-edit',
                //             'assign-save-content',
                //             'assign-copy-content',
                //             'reg-content-trans',
                //             'assign-save-ajax-content',
                //             'save-template',
                //             'preview',
                //             'ajax-stripper',
                //             'assets'
                //         ],
                //         'allow' => true,
                //         'roles' => [
                //             '@'
                //         ]
                //     ]
                // ]
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => [
                        'POST'
                    ]
                ]
            ]
        ];
    }

    public function createUrl()
    {}

    /**
     * Lists all FrontendSite models.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new FrontendSiteSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider
        ]);
    }

    /**
     * Displays a single FrontendSite model.
     *
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id)
        ]);
    }

    /**
     * Creates a new FrontendSite model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     *
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new FrontendSite();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect([
                'index'
            ]);
        } else {
            return $this->render('create', [
                'model' => $model
            ]);
        }
    }

    /**
     * Updates an existing FrontendSite model.
     * If update is successful, the browser will be redirected to the 'view' page.
     *
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect([
                'index'
            ]);
        } else {
            return $this->render('update', [
                'model' => $model
            ]);
        }
    }

    /**
     * Deletes an existing FrontendSite model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     *
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect([
            'index'
        ]);
    }

    /**
     * Finds the FrontendSite model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     *
     * @param integer $id
     * @return FrontendSite the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = FrontendSite::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

    public function actionSetDefaultSite()
    {
        $siteid = Yii::$app->request->get('site_id');
        /* reseting the default value */
        $siteDefault = FrontendSite::findOne([
            'site_default' => 1
        ]);
        if (! empty($siteDefault)) {
            $siteDefault->site_default = 0;
            $siteDefault->update();
            return $this->actionIndex();
        }
        /* setting the default value */
        $siteSetDefault = FrontendSite::find()->where('site_id = :siteid', [
            ':siteid' => $siteid
        ])->one();
        $siteSetDefault->site_default = 1;
        $siteSetDefault->update();

        return $this->actionIndex();
    }
}