protokollRepo = $protokollRepo ?? new KiProtokollRepository(); } public function index(): void { $pagination = Pagination::fromRequest(50); $search = $this->getString('search'); $status = $this->getString('status'); $model = $this->getString('model'); $searchVal = $search !== '' ? $search : null; $statusVal = $status !== '' ? $status : null; $modelVal = $model !== '' ? $model : null; $totalCount = $this->protokollRepo->countFiltered($searchVal, $statusVal, $modelVal); $pagination = $pagination->withTotal($totalCount); $entries = $this->protokollRepo->findPaginated( $searchVal, $statusVal, $modelVal, $pagination->limit, $pagination->offset ); $this->view('protokoll.index', [ 'title' => 'KI-Protokoll', 'stats' => $this->protokollRepo->getStatistics(), 'entries' => $entries, 'models' => $this->protokollRepo->getDistinctModels(), 'currentSearch' => $search, 'currentStatus' => $status, 'currentModel' => $model, 'currentPage' => $pagination->page, 'totalCount' => $pagination->totalCount, 'totalPages' => $pagination->totalPages(), ]); } public function show(string $id): void { $entry = $this->protokollRepo->findById((int) $id); if ($entry === null) { $this->notFound('Protokoll-Eintrag nicht gefunden'); } $entry['request_formatted'] = $this->formatJson($entry['request']); $entry['response_formatted'] = $this->formatJson($entry['response']); $prevId = $this->protokollRepo->findPreviousId((int) $id); $nextId = $this->protokollRepo->findNextId((int) $id); $this->view('protokoll.show', [ 'title' => 'Protokoll #' . $id, 'entry' => $entry, 'prevEntry' => $prevId !== null ? ['id' => $prevId] : false, 'nextEntry' => $nextId !== null ? ['id' => $nextId] : false, ]); } 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); } }