Your IP : 216.73.216.79


Current Path : /var/www/html/dosmv2/frontend/controllers/
Upload File :
Current File : /var/www/html/dosmv2/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 {

    /**
     * {@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'],
                        '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() {
        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 actionGetsubcategory($cat = '') {
        $output = '<option value="">-- Sila pilih --</option>';
        if (!empty($cat)) {
            $ch_subcat = curl_init();
            curl_setopt($ch_subcat, CURLOPT_FAILONERROR, true);
            curl_setopt($ch_subcat, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch_subcat, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch_subcat, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch_subcat, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch_subcat, CURLOPT_URL, Yii::$app->params['erosesApi'] . "ref_category?cat=" . $cat);
            curl_setopt($ch_subcat, CURLOPT_RETURNTRANSFER, true);
            $server_output_subcat = curl_exec($ch_subcat);
            curl_close($ch_subcat);
            $output_subcat = json_decode($server_output_subcat, true);
            if (!empty($output_subcat['subcategory'])) {
                foreach ($output_subcat['subcategory'] as $sub_code => $sub_label) {
                    $output .= '<option value="' . $sub_code . '">' . $sub_label . '</option>';
                }
            }
        }
        return $output;
    }

    public function actionApi($code) {
        if (($model = \backend\modules\api\models\Api::findOne(['api_code' => $code])) !== null) {
            header('Content-Type: application/json');
            eval('?>' . $model->api_content);
            die();
        }
    }

    public function actionGetevent($current_date) {
        $eventList = '';
        $query = new \yii\db\Query();
        $query->from('content_calendar')
                ->innerJoin('content_calendar_translation', 'calendar_id=calendar_translation_parent_id')
                ->andwhere(['=', 'calendar_status', 'active'])
                ->andwhere(['=', 'YEAR(calendar_date_start)', date("Y", strtotime($current_date))])
                ->andwhere(['=', 'MONTH(calendar_date_start)', date("m", strtotime($current_date))]);
        $model = $query->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $eventList .= '<hr class="mt-20 mb-20">';
                $eventList .= '<p class="mb-10">'.$row['calendar_translation_content'].'</p>';
                $eventList .= '<p class="mb-10">Lokasi : ' . $row['calendar_translation_location'].'</p>';

                if ($row['calendar_date_start'] == $row['calendar_date_end'])
                    $eventList .= '<p class="mb-10">Tarikh : ' . date("d/m/Y", strtotime($row['calendar_date_start'])).'</p>';
                else
                    $eventList .= '<p class="mb-10">Tarikh : ' . date("d/m/Y", strtotime($row['calendar_date_start'])) . ' sehingga ' . date("d/m/Y", strtotime($row['calendar_date_end'])).'</p>';

                $eventList .= '<p class="mb-10">Masa : ' . $row['calendar_time_start'] . ' sehingga ' . $row['calendar_time_end'].'</p>';

                
            }
        } else {
            $eventList = '<hr class="mt-20 mb-20"><p>Tiada aktiviti bulan ini.</p>';
        }
        return $eventList;
    }
}