<?php

namespace backend\controllers;

use backend\models\MasterKompetensiUnit;
use backend\models\MasterKompetensiUnitSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * MasterKompetensiUnitController implements the CRUD actions for MasterKompetensiUnit model.
 */
class MasterKompetensiUnitController extends Controller
{
    /**
     * @inheritDoc
     */
    public function behaviors()
    {
        return array_merge(
            parent::behaviors(),
            [
                'verbs' => [
                    'class' => VerbFilter::className(),
                    'actions' => [
                        'delete' => ['POST'],
                    ],
                ],
            ]
        );
    }

    /**
     * Lists all MasterKompetensiUnit models.
     *
     * @return string
     */
    public function actionIndex()
    {
        $searchModel = new MasterKompetensiUnitSearch();
        $dataProvider = $searchModel->search($this->request->queryParams);

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

    /**
     * Displays a single MasterKompetensiUnit model.
     * @param string $MASKOMU_UUID Maskomu Uuid
     * @return string
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($MASKOMU_UUID)
    {
        return $this->render('view', [
            'model' => $this->findModel($MASKOMU_UUID),
        ]);
    }

    /**
     * Creates a new MasterKompetensiUnit model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return string|\yii\web\Response
     */
    public function actionCreate()
    {
        $model = new MasterKompetensiUnit();

        if ($this->request->isPost) {
            if ($model->load($this->request->post()) && $model->save()) {
                return $this->redirect(['view', 'MASKOMU_UUID' => $model->MASKOMU_UUID]);
            }
        } else {
            $model->loadDefaultValues();
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }

    /**
     * Updates an existing MasterKompetensiUnit model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $MASKOMU_UUID Maskomu Uuid
     * @return string|\yii\web\Response
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($MASKOMU_UUID)
    {
        $model = $this->findModel($MASKOMU_UUID);

        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
            return $this->redirect(['view', 'MASKOMU_UUID' => $model->MASKOMU_UUID]);
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }

    /**
     * Deletes an existing MasterKompetensiUnit model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $MASKOMU_UUID Maskomu Uuid
     * @return \yii\web\Response
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($MASKOMU_UUID)
    {
        $this->findModel($MASKOMU_UUID)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the MasterKompetensiUnit model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $MASKOMU_UUID Maskomu Uuid
     * @return MasterKompetensiUnit the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($MASKOMU_UUID)
    {
        if (($model = MasterKompetensiUnit::findOne(['MASKOMU_UUID' => $MASKOMU_UUID])) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }
}
