repository = $repository; $this->apiFormatter = $apiFormatter; } /** * GET /semantic-explorer/entitaeten * Liste aller Entitaeten */ public function index(): void { $type = $this->getString('type'); $search = $this->getString('search'); $entities = $this->repository->findFiltered($type, $search); $stats = $this->repository->getStats(); $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->find($id); if ($entity === null) { $this->notFound('Entitaet nicht gefunden'); } $synonyms = $this->repository->findSynonyms($id); $outgoingRelations = $this->repository->getOutgoingRelations($id); $incomingRelations = $this->repository->getIncomingRelations($id); $chunks = $this->repository->findChunks($id); $classifications = $this->repository->findClassifications($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->getTypes(), ]); } /** * POST /semantic-explorer/entitaeten */ public function store(): void { $this->requireCsrf(); $input = $this->getJsonInput(); if (empty($input)) { $input = $_POST; } $name = trim($input['name'] ?? ''); $type = trim($input['type'] ?? ''); $description = trim($input['description'] ?? '') ?: null; if ($name === '' || $type === '') { if ($this->isHtmxRequest()) { $this->htmxError('Name und Typ sind erforderlich'); return; } $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400); return; } try { $id = $this->repository->create($name, $type, $description); if ($this->isHtmxRequest()) { $this->htmxRedirect('/semantic-explorer/entitaeten/' . $id); return; } $this->json($this->apiFormatter->created($id, 'Entität erstellt')); } catch (\Exception $e) { if ($this->isHtmxRequest()) { $this->htmxError($e->getMessage()); return; } $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->find($id); if ($entity === null) { $this->notFound('Entitaet nicht gefunden'); } $this->view('semantic-explorer.entitaeten.edit', [ 'title' => 'Entitaet bearbeiten', 'entity' => $entity, 'types' => $this->repository->getTypes(), ]); } /** * 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->update($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->delete($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); } } }