Files
confirms/app/Models/common/CodeModel.php
2026-04-27 15:03:36 +09:00

92 lines
2.4 KiB
PHP

<?php
namespace App\Models\common;
use CodeIgniter\Model;
class CodeModel extends Model
{
/**
* 코드목록 읽어오기(Y만)
*/
public function getCodeList(string $category): array
{
return $this->db->table('codes')
->select('category, category_nm, cd, cd_nm')
->where('category', $category)
->where('use_yn', 'Y')
->orderBy('view_odr', 'asc')
->get()
->getResultArray();
}
public function getCodeLists(array $categories): array
{
if (empty($categories)) {
return [];
}
$result = $this->db->table('codes')
->select('category, category_nm, cd, cd_nm')
->whereIn('category', $categories)
->where('use_yn', 'Y')
->orderBy('category', 'asc')
->orderBy('view_odr', 'asc')
->get()
->getResultArray();
$groupedData = [];
foreach ($result as $item) {
$category = $item['category'];
if (!isset($groupedData[$category])) {
$groupedData[$category] = [
'name' => $item['category_nm'],
'items' => []
];
}
$groupedData[$category]['items'][$item['cd']] = $item['cd_nm'];
}
return $groupedData;
}
public function getCategoryCodeList(array $category = [], string $useYn = ''): array
{
if (empty($category)) {
return [];
}
$builder = $this->db->table('codes');
$builder->select('category, cd, cd_nm, use_yn');
$builder->whereIn('category', $category);
if (!empty($useYn)) {
$builder->where('use_yn', $useYn);
}
$builder->orderBy('category', 'asc');
$builder->orderBy('view_odr', 'asc');
$query = $builder->get();
$codes = [];
foreach ($query->getResultArray() as $row) {
$codes[$row['category']][] = ['cd' => $row['cd'], 'cd_nm' => $row['cd_nm']];
}
return $codes;
}
/**
* 코드 상세
*/
public function getCodeDetail(string $category, string $code): array
{
return $this->db->table('codes')
->select('category, category_nm, cd, cd_nm')
->where('category', $category)
->where('cd', $code)
->get()
->getResultArray();
}
}