'Autorenprofil', 'structure' => 'Struktur', 'organization' => 'Organisation', 'contract' => 'Contract', 'rule' => 'Regel', 'system_prompt' => 'System-Prompt', ]; public function __construct(?ContentConfigRepository $configRepo = null) { $this->configRepo = $configRepo ?? new ContentConfigRepository(); } public function index(): void { $typeFilter = $this->getString('type'); $statusFilter = $this->getString('status'); $validType = in_array($typeFilter, self::TYPES, true) ? $typeFilter : null; $validStatus = in_array($statusFilter, ['draft', 'active', 'deprecated'], true) ? $statusFilter : null; $this->view('config.index', [ 'title' => 'Content-Konfiguration', 'configs' => $this->configRepo->findAll($validType, $validStatus), 'stats' => $this->configRepo->getStatistics(), 'types' => self::TYPES, 'typeLabels' => self::TYPE_LABELS, 'currentType' => $typeFilter, 'currentStatus' => $statusFilter, ]); } public function configNew(): void { $this->view('config.form', [ 'title' => 'Neue Konfiguration', 'config' => null, 'types' => self::TYPES, 'typeLabels' => self::TYPE_LABELS, 'parents' => $this->configRepo->getParentOptions(), 'isEdit' => false, ]); } public function store(): void { $this->requireCsrf(); $type = $_POST['type'] ?? ''; $name = trim($_POST['name'] ?? ''); $slug = trim($_POST['slug'] ?? ''); $description = trim($_POST['description'] ?? ''); $content = $_POST['content'] ?? '{}'; $version = trim($_POST['version'] ?? '1.0'); $status = $_POST['status'] ?? 'draft'; $parentId = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null; if (!in_array($type, self::TYPES, true) || $name === '' || $slug === '') { $_SESSION['error'] = 'Typ, Name und Slug sind erforderlich.'; header('Location: /config/new'); exit; } $decoded = json_decode($content, true); if ($decoded === null && $content !== 'null') { $_SESSION['error'] = 'Ungültiges JSON-Format.'; header('Location: /config/new'); exit; } $id = $this->configRepo->create( $type, $name, $slug, $description !== '' ? $description : null, $content, $version, $status, $parentId ); $_SESSION['success'] = 'Konfiguration erfolgreich erstellt.'; header('Location: /config/' . $id); exit; } public function show(string $id): void { $config = $this->configRepo->findById((int) $id); if ($config === null) { $this->notFound('Konfiguration nicht gefunden'); } $this->view('config.show', [ 'title' => $config['name'], 'config' => $config, 'children' => $this->configRepo->getChildren((int) $id), 'history' => $this->configRepo->getHistory((int) $id), 'typeLabels' => self::TYPE_LABELS, ]); } public function edit(string $id): void { $config = $this->configRepo->findById((int) $id); if ($config === null) { $this->notFound('Konfiguration nicht gefunden'); } $this->view('config.form', [ 'title' => 'Bearbeiten: ' . $config['name'], 'config' => $config, 'types' => self::TYPES, 'typeLabels' => self::TYPE_LABELS, 'parents' => $this->configRepo->getParentOptions((int) $id), 'isEdit' => true, ]); } public function update(string $id): void { $this->requireCsrf(); $config = $this->configRepo->findById((int) $id); if ($config === null) { $this->notFound('Konfiguration nicht gefunden'); } $name = trim($_POST['name'] ?? ''); $slug = trim($_POST['slug'] ?? ''); $description = trim($_POST['description'] ?? ''); $content = $_POST['content'] ?? '{}'; $newVersion = trim($_POST['new_version'] ?? ''); $changeDescription = trim($_POST['change_description'] ?? ''); $status = $_POST['status'] ?? $config['status']; $parentId = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null; if ($name === '' || $slug === '' || $newVersion === '') { $_SESSION['error'] = 'Name, Slug und neue Version sind erforderlich.'; header('Location: /config/' . $id . '/edit'); exit; } $decoded = json_decode($content, true); if ($decoded === null && $content !== 'null') { $_SESSION['error'] = 'Ungültiges JSON-Format.'; header('Location: /config/' . $id . '/edit'); exit; } $this->configRepo->saveHistory( (int) $id, $config['content'], $config['version'], 'web-ui', $changeDescription !== '' ? $changeDescription : 'Update auf Version ' . $newVersion ); $this->configRepo->update( (int) $id, $name, $slug, $description !== '' ? $description : null, $content, $newVersion, $status, $parentId ); $_SESSION['success'] = 'Konfiguration auf Version ' . $newVersion . ' aktualisiert.'; header('Location: /config/' . $id); exit; } public function delete(string $id): void { $this->requireCsrf(); $config = $this->configRepo->findById((int) $id); if ($config === null) { $this->notFound('Konfiguration nicht gefunden'); } if ($this->configRepo->countChildren((int) $id) > 0) { $_SESSION['error'] = 'Kann nicht gelöscht werden: Es existieren verknüpfte Einträge.'; header('Location: /config/' . $id); exit; } $this->configRepo->deleteHistory((int) $id); $this->configRepo->delete((int) $id); $_SESSION['success'] = 'Konfiguration gelöscht.'; header('Location: /config'); exit; } }