repo = $repo; } public function index(): void { $category = $this->getString('category'); $showAll = $this->getString('all') === '1'; $this->view('semantic-explorer.stopwords.index', [ 'title' => 'Stopwords - Semantic Explorer', 'stopwords' => $this->repo->findAll(!$showAll, $category ?: null), 'stats' => $this->repo->getStats(), 'currentCategory' => $category, 'showAll' => $showAll, ]); } public function create(): void { $this->view('semantic-explorer.stopwords.new', [ 'title' => 'Neues Stopword - Semantic Explorer', ]); } public function store(): void { $this->requireCsrf(); $word = trim($this->getString('word')); if ($word === '') { $_SESSION['error'] = 'Wort darf nicht leer sein.'; $this->redirect('/semantic-explorer/stopwords/new'); return; } try { $id = $this->repo->create([ 'word' => $word, 'category' => $this->getString('category') ?: 'generic', 'reason' => $this->getString('reason') ?: null, 'is_active' => isset($_POST['is_active']) ? 1 : 0, ]); $_SESSION['success'] = "Stopword '{$word}' wurde erstellt."; $this->redirect('/semantic-explorer/stopwords/' . $id); } catch (\PDOException $e) { if (str_contains($e->getMessage(), 'Duplicate')) { $_SESSION['error'] = "Stopword '{$word}' existiert bereits."; } else { $_SESSION['error'] = 'Fehler beim Speichern: ' . $e->getMessage(); } $this->redirect('/semantic-explorer/stopwords/new'); } } public function show(string $id): void { $stopword = $this->repo->find((int) $id); if ($stopword === null) { $this->notFound('Stopword nicht gefunden'); return; } $this->view('semantic-explorer.stopwords.edit', [ 'title' => 'Stopword: ' . $stopword['word'], 'stopword' => $stopword, ]); } public function update(string $id): void { $this->requireCsrf(); $stopword = $this->repo->find((int) $id); if ($stopword === null) { $this->notFound('Stopword nicht gefunden'); return; } $word = trim($this->getString('word')); if ($word === '') { $_SESSION['error'] = 'Wort darf nicht leer sein.'; $this->redirect('/semantic-explorer/stopwords/' . $id); return; } try { $this->repo->update((int) $id, [ 'word' => $word, 'category' => $this->getString('category') ?: 'generic', 'reason' => $this->getString('reason') ?: null, 'is_active' => isset($_POST['is_active']) ? 1 : 0, ]); $_SESSION['success'] = 'Stopword wurde aktualisiert.'; $this->redirect('/semantic-explorer/stopwords/' . $id); } catch (\PDOException $e) { if (str_contains($e->getMessage(), 'Duplicate')) { $_SESSION['error'] = "Stopword '{$word}' existiert bereits."; } else { $_SESSION['error'] = 'Fehler beim Speichern: ' . $e->getMessage(); } $this->redirect('/semantic-explorer/stopwords/' . $id); } } public function delete(string $id): void { $this->requireCsrf(); $stopword = $this->repo->find((int) $id); if ($stopword === null) { $this->notFound('Stopword nicht gefunden'); return; } $this->repo->delete((int) $id); $_SESSION['success'] = "Stopword '{$stopword['word']}' wurde geloescht."; $this->redirect('/semantic-explorer/stopwords'); } public function toggle(string $id): void { $this->requireCsrf(); $stopword = $this->repo->find((int) $id); if ($stopword === null) { $this->notFound('Stopword nicht gefunden'); return; } $this->repo->toggleActive((int) $id); $newState = $stopword['is_active'] ? 'deaktiviert' : 'aktiviert'; $_SESSION['success'] = "Stopword '{$stopword['word']}' wurde {$newState}."; $this->redirect('/semantic-explorer/stopwords'); } }