레이아웃 이름 → 라우트 path 매핑 */ private array $routePathMap = []; /** @var array 소유 템플릿의 프론트엔드 다국어 사전 (점 표기 중첩) */ private array $translations = []; /** * 라우트 path 매핑을 주입합니다. * * @param array $routePathMap 레이아웃 이름 → 라우트 path * @return $this */ public function withRoutePathMap(array $routePathMap): self { $this->routePathMap = $routePathMap; return $this; } /** * 설명 해석에 쓸 소유 템플릿 사전을 주입합니다. * * @param array $translations 템플릿 프론트엔드 다국어 데이터 * @return $this */ public function withTranslations(array $translations): self { $this->translations = $translations; return $this; } /** * 목록 행을 배열로 변환합니다. * * @param Request $request 요청 객체 * @return array 목록 행 데이터 */ public function toArray(Request $request): array { $name = $this->getValue('name'); $size = (int) $this->getValue('size', 0); return [ 'id' => $this->getValue('id'), 'template_id' => $this->getValue('template_id'), 'name' => $name, 'description' => LayoutDescription::resolve($this->getValue('description'), $name, $this->translations), // 이 레이아웃을 사용하는 라우트의 path (routes.json 기준). 파일 선택 시 ?route= // 동기화 / 위지윅에서 넘어온 ?route= 로 해당 파일 복원에 사용. 'route_path' => $this->routePathMap[$name] ?? null, 'size' => $size, 'size_formatted' => $this->formatFileSize($size), 'has_update' => false, // 낙관적 잠금 — 편집 진입 후 저장 요청에 expected_lock_version 으로 전달 'lock_version' => (int) $this->getValue('lock_version', 0), // 상세 응답(LayoutResource)의 formatTimestamps() 와 같은 규약 — 사용자 timezone // 기준 문자열이다. 원시 ISO 를 그대로 내보내면 목록의 수정일 표기만 형식이 달라진다. 'created_at' => $this->formatDateTimeStringForUser($this->toCarbon($this->getValue('created_at'))), 'updated_at' => $this->formatDateTimeStringForUser($this->toCarbon($this->getValue('updated_at'))), ]; } /** * 값을 Carbon 인스턴스로 변환합니다. * * 경량 조회는 배열 행을 넘기므로 값이 Carbon 일 수도, 문자열일 수도, null 일 수도 있다. * * @param mixed $value 변환할 값 * @return Carbon|null 변환된 Carbon 또는 null */ private function toCarbon(mixed $value): ?Carbon { if ($value === null || $value === '') { return null; } return $value instanceof Carbon ? $value : Carbon::parse($value); } /** * 파일 크기를 사람이 읽는 단위로 변환합니다. * * @param int $bytes 바이트 수 * @return string 변환된 크기 문자열 */ private function formatFileSize(int $bytes): string { if ($bytes < 1024) { return $bytes.' B'; } if ($bytes < 1048576) { return round($bytes / 1024, 1).' KB'; } return round($bytes / 1048576, 1).' MB'; } }