Your IP : 216.73.216.79


Current Path : /var/www/html/planmalaysia/common/components/
Upload File :
Current File : /var/www/html/planmalaysia/common/components/PortalModuleExtension.php

<?php 

namespace common\components;
use yii\BaseYii as Yii;
use backend\models\BanciMediaGallerySearch;
use backend\models\BanciArticleSearch;
use backend\models\BanciVideoSearch;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\Pjax;

class PortalModuleExtension {
    
    public $tag = [
        'csrftag',
        'arkib',
        'get',
        'modelparam',
        'arkibarview',
        'arkibimview',
        'arkibvidgallery',
        'datacountdown',
        'announcement',
        'highlight',
        'latestevent'
    ];

    public function __construct()
    {

    }

    public function csrftag($arg){
        return '<input class="form-token" type="hidden" name="'.Yii::$app->request->csrfParam.'"value="'.Yii::$app->request->csrfToken.'"/>';
    }

    public function arkib(){
        if(isset($_GET['type'])){
            $type = filter_var($_GET['type'],FILTER_SANITIZE_STRING);
        }else{
            $type = "01";
        }
        if(isset($_GET['year'])){
            $year = filter_var($_GET['year'],FILTER_SANITIZE_STRING);
        }

        if(isset($_GET['month'])){
            $month = filter_var($_GET['month'], FILTER_SANITIZE_STRING);
        }


        if(isset($type) && isset($year) && isset($month) ){
            if ($type == "01") {
                $searchModel = new BanciArticleSearch();
                $searchModel->banci_article_status = 2;
                if (isset($year)) {
                    $searchModel->year = $year;
                }
                if (isset($month)) {
                    $searchModel->month = $month;
                }

                $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

                return GridView::widget([
                                        'dataProvider' => $dataProvider,
                                        'columns' => [
                                            ['class' => 'yii\grid\SerialColumn'],
                                            'banci_article_title_my',
                                            [
                                                'attribute' => 'banci_article_category',
                                                'value' => function($model){
                                                    $ref = \backend\models\Ref::find()->where(['code' => $model->banci_article_category])->one();
                                                    if(Yii::$app->language == "en"){
                                                        $desc = $ref->descr_en;
                                                    }else{
                                                        $desc = $ref->descr;
                                                    }

                                                    return $desc;

                                                }
                                            ],
                                            [
                                                'class' => 'yii\grid\ActionColumn',
                                                'template' => '{viewpage}',
                                                'header' => '#',
                                                'buttons' => [
                                                                    'viewpage' => function ($url, $model) {
                                                                        return Html::a('<i class="fa fa-eye"></i>', 'index.php?&id=3&page_id=49&articid='.$model->banci_article_id,['target'=>'_blank']);
                                                                    },
                                                            ]
                                            ],
                                        ],
                                    ]);
            } elseif ($type == "02") {
                $searchModel = new BanciMediaGallerySearch();
                $searchModel->media_gallery_file_status = 1;
                $searchModel->year = $year;
                $searchModel->month = $month;

                $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
                return GridView::widget([
                                        'dataProvider' => $dataProvider,
                                        'columns' => [
                                            ['class' => 'yii\grid\SerialColumn'],
                                            'media_gallery_title',
                                            [
                                                'class' => 'yii\grid\ActionColumn',
                                                'template' => '{viewpage}',
                                                'header' => '#',
                                                'buttons' => [
                                                        'viewpage' => function ($url, $model) {
                                                            return Html::a('<i class="fa fa-eye"></i>','index.php?page_id=50&id=3&aid='.$model->media_gallery_id,['target'=>'_blank']);
                                                        },
                                                ]
                                            ],
                                        ],
                                    ]);
            }else{
                $searchModel = new BanciVideoSearch();
                $searchModel->video_status = 1;
                $searchModel->year = $year;
                $searchModel->month = $month;

                $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
                return GridView::widget([
                                        'dataProvider' => $dataProvider,
                                        'columns' => [
                                            ['class' => 'yii\grid\SerialColumn'],
                                            'video_title',
                                            [
                                                'class' => 'yii\grid\ActionColumn',
                                                'template' => '{viewpage}',
                                                'header' => '#',
                                                'buttons' => [
                                                        'viewpage' => function ($url, $model) {
                                                            return Html::a('<i class="fa fa-eye"></i>', 'index.php?page_id=51&id=3&vid='.$model->video_id, ['target'=>'_blank']);
                                                        },
                                                ]
                                            ],
                                        ],
                                    ]);

            }
        }else{
            return '<div class="alert alert-info">Sila Buat Carian.</div>';
        }
    }

    public function get($var){
         if (isset($_GET[''.$var[0].''])) {
             return $_GET[''.$var[0].''];
         }
    }

    public function modelparam($param){
        $param = explode('|',$param[0]);    
        if(isset($_GET[''.$param[0].''])){
            $mparam = $_GET[''.$param[0].''];
            return $mparam[$param[1]];
        }
    }

