surat/frontend/modules/frozen/controllers/SurgicalAddController.php

172 lines
5.1 KiB
PHP
Raw Normal View History

2024-12-25 03:04:59 +00:00
<?php
2025-01-02 09:35:59 +00:00
namespace frontend\modules\frozen\controllers;
2024-12-25 03:04:59 +00:00
use common\models\CaseSurgical;
2025-04-04 07:09:37 +00:00
use common\models\FrozenAdd;
2024-12-25 03:04:59 +00:00
use Yii;
use common\models\SurgicalAdd;
2025-04-04 07:09:37 +00:00
use frontend\modules\frozen\models\FrozenAddSearch;
2024-12-25 03:04:59 +00:00
use yii\base\Exception;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* SurgicalAddController implements the CRUD actions for SurgicalAdd model.
*/
class SurgicalAddController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all SurgicalAdd models.
* @return mixed
*/
public function actionIndex()
{
2025-04-04 07:09:37 +00:00
$searchModel = new FrozenAddSearch();
2024-12-25 03:04:59 +00:00
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single SurgicalAdd model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
$model = $this->findModel($id);
2025-04-04 07:09:37 +00:00
2025-07-01 07:53:41 +00:00
$case_surgical = CaseSurgical::findOne(['id_case' => $model->id_case]);
2025-04-04 07:09:37 +00:00
//$case_surgical->slides = SurgicalSlide::find()->where(['id_case' => $model->id_case])->all();
if ($model->load(Yii::$app->request->post())) {
2024-12-25 03:04:59 +00:00
try {
2025-04-04 07:09:37 +00:00
2025-07-01 07:53:41 +00:00
/* $items = Yii::$app->request->post();
2025-04-04 07:09:37 +00:00
//var_dump($items['SurgicalOperate']['items']);
//die();
2025-07-01 07:53:41 +00:00
if (!empty($items['CaseSurgical']['slides'])) {
foreach ($items['CaseSurgical']['slides'] as $key => $val) {
2025-04-04 07:09:37 +00:00
//var_dump($val['charge_id']);
//die();
if (empty($val['id'])) {
2025-07-01 07:53:41 +00:00
$slide = new SurgicalSlide();
2025-04-04 07:09:37 +00:00
} else {
2025-07-01 07:53:41 +00:00
$slide = SurgicalSlide::findOne($val['id']);
2025-04-04 07:09:37 +00:00
}
$slide->id_case = $model->id_case;
$slide->no_slide = $val['no_slide'];
$slide->quantity = $val['quantity'];
$slide->save();
}
2025-07-01 07:53:41 +00:00
} // if !empty()*/
2025-04-04 07:09:37 +00:00
2024-12-25 03:04:59 +00:00
$model->cut_id = Yii::$app->user->getId();
$model->end_at = date('Y-m-d H:i:s');
2025-07-01 07:53:41 +00:00
$model->status = 2;
2024-12-25 03:04:59 +00:00
$model->save();
Yii::$app->session->setFlash('success', 'บันทึกข้อมูลเรียบร้อยแล้ว');
return $this->redirect(['index']);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
2025-04-04 07:09:37 +00:00
$model->updateCounters(['hit' => 1]);
2024-12-25 03:04:59 +00:00
return $this->render('view', [
'model' => $model,
'case_surgical' => $case_surgical,
]);
}
/**
* Creates a new SurgicalAdd model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
2025-04-04 07:09:37 +00:00
$model = new FrozenAdd();
2024-12-25 03:04:59 +00:00
$model->add_at = date('Y-m-d H:i:s');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing SurgicalAdd model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing SurgicalAdd model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the SurgicalAdd model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return SurgicalAdd the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
2025-04-04 07:09:37 +00:00
if (($model = FrozenAdd::findOne($id)) !== null) {
2024-12-25 03:04:59 +00:00
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
2025-07-01 07:53:41 +00:00
}