clqms-be/app/Controllers/Organization/DisciplineController.php
mahdahar cd65e91db1 refactor: Rename controllers to follow CodeIgniter 4 naming convention
- Rename all controllers from X.php to XController.php format
- Add new RefTxtModel for text-based reference ranges
- Rename group_dialog.php to grp_dialog.php and remove title_dialog.php
- Add comprehensive test suite for v2/master/TestDef module
- Update Routes.php to reflect controller renames
- Remove obsolete data files (clqms_v2.sql, lab.dbml)
2026-01-05 16:55:34 +07:00

83 lines
2.7 KiB
PHP

<?php
namespace App\Controllers\Organization;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Organization\DisciplineModel;
class DisciplineController extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new DisciplineModel();
}
public function index() {
$filter = [
'DisciplineCode' => $this->request->getVar('DisciplineCode'),
'DisciplineName' => $this->request->getVar('DisciplineName'),
];
$rows = $this->model->getDisciplines($filter);
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($DisciplineID = null) {
$row = $this->model->where('DisciplineID', $DisciplineID)->first();
if (empty($row)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$id = $input["DisciplineID"];
if (!$id) { return $this->failValidationErrors('ID is required.'); }
$this->model->delete($id);
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$id = $this->model->insert($input,true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
$id = $input['DisciplineID'];
$this->model->update($id, $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
/*
try {
$id = $input['DisciplineID'];
$this->model->where('DisciplineID', $id)->update();
echo $this->model->getLastQuery();
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage() );
}
*/
}
}