Backup #613

ID613
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/EntityController.php
Version6
Typ modified
Größe5.2 KB
Hash646bc0fe92d4d7d52b22ccc07b737207c30a8e037445d84c43a366402af2f22c
Datum2025-12-23 04:42:27
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Controller;

use Framework\Controller;
use Infrastructure\Formatter\ApiResponseFormatter;
use Infrastructure\SemanticExplorerRepository;

/**
 * EntityController - CRUD for Semantic Explorer Entities
 *
 * Extracted from SemanticExplorerController for SRP compliance.
 */
class EntityController extends Controller
{
    private SemanticExplorerRepository $repository;
    private ApiResponseFormatter $apiFormatter;

    public function __construct(
        ?SemanticExplorerRepository $repository = null,
        ?ApiResponseFormatter $apiFormatter = null
    ) {
        $this->repository = $repository ?? new SemanticExplorerRepository();
        $this->apiFormatter = $apiFormatter ?? new ApiResponseFormatter();
    }

    /**
     * GET /semantic-explorer/entitaeten
     * Liste aller Entitaeten
     */
    public function index(): void
    {
        $type = $this->getString('type');
        $search = $this->getString('search');

        $entities = $this->repository->getEntitiesFiltered($type, $search);
        $stats = $this->repository->getEntityStats();

        $this->view('semantic-explorer.entitaeten.index', [
            'title' => 'Entitaeten',
            'entities' => $entities,
            'stats' => $stats,
            'currentType' => $type,
            'currentSearch' => $search,
        ]);
    }

    /**
     * GET /semantic-explorer/entitaeten/{id}
     * Entitaet-Details
     */
    public function show(int $id): void
    {
        $entity = $this->repository->getEntity($id);

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

        $synonyms = $this->repository->getEntitySynonyms($id);
        $outgoingRelations = $this->repository->getOutgoingRelations($id);
        $incomingRelations = $this->repository->getIncomingRelations($id);
        $chunks = $this->repository->getChunksForEntity($id);
        $classifications = $this->repository->getEntityClassifications($id);

        $this->view('semantic-explorer.entitaeten.show', [
            'title' => $entity['name'],
            'entity' => $entity,
            'synonyms' => $synonyms,
            'outgoingRelations' => $outgoingRelations,
            'incomingRelations' => $incomingRelations,
            'chunks' => $chunks,
            'classifications' => $classifications,
        ]);
    }

    /**
     * GET /semantic-explorer/entitaeten/new
     */
    public function create(): void
    {
        $this->view('semantic-explorer.entitaeten.new', [
            'title' => 'Neue Entitaet',
            'types' => $this->repository->getEntityTypes(),
        ]);
    }

    /**
     * POST /semantic-explorer/entitaeten
     */
    public function store(): void
    {
        $input = $this->getJsonInput();

        $name = trim($input['name'] ?? '');
        $type = trim($input['type'] ?? '');
        $description = trim($input['description'] ?? '') ?: null;

        if ($name === '' || $type === '') {
            $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);

            return;
        }

        try {
            $id = $this->repository->createEntity($name, $type, $description);
            $this->json($this->apiFormatter->created($id, 'Entität erstellt'));
        } catch (\Exception $e) {
            $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
        }
    }

    /**
     * GET /semantic-explorer/entitaeten/{id}/edit
     */
    public function edit(int $id): void
    {
        $entity = $this->repository->getEntity($id);

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

        $this->view('semantic-explorer.entitaeten.edit', [
            'title' => 'Entitaet bearbeiten',
            'entity' => $entity,
            'types' => $this->repository->getEntityTypes(),
        ]);
    }

    /**
     * POST /semantic-explorer/entitaeten/{id}
     */
    public function update(int $id): void
    {
        $input = $this->getJsonInput();

        $name = trim($input['name'] ?? '');
        $type = trim($input['type'] ?? '');
        $description = trim($input['description'] ?? '') ?: null;

        if ($name === '' || $type === '') {
            $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);

            return;
        }

        try {
            $this->repository->updateEntity($id, $name, $type, $description);
            $this->json($this->apiFormatter->ok('Entität aktualisiert'));
        } catch (\Exception $e) {
            $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
        }
    }

    /**
     * POST /semantic-explorer/entitaeten/{id}/delete
     */
    public function delete(int $id): void
    {
        try {
            $success = $this->repository->deleteEntity($id);
            if ($success) {
                $this->json($this->apiFormatter->ok('Entität gelöscht'));
            } else {
                $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);
            }
        } catch (\Exception $e) {
            $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
        }
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
1986 18 modified 6.5 KB 2025-12-28 03:00
1714 17 modified 5.5 KB 2025-12-27 12:27
1713 16 modified 5.0 KB 2025-12-27 12:27
1094 15 modified 5.0 KB 2025-12-25 09:19
1093 14 modified 5.0 KB 2025-12-25 09:19
1092 13 modified 5.0 KB 2025-12-25 09:19
1091 12 modified 5.0 KB 2025-12-25 09:19
1090 11 modified 5.0 KB 2025-12-25 09:19
1089 10 modified 5.1 KB 2025-12-25 09:19
1088 9 modified 5.1 KB 2025-12-25 09:19
1087 8 modified 5.1 KB 2025-12-25 09:17
691 7 modified 5.1 KB 2025-12-23 07:52
613 6 modified 5.2 KB 2025-12-23 04:42
515 5 modified 5.1 KB 2025-12-22 15:48
514 4 modified 5.0 KB 2025-12-22 15:48
513 3 modified 4.8 KB 2025-12-22 15:48
302 2 modified 4.7 KB 2025-12-22 08:04
301 1 modified 4.8 KB 2025-12-22 08:04

← Zurück zur Übersicht