relationRepository = $relationRepository; $this->entityRepository = $entityRepository; $this->apiFormatter = $apiFormatter; } /** * GET /semantic-explorer/relationen * Beziehungen zwischen Entitaeten */ public function index(): void { $type = $this->getString('type'); $relations = $this->relationRepository->findFiltered($type); $relationTypes = $this->relationRepository->getTypes(); $stats = $this->relationRepository->getStats(); $this->view('semantic-explorer.relationen', [ 'title' => 'Relationen', 'relations' => $relations, 'relationTypes' => $relationTypes, 'stats' => $stats, 'currentType' => $type, ]); } /** * GET /semantic-explorer/relationen/new */ public function create(): void { $this->view('semantic-explorer.relationen.new', [ 'title' => 'Neue Relation', 'entities' => $this->entityRepository->findAllSimple(), 'relationTypes' => $this->relationRepository->getTypesList(), ]); } /** * POST /semantic-explorer/relationen */ public function store(): void { $this->requireCsrf(); $input = $this->getJsonInput(); if (empty($input)) { $input = $_POST; } $sourceId = (int) ($input['source_entity_id'] ?? 0); $targetId = (int) ($input['target_entity_id'] ?? 0); $type = trim($input['relation_type'] ?? ''); $strength = (float) ($input['strength'] ?? 1.0); if ($sourceId === 0 || $targetId === 0 || $type === '') { if ($this->isHtmxRequest()) { $this->htmxError('Alle Felder sind erforderlich'); return; } $this->json($this->apiFormatter->validationError('Alle Felder sind erforderlich'), 400); return; } try { $id = $this->relationRepository->create($sourceId, $targetId, $type, $strength); if ($this->isHtmxRequest()) { $this->htmxRedirect('/semantic-explorer/relationen'); return; } $this->json($this->apiFormatter->created($id, 'Relation 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/relationen/{id}/edit */ public function edit(int $id): void { $relation = $this->relationRepository->find($id); if ($relation === null) { $this->notFound('Relation nicht gefunden'); } $this->view('semantic-explorer.relationen.edit', [ 'title' => 'Relation bearbeiten', 'relation' => $relation, 'relationTypes' => $this->relationRepository->getTypesList(), ]); } /** * POST /semantic-explorer/relationen/{id} */ public function update(int $id): void { $input = $this->getJsonInput(); $type = trim($input['relation_type'] ?? ''); $strength = (float) ($input['strength'] ?? 1.0); if ($type === '') { $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400); return; } try { $this->relationRepository->update($id, $type, $strength); $this->json($this->apiFormatter->ok('Relation aktualisiert')); } catch (\Exception $e) { $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500); } } /** * POST /semantic-explorer/relationen/{id}/delete */ public function destroy(int $id): void { try { $this->relationRepository->delete($id); $this->json($this->apiFormatter->ok('Relation gelöscht')); } catch (\Exception $e) { $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500); } } }