Your IP : 216.73.216.79


Current Path : /var/www/html/digitalnahrimv2/frontend/controllers/
Upload File :
Current File : /var/www/html/digitalnahrimv2/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;
use backend\modules\mwrj\models\MwrjList;

/**
 * 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,
            ],
        ];
    }

    public function actionSortingmwrj($data = '') {
        $count = 0;
        $data_arr = explode(',', $data);
        if (!empty($data_arr)) {
            foreach ($data_arr as $id) {
                $model = MwrjList::findOne($id);
                if (!empty($model)) {
                    $count++;
                    $model->sorting = $count;
                    $model->save(false);
                }
            }
        }

        return $data;
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex() {
        return $this->render('index');
    }

    public function stub() {
        return '1231';
    }

    /**
     * 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 actionDownloadcv($id) {


        $output = '';
        $model = \backend\modules\fruserdynav2\models\FrontendUser::findOne($id);
        if (!empty($model)) {
            $user_image = '/admin/images/user_default.png';
            if (!empty($model->img_url))
                $user_image = '/' . $model->img_url;
            $output .= '<h3><b>CURRICULUM VITAE</b></h3><br>
                <table width="100%" border="0">
                    <tr>
                        <td width="70%">
                            <h4><b>' . strtoupper($model->fullname) . '</b></h4><br>
                            <p>Email Address : <b>' . $model->username . '</b></p><br>
                            <p>Telephone Number : <b>' . $model->phone . '</b></p><br>
                            <p>Organization Name : <b>' . $model->organization . '</b></p><br>
                            <p>Designation : <b>' . $model->designation . '</b></p><br>
                            <p>Department : <b>' . \backend\modules\refdynawebv2\models\Ref::getDesc('DEPT', $model->department, 'descr_en') . '</b></p>
                        </td>
                        <td width="30%" style="vertical-align:top;text-align:right;"><img src="' . $user_image . '" style="width:150px;"></td>
                    </tr>
                </table>';
        }
        $modelacademic = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'academic'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelacademic)) {
            $output .= '<br><h4><b>Academic</b></h4><ol>';
            foreach ($modelacademic as $rowacademic) {
                $output .= '<li>' . $rowacademic->details . ' (' . $rowacademic->year . ')</li>';
            }
            $output .= '</ol>';
        }

        $modelworking = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'working'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelworking)) {
            $output .= '<br><h4><b>Working Experience</b></h4><ol>';
            foreach ($modelworking as $rowworking) {
                $output .= '<li>' . $rowworking->details . ' (' . $rowworking->year . ')</li>';
            }
            $output .= '</ol>';
        }

        $modelprofessional = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'professional'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelprofessional)) {
            $output .= '<br><h4><b>Professional Experience</b></h4><ol>';
            foreach ($modelprofessional as $rowprofessional) {
                $output .= '<li>' . $rowprofessional->details . ' (' . $rowprofessional->year . ')</li>';
            }
            $output .= '</ol>';
        }

        $modelawards = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'awards'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelawards)) {
            $output .= '<br><h4><b>Awards & Recognitions</b></h4><ol>';
            foreach ($modelawards as $rowawards) {
                $output .= '<li>' . $rowawards->details . ' (' . $rowawards->year . ')</li>';
            }
            $output .= '</ol>';
        }

        $modelprojects = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'projects'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelprojects)) {
            $output .= '<br><h4><b>Projects</b></h4><ol>';
            foreach ($modelprojects as $rowprojects) {
                $output .= '<li>' . $rowprojects->details . ' (' . $rowprojects->year . ')</li>';
            }
            $output .= '</ol>';
        }
        
        $modelaffiliation = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'affiliation'])->orderby(['year' => SORT_DESC])->all();
        if (!empty($modelaffiliation)) {
            $output .= '<br><h4><b>Affiliation</b></h4><ol>';
            foreach ($modelaffiliation as $rowaffiliation) {
                $output .= '<li>' . $rowaffiliation->details . ' (' . $rowaffiliation->year . ')</li>';
            }
            $output .= '</ol>';
        }

        $queryPublication = new \yii\db\Query();
        $queryPublication->from('publication_author')
                ->innerJoin('publication_document', 'document_id=publication_id')
                ->innerJoin('publication_document_translation', 'publication_document.document_id=publication_document_translation.document_translation_parent_id')
                ->where(['=', 'user_id', $id])
                ->andwhere(['=', 'document_status', 'active'])
                ->orderBy(['publication_document.document_date' => SORT_DESC]);
        $modelPublication = $queryPublication->all();
        $countPublication = 0;
        if (!empty($modelPublication)) {
            $output .= '<br><h4><b>Publications</b></h4><ol>';
            foreach ($modelPublication as $rowPublication) {
                $countPublication++;
                $output .= '<li>' . ucwords(strtolower($rowPublication['document_translation_title'])) . '</li>';
            }
            $output .= '</ol>';
        }

        $modelreferences = \backend\modules\fruserdynav2\models\FrontendUserCv::find()->where(['=', 'user_id', $id])->andwhere(['=', 'type', 'references'])->orderby(['id' => SORT_ASC])->all();
        if (!empty($modelreferences)) {
            $output .= '<br><h4><b>References</b></h4><ol>';
            foreach ($modelreferences as $rowreferences) {
                $output .= '<li>' . $rowreferences->details . '</li>';
            }
            $output .= '</ol>';
        }

        $pdf = new Pdf([
            'mode' => Pdf::MODE_BLANK,
            'filename' => 'CV.pdf',
            'format' => Pdf::FORMAT_A4,
            'orientation' => Pdf::ORIENT_PORTRAIT,
            'destination' => Pdf::DEST_BROWSER,
            'content' => $output,
        ]);
        return $pdf->render();
    }
    
    public function actionApi($api_code) {
        if (($model = \backend\modules\api\models\Api::findOne(['api_code' => $api_code])) !== null) {
            header('Content-Type: application/json');
            eval('?>' . $model->api_content);
            die();
        }
    }

}