Files
sam-api/app/Models/Documents/DocumentTemplateSectionItem.php
권혁성 af42c115ae feat:검사 기준서 동적화 + 외부 키 매핑 동적화
- 템플릿별 동적 필드 정의 (document_template_section_fields)
- 외부 키 매핑 동적화 (document_template_links + link_values)
- 문서 레벨 연결 (document_links)
- 시스템 프리셋 (document_template_field_presets)
- section_items에 field_values JSON 컬럼 추가
- 기존 고정 필드 → 동적 field_values 데이터 마이그레이션
- search_api → source_table 전환 마이그레이션

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 08:37:55 +09:00

68 lines
1.7 KiB
PHP

<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 양식 섹션 검사항목 모델
*
* @property int $id
* @property int $section_id
* @property string|null $category 항목 분류
* @property string $item 검사항목
* @property string|null $standard 검사기준
* @property string|null $method 검사방식
* @property string|null $frequency 검사주기
* @property string|null $regulation 관련 규격
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateSectionItem extends Model
{
protected $table = 'document_template_section_items';
protected $fillable = [
'section_id',
'category',
'item',
'standard',
'tolerance',
'standard_criteria',
'method',
'measurement_type',
'frequency_n',
'frequency_c',
'frequency',
'regulation',
'field_values',
'sort_order',
];
protected $casts = [
'tolerance' => 'array',
'standard_criteria' => 'array',
'field_values' => 'array',
'sort_order' => 'integer',
'frequency_n' => 'integer',
'frequency_c' => 'integer',
];
/**
* field_values 우선, 없으면 기존 컬럼 fallback
*/
public function getFieldValue(string $key): mixed
{
if (! empty($this->field_values) && array_key_exists($key, $this->field_values)) {
return $this->field_values[$key];
}
return $this->attributes[$key] ?? null;
}
public function section(): BelongsTo
{
return $this->belongsTo(DocumentTemplateSection::class, 'section_id');
}
}