2025-09-18 16:31:56 +07:00
|
|
|
<?php
|
2025-10-16 11:09:36 +07:00
|
|
|
namespace App\Controllers\Contact;
|
2025-09-18 16:31:56 +07:00
|
|
|
|
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
2025-10-15 11:01:52 +07:00
|
|
|
use App\Controllers\BaseController;
|
2025-10-14 18:53:06 +07:00
|
|
|
use App\Models\Contact\OccupationModel;
|
2025-09-18 16:31:56 +07:00
|
|
|
|
2026-01-05 16:55:34 +07:00
|
|
|
class OccupationController extends BaseController {
|
2025-09-18 16:31:56 +07:00
|
|
|
use ResponseTrait;
|
|
|
|
|
|
2025-09-29 10:56:34 +07:00
|
|
|
protected $db;
|
2025-10-14 18:53:06 +07:00
|
|
|
protected $model;
|
|
|
|
|
protected $rules;
|
2025-09-29 10:56:34 +07:00
|
|
|
|
2025-09-18 16:31:56 +07:00
|
|
|
public function __construct() {
|
|
|
|
|
$this->db = \Config\Database::connect();
|
2025-10-14 18:53:06 +07:00
|
|
|
$this->model = new OccupationModel();
|
|
|
|
|
$this->rules = [ 'OccCode' => 'required','OccText' => 'required' ];
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index() {
|
2025-12-01 16:47:52 +07:00
|
|
|
$OccCode = $this->request->getVar('OccCode');
|
|
|
|
|
$OccText = $this->request->getVar('OccText');
|
|
|
|
|
$rows = $this->model->getOccupations($OccCode,$OccText);
|
|
|
|
|
|
2025-09-18 16:31:56 +07:00
|
|
|
if (empty($rows)) {
|
2025-10-01 12:40:05 +07:00
|
|
|
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
|
2025-10-01 12:40:05 +07:00
|
|
|
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show($OccupationID = null) {
|
2025-09-29 10:56:34 +07:00
|
|
|
$model = new OccupationModel();
|
2025-12-29 12:55:31 +07:00
|
|
|
$row = $model->find($OccupationID);
|
|
|
|
|
if (empty($row)) {
|
|
|
|
|
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
2025-12-29 12:55:31 +07:00
|
|
|
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create() {
|
2025-10-01 12:40:05 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2025-09-18 16:31:56 +07:00
|
|
|
try {
|
2025-10-15 11:01:52 +07:00
|
|
|
$this->model->insert($input);
|
|
|
|
|
$id = $this->model->getInsertID();
|
|
|
|
|
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
2025-09-18 16:31:56 +07:00
|
|
|
} catch (\Throwable $e) {
|
2025-10-01 12:40:05 +07:00
|
|
|
$this->db->transRollback();
|
|
|
|
|
return $this->failServerError('Exception : ' . $e->getMessage());
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update() {
|
2025-10-01 12:40:05 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2025-09-18 16:31:56 +07:00
|
|
|
try {
|
2025-10-15 11:01:52 +07:00
|
|
|
$this->model->update($input['OccupationID'], $input);
|
|
|
|
|
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['OccupationID'] ], 201);
|
2025-09-18 16:31:56 +07:00
|
|
|
} catch (\Throwable $e) {
|
2025-10-01 12:40:05 +07:00
|
|
|
return $this->failServerError('Exception : ' . $e->getMessage());
|
2025-09-18 16:31:56 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 16:55:34 +07:00
|
|
|
}
|