'Critic-Prompt', 'generate' => 'Generierungs-Prompt', 'revise' => 'Revisions-Prompt', 'system' => 'System-Prompt', 'other' => 'Sonstiges', ]; public function __construct(?PromptsRepository $promptsRepo = null) { $this->promptsRepo = $promptsRepo ?? new PromptsRepository(); } public function index(): void { $this->view('prompts.index', [ 'title' => 'Prompts verwalten', 'prompts' => $this->promptsRepo->findAll(), 'stats' => $this->promptsRepo->getStatistics(), 'promptTypes' => self::PROMPT_TYPES, ]); } public function promptsNew(): void { $this->view('prompts.form', [ 'title' => 'Neuer Prompt', 'prompt' => null, 'promptTypes' => self::PROMPT_TYPES, 'isEdit' => false, ]); } public function store(): void { $this->requireCsrf(); $name = trim($_POST['name'] ?? ''); $version = trim($_POST['version'] ?? '1.0'); $content = $_POST['content'] ?? ''; $isActive = isset($_POST['is_active']) ? 1 : 0; if ($name === '' || $content === '') { $_SESSION['error'] = 'Name und Inhalt sind erforderlich.'; header('Location: /prompts/new'); exit; } $id = $this->promptsRepo->create($name, $version, $content, $isActive); $_SESSION['success'] = 'Prompt erfolgreich erstellt.'; header('Location: /prompts/' . $id); exit; } public function show(string $id): void { $prompt = $this->promptsRepo->findById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $this->view('prompts.show', [ 'title' => $prompt['name'], 'prompt' => $prompt, 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id), 'promptTypes' => self::PROMPT_TYPES, ]); } public function edit(string $id): void { $prompt = $this->promptsRepo->findById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $this->view('prompts.form', [ 'title' => 'Bearbeiten: ' . $prompt['name'], 'prompt' => $prompt, 'promptTypes' => self::PROMPT_TYPES, 'isEdit' => true, ]); } public function update(string $id): void { $this->requireCsrf(); $prompt = $this->promptsRepo->findById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $name = trim($_POST['name'] ?? ''); $version = trim($_POST['version'] ?? $prompt['version']); $content = $_POST['content'] ?? ''; $isActive = isset($_POST['is_active']) ? 1 : 0; if ($name === '' || $content === '') { $_SESSION['error'] = 'Name und Inhalt sind erforderlich.'; header('Location: /prompts/' . $id . '/edit'); exit; } $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive); $_SESSION['success'] = 'Prompt aktualisiert.'; header('Location: /prompts/' . $id); exit; } public function delete(string $id): void { $this->requireCsrf(); $prompt = $this->promptsRepo->findById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $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; } $this->promptsRepo->delete((int) $id); $_SESSION['success'] = 'Prompt gelöscht.'; header('Location: /prompts'); exit; } public function duplicate(string $id): void { $this->requireCsrf(); $prompt = $this->promptsRepo->findById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $newName = $prompt['name'] . ' (Kopie)'; $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0'); $_SESSION['success'] = 'Prompt dupliziert.'; header('Location: /prompts/' . $newId . '/edit'); exit; } }