2025-12-01 16:47:52 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
2026-02-18 10:15:47 +07:00
|
|
|
use App\Traits\ResponseTrait;
|
2025-12-01 16:47:52 +07:00
|
|
|
use App\Controllers\BaseController;
|
|
|
|
|
use App\Models\AreaGeoModel;
|
|
|
|
|
|
2026-01-05 16:55:34 +07:00
|
|
|
class AreaGeoController extends BaseController {
|
2025-12-01 16:47:52 +07:00
|
|
|
use ResponseTrait;
|
|
|
|
|
|
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
$this->model = new AreaGeoModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
|
try {
|
2025-12-02 12:52:23 +07:00
|
|
|
$filters = [
|
|
|
|
|
'AreaGeoID' => $this->request->getVar('AreaGeoID') ?? null,
|
|
|
|
|
'AreaName' => $this->request->getVar('AreaName') ?? null
|
|
|
|
|
];
|
|
|
|
|
$rows = $this->model->getAreaGeos( $filters );
|
2025-12-01 16:47:52 +07:00
|
|
|
|
|
|
|
|
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
|
|
|
|
|
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProvinces() {
|
|
|
|
|
$rows = $this->model->getProvinces();
|
2026-01-26 10:27:28 +07:00
|
|
|
$transformed = array_map(function($row) {
|
|
|
|
|
return ['value' => $row['AreaGeoID'], 'label' => $row['AreaName']];
|
|
|
|
|
}, $rows);
|
|
|
|
|
if (empty($transformed)) { return $this->respond([ 'status' => 'success', 'data' => [] ], 200); }
|
|
|
|
|
return $this->respond([ 'status' => 'success', 'data' => $transformed ], 200);
|
2025-12-01 16:47:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCities() {
|
2026-02-16 10:16:07 +07:00
|
|
|
$filter = [ 'Parent' => $this->request->getVar('ProvinceID') ?? null ];
|
2025-12-02 13:19:42 +07:00
|
|
|
$rows = $this->model->getCities($filter);
|
2026-01-26 10:27:28 +07:00
|
|
|
$transformed = array_map(function($row) {
|
|
|
|
|
return ['value' => $row['AreaGeoID'], 'label' => $row['AreaName']];
|
|
|
|
|
}, $rows);
|
|
|
|
|
if (empty($transformed)) { return $this->respond([ 'status' => 'success', 'data' => [] ], 200); }
|
|
|
|
|
return $this->respond([ 'status' => 'success', 'data' => $transformed ], 200);
|
2025-12-01 16:47:52 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-05 16:55:34 +07:00
|
|
|
}
|