<?php

namespace api\modules\prolab\controllers;

use Yii;
use common\models\RiaLabD;
use api\modules\prolab\models\RiaLabDSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

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

    /**
     * Lists all RiaLabD models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new RiaLabDSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

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

    /**
     * Displays a single RiaLabD model.
     * @param string $RiaHDocDate
     * @param string $RiaHDocID
     * @param integer $RiaLDSeq
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($RiaHDocDate, $RiaHDocID, $RiaLDSeq)
    {
        return $this->render('view', [
            'model' => $this->findModel($RiaHDocDate, $RiaHDocID, $RiaLDSeq),
        ]);
    }

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'RiaHDocDate' => $model->RiaHDocDate, 'RiaHDocID' => $model->RiaHDocID, 'RiaLDSeq' => $model->RiaLDSeq]);
        }

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

    /**
     * Updates an existing RiaLabD model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $RiaHDocDate
     * @param string $RiaHDocID
     * @param integer $RiaLDSeq
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($RiaHDocDate, $RiaHDocID, $RiaLDSeq)
    {
        $model = $this->findModel($RiaHDocDate, $RiaHDocID, $RiaLDSeq);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'RiaHDocDate' => $model->RiaHDocDate, 'RiaHDocID' => $model->RiaHDocID, 'RiaLDSeq' => $model->RiaLDSeq]);
        }

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

    /**
     * Deletes an existing RiaLabD model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $RiaHDocDate
     * @param string $RiaHDocID
     * @param integer $RiaLDSeq
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($RiaHDocDate, $RiaHDocID, $RiaLDSeq)
    {
        $this->findModel($RiaHDocDate, $RiaHDocID, $RiaLDSeq)->delete();

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

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

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