ProtokollController.php

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 4

Klassen 1

Funktionen 3

Versionen 15

Code

<?php

declare(strict_types=1);

namespace Controller;

// @responsibility: HTTP-Endpunkte für KI-Protokoll-Anzeige

use Framework\Controller;
use UseCases\Protokoll\ViewProtokollUseCase;

class ProtokollController extends Controller
{
    private ViewProtokollUseCase $protokollUseCase;

    public function __construct(ViewProtokollUseCase $protokollUseCase)
    {
        $this->protokollUseCase = $protokollUseCase;
    }

    public function index(): void
    {
        $pagination = $this->getPagination(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;

        $result = $this->protokollUseCase->getPaginated($searchVal, $statusVal, $modelVal, $pagination);
        $updatedPagination = $result['pagination'];

        $this->view('protokoll.index', [
            'title' => 'KI-Protokoll',
            'stats' => $this->protokollUseCase->getStatistics(),
            'entries' => array_map(fn ($dto) => $dto->toArray(), $result['entries']),
            'models' => $this->protokollUseCase->getDistinctModels(),
            'currentSearch' => $search,
            'currentStatus' => $status,
            'currentModel' => $model,
            'currentPage' => $updatedPagination->page,
            'totalCount' => $updatedPagination->totalCount,
            'totalPages' => $updatedPagination->totalPages(),
        ]);
    }

    public function show(string $id): void
    {
        $entry = $this->protokollUseCase->getById((int) $id);
        if ($entry === null) {
            $this->notFound('Protokoll-Eintrag nicht gefunden');
        }

        $nav = $this->protokollUseCase->getNavigation((int) $id);

        $this->view('protokoll.show', [
            'title' => 'Protokoll #' . $id,
            'entry' => $entry->toArray(),
            'prevEntry' => $nav['prevId'] !== null ? ['id' => $nav['prevId']] : false,
            'nextEntry' => $nav['nextId'] !== null ? ['id' => $nav['nextId']] : false,
        ]);
    }
}
← Übersicht Graph