- Auditable 트레잇: 모델 insert/update/delete 시 activity_log 자동 기록 (조회 제외, before/after JSON, 민감필드 마스킹, 사용자/IP) - 도메인 모델 28개에 적용 (로그성 테이블 제외) - 관리자 전용 조회: Admin\ActivityLog (기간/작업/대상/사용자 필터 + 상세 변경내역) - 라우트 admin/access/activity-logs(+상세), 메뉴 '활동 로그' 추가 - 테넌트 분리: 슈퍼=전체, 지자체관리자=소속 지자체만 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class SalesAgencyModel extends Model
|
|
{
|
|
use \App\Models\Traits\Auditable;
|
|
|
|
protected $table = 'sales_agency';
|
|
protected $primaryKey = 'sa_idx';
|
|
protected $returnType = 'object';
|
|
protected $useTimestamps = false;
|
|
protected $allowedFields = [
|
|
'sa_lg_idx',
|
|
'sa_kind',
|
|
'sa_code',
|
|
'sa_name',
|
|
'sa_regdate',
|
|
];
|
|
|
|
/** sales_agency 테이블에 sa_kind, sa_code 컬럼이 있는지(마이그레이션 적용 여부). */
|
|
public function hasKindCodeColumns(): bool
|
|
{
|
|
static $cache = null;
|
|
if ($cache === null) {
|
|
$cols = db_connect()->getFieldNames($this->table);
|
|
$cache = in_array('sa_kind', $cols, true) && in_array('sa_code', $cols, true);
|
|
}
|
|
|
|
return $cache;
|
|
}
|
|
|
|
/**
|
|
* 신규 스키마면 구분·코드 순, 아니면 명·PK 순(옛 DB 호환).
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function orderForDisplay()
|
|
{
|
|
return $this->hasKindCodeColumns()
|
|
? $this->orderBy('sa_kind', 'ASC')->orderBy('sa_code', 'ASC')
|
|
: $this->orderBy('sa_name', 'ASC')->orderBy('sa_idx', 'ASC');
|
|
}
|
|
}
|