Backup #453

ID453
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/ProtokollController.php
Version11
Typ modified
Größe2.9 KB
Hash5bbf585defa7e9a251f336d9e547c70f9007875c1cd8d08652268e08068abce4
Datum2025-12-22 10:27:54
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Write-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Controller;

use Domain\ValueObject\Pagination;
use Framework\Controller;
use Infrastructure\Persistence\KiProtokollRepository;

class ProtokollController extends Controller
{
    private KiProtokollRepository $protokollRepo;

    public function __construct(?KiProtokollRepository $protokollRepo = null)
    {
        $this->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);
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
699 15 modified 2.1 KB 2025-12-23 07:53
643 14 modified 2.1 KB 2025-12-23 04:47
469 13 modified 2.1 KB 2025-12-22 10:32
468 12 modified 2.1 KB 2025-12-22 10:32
453 11 modified 2.9 KB 2025-12-22 10:27
448 10 modified 5.3 KB 2025-12-22 10:19
407 9 modified 5.2 KB 2025-12-22 08:55
345 8 modified 5.1 KB 2025-12-22 08:12
344 7 modified 5.1 KB 2025-12-22 08:12
343 6 modified 5.1 KB 2025-12-22 08:12
306 5 modified 5.1 KB 2025-12-22 08:05
246 4 modified 5.2 KB 2025-12-22 01:46
135 3 modified 4.9 KB 2025-12-20 19:56
34 2 modified 5.7 KB 2025-12-20 17:23
3 1 modified 5.7 KB 2025-12-20 16:08

← Zurück zur Übersicht