clqms-be/app/Controllers/Contact/OccupationController.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

65 lines
2.2 KiB
PHP

<?php
namespace App\Controllers\Contact;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Contact\OccupationModel;
class OccupationController extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
protected $rules;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new OccupationModel();
$this->rules = [ 'OccCode' => 'required','OccText' => 'required' ];
}
public function index() {
$OccCode = $this->request->getVar('OccCode');
$OccText = $this->request->getVar('OccText');
$rows = $this->model->getOccupations($OccCode,$OccText);
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($OccupationID = null) {
$model = new OccupationModel();
$row = $model->find($OccupationID);
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 create() {
$input = $this->request->getJSON(true);
try {
$this->model->insert($input);
$id = $this->model->getInsertID();
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
$this->db->transRollback();
return $this->failServerError('Exception : ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
$this->model->update($input['OccupationID'], $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['OccupationID'] ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Exception : ' . $e->getMessage());
}
}
}