Backup #1609

ID1609
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/StopwordController.php
Version4
Typ modified
Größe4.7 KB
Hashaa16358e3764483b2f287ebac927787bfb3a30be40c02d443587a20630eb485c
Datum2025-12-27 00:28:27
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

declare(strict_types=1);

namespace Controller;

// @responsibility: HTTP-Endpunkte für Stopword-Verwaltung (Entity-Extraction Filter)

use Domain\Repository\StopwordRepositoryInterface;
use Framework\Controller;

class StopwordController extends Controller
{
    private StopwordRepositoryInterface $repo;

    public function __construct(StopwordRepositoryInterface $repo)
    {
        $this->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');
        }

        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');
        }

        $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');
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
1739 14 modified 5.8 KB 2025-12-27 12:41
1738 13 modified 5.7 KB 2025-12-27 12:41
1737 12 modified 5.7 KB 2025-12-27 12:40
1736 11 modified 5.7 KB 2025-12-27 12:39
1733 10 modified 5.5 KB 2025-12-27 12:37
1732 9 modified 5.1 KB 2025-12-27 12:37
1731 8 modified 4.7 KB 2025-12-27 12:37
1612 7 modified 4.7 KB 2025-12-27 00:28
1611 6 modified 4.7 KB 2025-12-27 00:28
1610 5 modified 4.7 KB 2025-12-27 00:28
1609 4 modified 4.7 KB 2025-12-27 00:28
1608 3 modified 4.8 KB 2025-12-27 00:28
1607 2 modified 4.8 KB 2025-12-27 00:28
1603 1 modified 4.5 KB 2025-12-27 00:25

← Zurück zur Übersicht