{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
"old_string": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass PromptsController extends Controller\n{\n private \\PDO $db;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }\n\n \/**\n * GET \/prompts\n *\/\n public function index(): void\n {\n $stmt = $this->db->query('\n SELECT p.*,\n (SELECT COUNT(*) FROM critics c WHERE c.prompt_id = p.id) as critic_count\n FROM prompts p\n ORDER BY p.name\n ');\n $prompts = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $stats = $this->getStatistics();\n\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => $prompts,\n 'stats' => $stats,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/new\n *\/\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n \/**\n * POST \/prompts\n *\/\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, ?)\n ');\n $stmt->execute([$name, $version, $content, $isActive]);\n $id = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * GET \/prompts\/{id}\n *\/\n public function show(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Verknüpfte Critics laden\n $stmt = $this->db->prepare('SELECT * FROM critics WHERE prompt_id = ? ORDER BY name');\n $stmt->execute([$id]);\n $linkedCritics = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $linkedCritics,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/{id}\/edit\n *\/\n public function edit(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n \/**\n * POST \/prompts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $stmt = $this->db->prepare('\n UPDATE prompts\n SET name = ?, version = ?, content = ?, is_active = ?\n WHERE id = ?\n ');\n $stmt->execute([$name, $version, $content, $isActive, $id]);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/delete\n *\/\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Prüfen ob Critics verknüpft sind\n $stmt = $this->db->prepare('SELECT COUNT(*) FROM critics WHERE prompt_id = ?');\n $stmt->execute([$id]);\n $criticCount = (int) $stmt->fetchColumn();\n\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $stmt = $this->db->prepare('DELETE FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/duplicate\n *\/\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newVersion = '1.0';\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, 0)\n ');\n $stmt->execute([$newName, $newVersion, $prompt['content']]);\n $newId = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n\n \/\/ ========== Private Helpers ==========\n\n private function findById(int $id): ?array\n {\n $stmt = $this->db->prepare('SELECT * FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n return $result !== false ? $result : null;\n }\n\n private function getStatistics(): array\n {\n $stats = ['total' => 0, 'active' => 0, 'inactive' => 0, 'linked_to_critics' => 0];\n\n $stmt = $this->db->query('SELECT COUNT(*) as cnt, SUM(is_active) as active FROM prompts');\n $row = $stmt->fetch(\\PDO::FETCH_ASSOC);\n $stats['total'] = (int) $row['cnt'];\n $stats['active'] = (int) $row['active'];\n $stats['inactive'] = $stats['total'] - $stats['active'];\n\n $stmt = $this->db->query('SELECT COUNT(DISTINCT prompt_id) FROM critics WHERE prompt_id IS NOT NULL');\n $stats['linked_to_critics'] = (int) $stmt->fetchColumn();\n\n return $stats;\n }\n}",
"new_string": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Persistence\\PromptsRepository;\n\nclass PromptsController extends Controller\n{\n private PromptsRepository $promptsRepo;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct(?PromptsRepository $promptsRepo = null)\n {\n $this->promptsRepo = $promptsRepo ?? new PromptsRepository();\n }\n\n public function index(): void\n {\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => $this->promptsRepo->findAll(),\n 'stats' => $this->promptsRepo->getStatistics(),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $id = $this->promptsRepo->create($name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $this->promptsRepo->delete((int) $id);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n}"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
"oldString": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass PromptsController extends Controller\n{\n private \\PDO $db;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }\n\n \/**\n * GET \/prompts\n *\/\n public function index(): void\n {\n $stmt = $this->db->query('\n SELECT p.*,\n (SELECT COUNT(*) FROM critics c WHERE c.prompt_id = p.id) as critic_count\n FROM prompts p\n ORDER BY p.name\n ');\n $prompts = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $stats = $this->getStatistics();\n\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => $prompts,\n 'stats' => $stats,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/new\n *\/\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n \/**\n * POST \/prompts\n *\/\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, ?)\n ');\n $stmt->execute([$name, $version, $content, $isActive]);\n $id = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * GET \/prompts\/{id}\n *\/\n public function show(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Verknüpfte Critics laden\n $stmt = $this->db->prepare('SELECT * FROM critics WHERE prompt_id = ? ORDER BY name');\n $stmt->execute([$id]);\n $linkedCritics = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $linkedCritics,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/{id}\/edit\n *\/\n public function edit(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n \/**\n * POST \/prompts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $stmt = $this->db->prepare('\n UPDATE prompts\n SET name = ?, version = ?, content = ?, is_active = ?\n WHERE id = ?\n ');\n $stmt->execute([$name, $version, $content, $isActive, $id]);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/delete\n *\/\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Prüfen ob Critics verknüpft sind\n $stmt = $this->db->prepare('SELECT COUNT(*) FROM critics WHERE prompt_id = ?');\n $stmt->execute([$id]);\n $criticCount = (int) $stmt->fetchColumn();\n\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $stmt = $this->db->prepare('DELETE FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/duplicate\n *\/\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newVersion = '1.0';\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, 0)\n ');\n $stmt->execute([$newName, $newVersion, $prompt['content']]);\n $newId = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n\n \/\/ ========== Private Helpers ==========\n\n private function findById(int $id): ?array\n {\n $stmt = $this->db->prepare('SELECT * FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n return $result !== false ? $result : null;\n }\n\n private function getStatistics(): array\n {\n $stats = ['total' => 0, 'active' => 0, 'inactive' => 0, 'linked_to_critics' => 0];\n\n $stmt = $this->db->query('SELECT COUNT(*) as cnt, SUM(is_active) as active FROM prompts');\n $row = $stmt->fetch(\\PDO::FETCH_ASSOC);\n $stats['total'] = (int) $row['cnt'];\n $stats['active'] = (int) $row['active'];\n $stats['inactive'] = $stats['total'] - $stats['active'];\n\n $stmt = $this->db->query('SELECT COUNT(DISTINCT prompt_id) FROM critics WHERE prompt_id IS NOT NULL');\n $stats['linked_to_critics'] = (int) $stmt->fetchColumn();\n\n return $stats;\n }\n}",
"newString": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Persistence\\PromptsRepository;\n\nclass PromptsController extends Controller\n{\n private PromptsRepository $promptsRepo;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct(?PromptsRepository $promptsRepo = null)\n {\n $this->promptsRepo = $promptsRepo ?? new PromptsRepository();\n }\n\n public function index(): void\n {\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => $this->promptsRepo->findAll(),\n 'stats' => $this->promptsRepo->getStatistics(),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $id = $this->promptsRepo->create($name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $this->promptsRepo->delete((int) $id);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n}",
"originalFile": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass PromptsController extends Controller\n{\n private \\PDO $db;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }\n\n \/**\n * GET \/prompts\n *\/\n public function index(): void\n {\n $stmt = $this->db->query('\n SELECT p.*,\n (SELECT COUNT(*) FROM critics c WHERE c.prompt_id = p.id) as critic_count\n FROM prompts p\n ORDER BY p.name\n ');\n $prompts = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $stats = $this->getStatistics();\n\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => $prompts,\n 'stats' => $stats,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/new\n *\/\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n \/**\n * POST \/prompts\n *\/\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, ?)\n ');\n $stmt->execute([$name, $version, $content, $isActive]);\n $id = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * GET \/prompts\/{id}\n *\/\n public function show(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Verknüpfte Critics laden\n $stmt = $this->db->prepare('SELECT * FROM critics WHERE prompt_id = ? ORDER BY name');\n $stmt->execute([$id]);\n $linkedCritics = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $linkedCritics,\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n \/**\n * GET \/prompts\/{id}\/edit\n *\/\n public function edit(string $id): void\n {\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n \/**\n * POST \/prompts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $stmt = $this->db->prepare('\n UPDATE prompts\n SET name = ?, version = ?, content = ?, is_active = ?\n WHERE id = ?\n ');\n $stmt->execute([$name, $version, $content, $isActive, $id]);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/delete\n *\/\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n \/\/ Prüfen ob Critics verknüpft sind\n $stmt = $this->db->prepare('SELECT COUNT(*) FROM critics WHERE prompt_id = ?');\n $stmt->execute([$id]);\n $criticCount = (int) $stmt->fetchColumn();\n\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $stmt = $this->db->prepare('DELETE FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n \/**\n * POST \/prompts\/{id}\/duplicate\n *\/\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->findById((int) $id);\n\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newVersion = '1.0';\n\n $stmt = $this->db->prepare('\n INSERT INTO prompts (name, version, content, is_active)\n VALUES (?, ?, ?, 0)\n ');\n $stmt->execute([$newName, $newVersion, $prompt['content']]);\n $newId = $this->db->lastInsertId();\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n\n \/\/ ========== Private Helpers ==========\n\n private function findById(int $id): ?array\n {\n $stmt = $this->db->prepare('SELECT * FROM prompts WHERE id = ?');\n $stmt->execute([$id]);\n $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n return $result !== false ? $result : null;\n }\n\n private function getStatistics(): array\n {\n $stats = ['total' => 0, 'active' => 0, 'inactive' => 0, 'linked_to_critics' => 0];\n\n $stmt = $this->db->query('SELECT COUNT(*) as cnt, SUM(is_active) as active FROM prompts');\n $row = $stmt->fetch(\\PDO::FETCH_ASSOC);\n $stats['total'] = (int) $row['cnt'];\n $stats['active'] = (int) $row['active'];\n $stats['inactive'] = $stats['total'] - $stats['active'];\n\n $stmt = $this->db->query('SELECT COUNT(DISTINCT prompt_id) FROM critics WHERE prompt_id IS NOT NULL');\n $stats['linked_to_critics'] = (int) $stmt->fetchColumn();\n\n return $stats;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 3,
"oldLines": 11,
"newStart": 3,
"newLines": 11,
"lines": [
" namespace Controller;",
" ",
" use Framework\\Controller;",
"-use Infrastructure\\Config\\DatabaseFactory;",
"+use Infrastructure\\Persistence\\PromptsRepository;",
" ",
" class PromptsController extends Controller",
" {",
"- private \\PDO $db;",
"+ private PromptsRepository $promptsRepo;",
" ",
" private const PROMPT_TYPES = [",
" 'critic' => 'Critic-Prompt',"
]
},
{
"oldStart": 17,
"oldLines": 37,
"newStart": 17,
"newLines": 21,
"lines": [
" 'other' => 'Sonstiges',",
" ];",
" ",
"- public function __construct()",
"+ public function __construct(?PromptsRepository $promptsRepo = null)",
" {",
"- $this->db = DatabaseFactory::content();",
"+ $this->promptsRepo = $promptsRepo ?? new PromptsRepository();",
" }",
" ",
"- \/**",
"- * GET \/prompts",
"- *\/",
" public function index(): void",
" {",
"- $stmt = $this->db->query('",
"- SELECT p.*,",
"- (SELECT COUNT(*) FROM critics c WHERE c.prompt_id = p.id) as critic_count",
"- FROM prompts p",
"- ORDER BY p.name",
"- ');",
"- $prompts = $stmt->fetchAll(\\PDO::FETCH_ASSOC);",
"-",
"- $stats = $this->getStatistics();",
"-",
" $this->view('prompts.index', [",
" 'title' => 'Prompts verwalten',",
"- 'prompts' => $prompts,",
"- 'stats' => $stats,",
"+ 'prompts' => $this->promptsRepo->findAll(),",
"+ 'stats' => $this->promptsRepo->getStatistics(),",
" 'promptTypes' => self::PROMPT_TYPES,",
" ]);",
" }",
" ",
"- \/**",
"- * GET \/prompts\/new",
"- *\/",
" public function promptsNew(): void",
" {",
" $this->view('prompts.form', ["
]
},
{
"oldStart": 58,
"oldLines": 9,
"newStart": 42,
"newLines": 6,
"lines": [
" ]);",
" }",
" ",
"- \/**",
"- * POST \/prompts",
"- *\/",
" public function store(): void",
" {",
" $this->requireCsrf();"
]
},
{
"oldStart": 76,
"oldLines": 49,
"newStart": 57,
"newLines": 31,
"lines": [
" exit;",
" }",
" ",
"- $stmt = $this->db->prepare('",
"- INSERT INTO prompts (name, version, content, is_active)",
"- VALUES (?, ?, ?, ?)",
"- ');",
"- $stmt->execute([$name, $version, $content, $isActive]);",
"- $id = $this->db->lastInsertId();",
"+ $id = $this->promptsRepo->create($name, $version, $content, $isActive);",
" ",
" $_SESSION['success'] = 'Prompt erfolgreich erstellt.';",
" header('Location: \/prompts\/' . $id);",
" exit;",
" }",
" ",
"- \/**",
"- * GET \/prompts\/{id}",
"- *\/",
" public function show(string $id): void",
" {",
"- $prompt = $this->findById((int) $id);",
"-",
"+ $prompt = $this->promptsRepo->findById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }",
" ",
"- \/\/ Verknüpfte Critics laden",
"- $stmt = $this->db->prepare('SELECT * FROM critics WHERE prompt_id = ? ORDER BY name');",
"- $stmt->execute([$id]);",
"- $linkedCritics = $stmt->fetchAll(\\PDO::FETCH_ASSOC);",
"-",
" $this->view('prompts.show', [",
" 'title' => $prompt['name'],",
" 'prompt' => $prompt,",
"- 'linkedCritics' => $linkedCritics,",
"+ 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),",
" 'promptTypes' => self::PROMPT_TYPES,",
" ]);",
" }",
" ",
"- \/**",
"- * GET \/prompts\/{id}\/edit",
"- *\/",
" public function edit(string $id): void",
" {",
"- $prompt = $this->findById((int) $id);",
"-",
"+ $prompt = $this->promptsRepo->findById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }"
]
},
{
"oldStart": 131,
"oldLines": 15,
"newStart": 94,
"newLines": 11,
"lines": [
" ]);",
" }",
" ",
"- \/**",
"- * POST \/prompts\/{id}",
"- *\/",
" public function update(string $id): void",
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->findById((int) $id);",
"-",
"+ $prompt = $this->promptsRepo->findById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }"
]
},
{
"oldStart": 155,
"oldLines": 102,
"newStart": 114,
"newLines": 50,
"lines": [
" exit;",
" }",
" ",
"- $stmt = $this->db->prepare('",
"- UPDATE prompts",
"- SET name = ?, version = ?, content = ?, is_active = ?",
"- WHERE id = ?",
"- ');",
"- $stmt->execute([$name, $version, $content, $isActive, $id]);",
"+ $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);",
" ",
" $_SESSION['success'] = 'Prompt aktualisiert.';",
" header('Location: \/prompts\/' . $id);",
" exit;",
" }",
" ",
"- \/**",
"- * POST \/prompts\/{id}\/delete",
"- *\/",
" public function delete(string $id): void",
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->findById((int) $id);",
"-",
"+ $prompt = $this->promptsRepo->findById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }",
" ",
"- \/\/ Prüfen ob Critics verknüpft sind",
"- $stmt = $this->db->prepare('SELECT COUNT(*) FROM critics WHERE prompt_id = ?');",
"- $stmt->execute([$id]);",
"- $criticCount = (int) $stmt->fetchColumn();",
"-",
"+ $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);",
" if ($criticCount > 0) {",
" $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";",
" header('Location: \/prompts\/' . $id);",
" exit;",
" }",
" ",
"- $stmt = $this->db->prepare('DELETE FROM prompts WHERE id = ?');",
"- $stmt->execute([$id]);",
"+ $this->promptsRepo->delete((int) $id);",
" ",
" $_SESSION['success'] = 'Prompt gelöscht.';",
" header('Location: \/prompts');",
" exit;",
" }",
" ",
"- \/**",
"- * POST \/prompts\/{id}\/duplicate",
"- *\/",
" public function duplicate(string $id): void",
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->findById((int) $id);",
"-",
"+ $prompt = $this->promptsRepo->findById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }",
" ",
" $newName = $prompt['name'] . ' (Kopie)';",
"- $newVersion = '1.0';",
"+ $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');",
" ",
"- $stmt = $this->db->prepare('",
"- INSERT INTO prompts (name, version, content, is_active)",
"- VALUES (?, ?, ?, 0)",
"- ');",
"- $stmt->execute([$newName, $newVersion, $prompt['content']]);",
"- $newId = $this->db->lastInsertId();",
"-",
" $_SESSION['success'] = 'Prompt dupliziert.';",
" header('Location: \/prompts\/' . $newId . '\/edit');",
" exit;",
" }",
"-",
"- \/\/ ========== Private Helpers ==========",
"-",
"- private function findById(int $id): ?array",
"- {",
"- $stmt = $this->db->prepare('SELECT * FROM prompts WHERE id = ?');",
"- $stmt->execute([$id]);",
"- $result = $stmt->fetch(\\PDO::FETCH_ASSOC);",
"-",
"- return $result !== false ? $result : null;",
"- }",
"-",
"- private function getStatistics(): array",
"- {",
"- $stats = ['total' => 0, 'active' => 0, 'inactive' => 0, 'linked_to_critics' => 0];",
"-",
"- $stmt = $this->db->query('SELECT COUNT(*) as cnt, SUM(is_active) as active FROM prompts');",
"- $row = $stmt->fetch(\\PDO::FETCH_ASSOC);",
"- $stats['total'] = (int) $row['cnt'];",
"- $stats['active'] = (int) $row['active'];",
"- $stats['inactive'] = $stats['total'] - $stats['active'];",
"-",
"- $stmt = $this->db->query('SELECT COUNT(DISTINCT prompt_id) FROM critics WHERE prompt_id IS NOT NULL');",
"- $stats['linked_to_critics'] = (int) $stmt->fetchColumn();",
"-",
"- return $stats;",
"- }",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}