Your IP : 216.73.216.79


Current Path : /var/www/html/portalv2/frontend/controllers/
Upload File :
Current File : /var/www/html/portalv2/frontend/controllers/SiteController.php

<?php

namespace frontend\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use kartik\mpdf\Pdf;

/**
 * Site controller
 */
class SiteController extends Controller
{

    /*** system parameter **/
    public $DYNAWEB_DEFAULT_ROUTE_PAGE;

    public $DYNAWEB_DEFAULT_ROUTE_PARAMS;
    /**
     * {@inheritDoc}
     * @see \yii\web\Controller::beforeAction()
     */
    public function beforeAction($action)
    {
        //         $this->layout = 'main_default';
        // TODO Auto-generated method stub
        return parent::beforeAction($action);
    }

    /**
     * @inheritdoc
     */

    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup', 'error', 'stub'],
                'rules' => [
                    [
                        'actions' => ['signup', 'error', 'stub'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout', 'error', 'stub'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex($frontendpage = null, $params = null)
    {
        $this->DYNAWEB_DEFAULT_ROUTE_PAGE   = $frontendpage;
        $this->DYNAWEB_DEFAULT_ROUTE_PARAMS = $params;

        return $this->render('index');
    }

    /**
     * use slug
     * */
    public function actionPage()
    {
        return $this->render('page'); // placeholder
    }

    /**
     * Logs out the current user.
     *
     * @return mixed
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }

    public function actionError()
    {
        $exception = Yii::$app->errorHandler->exception;
        if ($exception !== null) {
            return $exception->getMessage();
        }
    }

    public function actionViewpdf($doc_id)
    {
        if (($model = \common\models\CourseDocument::findOne($doc_id)) !== null) {
            $pdf = new Pdf([
                'mode' => Pdf::MODE_BLANK,
                'filename' => $model->doc_title . '.pdf',
                'format' => Pdf::FORMAT_A4,
                'orientation' => Pdf::ORIENT_PORTRAIT,
                'destination' => Pdf::DEST_DOWNLOAD,
                'content' => $model->doc_content,
            ]);
            return $pdf->render();
        }
    }

    public function actionTranslate($language)
    {
        $cookies = Yii::$app->response->cookies;
        Yii::$app->language = $language;
        $cookies->add(new \yii\web\Cookie([
            'name' => 'language',
            'value' => $language
        ]));
        return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);
    }


    public function actionStub() {
    }
}