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