    public function arkibarview($content){
        $arid = filter_var($_GET['articid'],FILTER_SANITIZE_NUMBER_INT);
        $model = \backend\models\BanciArticleSearch::findOne($arid);
                
        if(Yii::$app->language == "en"){
            $title = $model->banci_article_title_en;
            $contents = $model->banci_article_content_en;
        }else{
            $title = $model->banci_article_title_my;
            $contents = $model->banci_article_content_my;
        }

        if($model->banci_article_category == "AK"){
           $contents = $contents.'<br> <a href="index.php?&id=3&page_id=42&filename=aktabanci&aid='.$model->banci_article_id.'" type="button" class="btn btn-primary">'.Yii::t('portal','Selanjutnya').'</a>';
        }elseif($model->banci_article_category == "QA"){
           $contents = $contents.'<br> <a href="index.php?&id=3&page_id=43&filename=soalselidik&aid='.$model->banci_article_id.'" type="button" class="btn btn-primary">'.Yii::t('portal','Selanjutnya').'</a>';
        }

        if(empty($model->banci_article_image)){
            $image = 'admin/uploads/noimage.jpg';
        }else{
            $image = 'admin/uploads/'.$model->banci_article_image;
        }
        
        $ctitle = str_replace('#title',$title,$content[0]);
        $ccater = str_replace('#kategori', $model->banci_article_category, $ctitle);
        $csubcat= str_replace('#subkategori', $model->banci_article_subcategory, $ccater);
        $cimage = str_replace('#images', $image , $csubcat);
        $ccont  = str_replace('#content', $contents, $cimage);

        return $ccont;
    }

    public function arkibimview($content){
        $arid = filter_var($_GET['aid'], FILTER_SANITIZE_NUMBER_INT);
        $model = \backend\models\BanciMediaGallery::findOne($arid);
                
        if (Yii::$app->language == "en") {
            $title = $model->media_gallery_title_en;
            $contents = $model->media_gallery_description_en;
        } else {
            $title = $model->media_gallery_title;
            $contents = $model->media_gallery_description;
        }

        if (empty($model->media_gallery_thumb_image)) {
            $image = 'admin/uploads/noimage.jpg';
        } else {
            $image = 'admin/'.$model->media_gallery_thumb_image;
        }
        
        $ctitle = str_replace('#title', $title, $content[0]);
        $ccater = str_replace('#kategori', $model->media_gallery_category, $ctitle);
        $cimage = str_replace('#images', $image, $ccater);
        $ccont  = str_replace('#content', $contents, $cimage);

        return $ccont;
    }

    public function arkibvidgallery($content){
        $vid = filter_var($_GET['vid'], FILTER_SANITIZE_NUMBER_INT);
        $model = \backend\models\BanciVideo::findOne($vid);
        
        if (Yii::$app->language == "en") {
            $title = $model->video_title_en;
            $desc = $model->video_description_en;
            
        } else {
            $title = $model->video_title;
            $desc = $model->video_description;
        }

        $url = $model->video_url;
        parse_str(parse_url($url, PHP_URL_QUERY), $query);
        
        $ctitle = str_replace('#title', $title, $content[0]);
        $cdesc  = str_replace('#desc', $desc, $ctitle);
        $ccont  = str_replace('#url', $query['v'], $cdesc);

        return $ccont;
    }

    public function datacountdown(){
        $countdown = \backend\models\BanciCountdownClock::find()->where(['countdown_status' => '1'])->one();
        return 'WPTOT--'.$countdown->countdown_WPTOT.'<--->WPMTH--'.$countdown->countdown_WPMTH.'<--->WPDAY--'.$countdown->countdown_WPDAY.'<--->WPHOUR--'.$countdown->countdown_WPHOUR.'<--->WPMIN--'.$countdown->countdown_WPMIN.'<--->WPSEC--'.$countdown->countdown_WPSEC.'<--->MPTOT--'.$countdown->countdown_MPTOT.'<--->MPMTH--'.$countdown->countdown_MPMTH.'<--->MPDAY--'.$countdown->countdown_MPDAY.'<--->MPHOUR--'.$countdown->countdown_MPHOUR.'<--->MPMIN--'.$countdown->countdown_MPMIN.'<--->MPSEC--'.$countdown->countdown_MPSEC.'';
    }

    public function announcement(){
        $announce = \backend\models\BanciAnnouncement::find()->where(['banci_announcement_status' => 1])->asArray()->all();
        $html = '';
        foreach ($announce as $aval) {
            $html .= "<div class=\"item\">".$aval['banci_announcement_content']."</div>";
        }
        return $html;
    }

    public function highlight(){
        $highlights = \backend\models\BanciHighlight::find()->where(['highlight_status'=>'1'])->all();
        $html = "";
        $active = "active";
        $i = 0;
        foreach ($highlights as $highlight) {
            
            /* default */
            $image = $highlight->highlight_image;
            
            if(Yii::$app->language == "en"){
               $image =  $highlight->highlight_image_en;
            }

            if($i > 0){
                $active = "";
            }
            $html .= '<div class="item '.$active.'">
                        <img src="admin/'.$image.'" style="height:200px;width:100%" alt="'.$highlight->highlight_title.'">
                    </div>';
        $i++;}
        return $html;
    }

    public function latestevent(){
        $latestevents = \backend\models\BanciMediaGallery::find()->orderBy('created_at DESC')->limit(5)->asArray()->all();
        $html = '';

        foreach ($latestevents as $latestevent) {
            $html .= '
                <div class="item">
                    <div class="col-md-4">
                    <img src="admin/'.$latestevent['media_gallery_thumb_image'].'" style="height:80px">
                    </div>
                    <div class="col-md-8">
                        <a target="_blank" href="index.php?&id=3&page_id=41&aid='.$latestevent['media_gallery_id'].'" class="hover"><b>'.$latestevent['media_gallery_title'].' »</b></a><br>
                        <span class="font-small">'.date('d M Y',strtotime($latestevent['created_at'])).'</span>
                    </div>
                </div>
            ';
        }
        return $html;
    }

}