Your IP : 216.73.216.79


Current Path : /var/www/html/school/backend/controllers/
Upload File :
Current File : /var/www/html/school/backend/controllers/LangController.php

<?php

namespace backend\controllers;

use Yii;
use backend\models\Lang;
use backend\models\LangDoc;
use backend\models\LangDocSearch;
use backend\models\Attachment;
use backend\models\LangSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;

/**
 * LangController implements the CRUD actions for Lang model.
 */
class LangController extends Controller {

    /**
     * @inheritdoc
     */
    public function behaviors() {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
//                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Lang models.
     * @return mixed
     */
//    public function actionIndex() {
//        $searchModel = new LangSearch();
//        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
//
//        return $this->render('index', [
//                    'searchModel' => $searchModel,
//                    'dataProvider' => $dataProvider,
//        ]);
//    }

    public function actionIndex($staffid) {
        $searchModel = new LangSearch();
        $searchModel->staff_info_id = $staffid;
        $dataProvider = $searchModel->searchAdmin(Yii::$app->request->queryParams);

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

    public function actionMyProfile() {
        $searchModel = new LangSearch();
        $dataProvider = $searchModel->searchMyProfile(Yii::$app->request->queryParams);

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

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

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

        $model->staff_info_id = $staffid;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $log = new \backend\models\Log();
            $log->module = Yii::$app->controller->id;
            $log->details = Yii::$app->controller->action->id . ":" . $model->id;

            $log->save();
            return $this->redirect(['index', 'staffid' => $staffid]);
        } else {
            return $this->render('create', [
                        'model' => $model,
                        'staffid' => $staffid,
            ]);
        }
    }

    public function actionCreateProfile() {
        $model = new Lang();
        $model->staff_info_id = Yii::$app->user->identity->staff->id;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $log = new \backend\models\Log();
            $log->module = Yii::$app->controller->id;
            $log->details = Yii::$app->controller->action->id . ":" . $model->id;

            $log->save();
            return $this->redirect(['my-profile']);
        } else {
            return $this->render('profile/createProfile', [
                        'model' => $model,
            ]);
        }
    }


    public function actionUpdate($id) {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $log = new \backend\models\Log();
            $log->module = Yii::$app->controller->id;
            $log->details = Yii::$app->controller->action->id . ":" . $model->id;

            $log->save();
            return $this->redirect(['index', 'staffid' => $model->staff_info_id]);
        } else {
            return $this->render('update', [
                        'model' => $model,
                        'staffid' => $model->staff_info_id,
                        'LangDoc' => $model->id,
            ]);
        }
    }

    public function actionUpdateProfile($id) {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $log = new \backend\models\Log();
            $log->module = Yii::$app->controller->id;
            $log->details = Yii::$app->controller->action->id . ":" . $model->id;

            $log->save();
            return $this->redirect(['my-profile']);
        } else {
            return $this->render('profile/updateProfile', [
                        'model' => $model,
            ]);
        }
    }



    /**
     * Deletes an existing Lang model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id, $staffid) {
        $this->findModel($id)->delete();
        $log = new \backend\models\Log();
        $log->module = Yii::$app->controller->id;
        $log->details = Yii::$app->controller->action->id . ":" . $id;

        $log->save();
        return $this->redirect(['index', 'staffid' => $staffid]);
    }

    public function actionDeleteProfile($id) {
        $this->findModel($id)->delete();
        $log = new \backend\models\Log();
        $log->module = Yii::$app->controller->id;
        $log->details = Yii::$app->controller->action->id . ":" . $id;

        $log->save();
        return $this->redirect(['my-profile']);
    }

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

    public function actionDownloadAttachment($id) {
        $att = \backend\models\Attachment::findOne($id);
        $path = getcwd() . "/uploads/langInfo/" . $att->file_name_sys;
        if (file_exists($path)) {
//            header('Content-Type:' . $att->doctype);
            header("Content-Disposition: attachment; filename={$att->file_name}");
            readfile($path);
        }
    }

}