protokollRepo = $protokollRepo ?? new KiProtokollRepository(); } public function getPaginated( ?string $search, ?string $status, ?string $model, Pagination $pagination ): array { $totalCount = $this->protokollRepo->countFiltered($search, $status, $model); $updatedPagination = $pagination->withTotal($totalCount); $entries = $this->protokollRepo->findPaginated( $search, $status, $model, $updatedPagination->limit, $updatedPagination->offset ); return [ 'entries' => array_map(fn (array $row) => ProtokollDTO::fromArray($row), $entries), 'pagination' => $updatedPagination, ]; } public function getById(int $id): ?ProtokollDTO { $entry = $this->protokollRepo->findById($id); if ($entry === null) { return null; } $entry['request_formatted'] = $this->formatJson($entry['request']); $entry['response_formatted'] = $this->formatJson($entry['response']); return ProtokollDTO::fromArray($entry); } public function getNavigation(int $id): array { return [ 'prevId' => $this->protokollRepo->findPreviousId($id), 'nextId' => $this->protokollRepo->findNextId($id), ]; } public function getStatistics(): array { return $this->protokollRepo->getStatistics(); } public function getDistinctModels(): array { return $this->protokollRepo->getDistinctModels(); } private function formatJson(?string $json): string { if ($json === null || $json === '') { return '-'; } $decoded = json_decode($json, true); if ($decoded === null) { return htmlspecialchars($json); } $formatted = json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); return $formatted !== false ? $formatted : htmlspecialchars($json); } }