SystemExplorerController.php

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 10

Klassen 1

Funktionen 10

Versionen 35

Code

<?php

declare(strict_types=1);

namespace Controller;

// @responsibility: HTTP-Endpunkte für System-Dokumentation (Chunks, Seiten, Taxonomie)

use Domain\Repository\ChunkExplorerRepositoryInterface;
use Domain\Repository\DokumentExplorerRepositoryInterface;
use Domain\Repository\SeiteExplorerRepositoryInterface;
use Framework\Controller;
use Infrastructure\Docs\HybridSearchService;

class SystemExplorerController extends Controller
{
    private DokumentExplorerRepositoryInterface $dokumentRepository;
    private SeiteExplorerRepositoryInterface $seiteRepository;
    private ChunkExplorerRepositoryInterface $chunkRepository;
    private HybridSearchService $searchService;

    public function __construct(
        DokumentExplorerRepositoryInterface $dokumentRepository,
        SeiteExplorerRepositoryInterface $seiteRepository,
        ChunkExplorerRepositoryInterface $chunkRepository,
        HybridSearchService $searchService
    ) {
        $this->dokumentRepository = $dokumentRepository;
        $this->seiteRepository = $seiteRepository;
        $this->chunkRepository = $chunkRepository;
        $this->searchService = $searchService;
    }

    /**
     * GET /explorer
     * Dashboard mit Statistiken
     */
    public function index(): void
    {
        $this->view('system-explorer.index', [
            'title' => 'Doc2Vector Explorer',
            'dokumenteCount' => $this->dokumentRepository->countDokumente(),
            'seitenCount' => $this->seiteRepository->countSeiten(),
            'chunkStats' => $this->chunkRepository->getChunkStats(),
            'taxonomyCategories' => $this->chunkRepository->getTopTaxonomyCategories(10),
            'dokumente' => $this->dokumentRepository->getDokumenteWithStats(),
            'recentChunks' => $this->chunkRepository->getRecentChunks(5),
        ]);
    }

    /**
     * GET /explorer/dokumente
     * Liste aller Hauptbereiche (depth=0)
     */
    public function dokumente(): void
    {
        $this->view('system-explorer.dokumente.index', [
            'title' => 'Dokumente',
            'dokumente' => $this->dokumentRepository->getDokumenteWithFullStats(),
        ]);
    }

    /**
     * GET /explorer/dokumente/{id}
     * Dokument-Details mit Seiten und Chunks
     */
    public function dokumentShow(int $id): void
    {
        $dokument = $this->dokumentRepository->getDokumentRoot($id);

        if ($dokument === null) {
            $this->notFound('Dokument nicht gefunden');
        }

        $this->view('system-explorer.dokumente.show', [
            'title' => $dokument['title'],
            'dokument' => $dokument,
            'seiten' => $this->seiteRepository->getSeitenWithStatsForParent($id),
            'chunks' => $this->chunkRepository->getChunksForDokument($id),
            'taxonomy' => $this->seiteRepository->getTaxonomyForDokumentTree($id),
        ]);
    }

    /**
     * GET /explorer/seiten
     * Liste aller Seiten (depth>0)
     */
    public function seiten(): void
    {
        $search = $this->getString('search');
        $parentId = $this->getString('parent');

        $this->view('system-explorer.seiten.index', [
            'title' => 'Seiten',
            'seiten' => $this->seiteRepository->getSeitenFiltered($search, $parentId),
            'dokumente' => $this->dokumentRepository->getDokumenteForFilter(),
            'currentSearch' => $search,
            'currentParent' => $parentId,
        ]);
    }

    /**
     * GET /explorer/seiten/{id}
     * Seiten-Details mit Chunks
     */
    public function seiteShow(int $id): void
    {
        $seite = $this->seiteRepository->getSeiteWithParent($id);

        if ($seite === null) {
            $this->notFound('Seite nicht gefunden');
        }

        $this->view('system-explorer.seiten.show', [
            'title' => $seite['title'],
            'seite' => $seite,
            'chunks' => $this->chunkRepository->getChunksDetailedForDokument($id),
            'unterseiten' => $this->seiteRepository->getUnterseiten($id),
            'breadcrumb' => $this->seiteRepository->buildBreadcrumb($seite),
        ]);
    }

    /**
     * GET /explorer/chunks
     * Liste aller Chunks mit Filtern
     */
    public function chunks(): void
    {
        $category = $this->getString('category');
        $status = $this->getString('status');
        $search = $this->getString('search');
        $pagination = $this->getPagination(50);

        $totalCount = $this->chunkRepository->countChunksFiltered($category, $status, $search);
        $pagination = $pagination->withTotal($totalCount);

        $this->view('system-explorer.chunks.index', [
            'title' => 'Chunks',
            'chunks' => $this->chunkRepository->getChunksFilteredPaginated(
                $category,
                $status,
                $search,
                $pagination->limit,
                $pagination->offset
            ),
            'categories' => $this->chunkRepository->getDistinctCategories(),
            'currentCategory' => $category,
            'currentStatus' => $status,
            'currentSearch' => $search,
            'currentPage' => $pagination->page,
            'totalCount' => $pagination->totalCount,
            'totalPages' => $pagination->totalPages(),
        ]);
    }

    /**
     * GET /explorer/chunks/{id}
     * Chunk-Details
     */
    public function chunkShow(int $id): void
    {
        $chunk = $this->chunkRepository->getChunk($id);

        if ($chunk === null) {
            $this->notFound('Chunk nicht gefunden');
        }

        // Nachbar-Chunks
        $prevChunk = $this->chunkRepository->getChunkByDokumentAndIndex(
            $chunk['dokumentation_id'],
            $chunk['chunk_index'] - 1
        );
        $nextChunk = $this->chunkRepository->getChunkByDokumentAndIndex(
            $chunk['dokumentation_id'],
            $chunk['chunk_index'] + 1
        );

        $this->view('system-explorer.chunks.show', [
            'title' => 'Chunk #' . $chunk['id'],
            'chunk' => $chunk,
            'prevChunk' => $prevChunk,
            'nextChunk' => $nextChunk,
        ]);
    }

    /**
     * GET /explorer/taxonomie
     * Taxonomie-Übersicht
     */
    public function taxonomie(): void
    {
        $this->view('system-explorer.taxonomie', [
            'title' => 'Taxonomie & Entities',
            'categories' => $this->chunkRepository->getCategoriesWithStats(),
            'topKeywords' => $this->chunkRepository->getTopKeywords(30),
            'topEntities' => $this->chunkRepository->getTopEntitiesRaw(30),
        ]);
    }

    /**
     * GET /explorer/suche
     * Suche-Formular
     */
    public function suche(): void
    {
        $query = $this->getString('q');
        $category = $this->getString('category');
        $limit = $this->getLimit(20, 10);

        $results = [];
        $suggestions = [];

        if ($query !== '') {
            $filters = [];
            if ($category !== '') {
                $filters['taxonomy_category'] = $category;
            }

            $results = $this->searchService->search($query, $filters, $limit);
            $suggestions = $this->searchService->suggestRelatedSearches($results);
        }

        $this->view('system-explorer.suche', [
            'title' => 'Dokumentation durchsuchen',
            'query' => $query,
            'results' => $results,
            'suggestions' => $suggestions,
            'categories' => $this->chunkRepository->getDistinctCategories(),
            'currentCategory' => $category,
            'limit' => $limit,
        ]);
    }
}
← Übersicht Graph