Backup #452

ID452
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/ConfigController.php
Version8
Typ modified
Größe6.7 KB
Hash98dae38e4074e0b173226eceddde9623440cf854879bd2899732481a8e0edb98
Datum2025-12-22 10:26:58
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Write-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Controller;

use Framework\Controller;
use Infrastructure\Persistence\ContentConfigRepository;

class ConfigController extends Controller
{
    private ContentConfigRepository $configRepo;

    private const TYPES = ['author_profile', 'structure', 'organization', 'contract', 'rule', 'system_prompt'];
    private const TYPE_LABELS = [
        'author_profile' => 'Autorenprofil',
        'structure' => 'Struktur',
        'organization' => 'Organisation',
        'contract' => 'Contract',
        'rule' => 'Regel',
        'system_prompt' => 'System-Prompt',
    ];

    public function __construct(?ContentConfigRepository $configRepo = null)
    {
        $this->configRepo = $configRepo ?? new ContentConfigRepository();
    }

    public function index(): void
    {
        $typeFilter = $this->getString('type');
        $statusFilter = $this->getString('status');

        $validType = in_array($typeFilter, self::TYPES, true) ? $typeFilter : null;
        $validStatus = in_array($statusFilter, ['draft', 'active', 'deprecated'], true) ? $statusFilter : null;

        $this->view('config.index', [
            'title' => 'Content-Konfiguration',
            'configs' => $this->configRepo->findAll($validType, $validStatus),
            'stats' => $this->configRepo->getStatistics(),
            'types' => self::TYPES,
            'typeLabels' => self::TYPE_LABELS,
            'currentType' => $typeFilter,
            'currentStatus' => $statusFilter,
        ]);
    }

    public function configNew(): void
    {
        $this->view('config.form', [
            'title' => 'Neue Konfiguration',
            'config' => null,
            'types' => self::TYPES,
            'typeLabels' => self::TYPE_LABELS,
            'parents' => $this->configRepo->getParentOptions(),
            'isEdit' => false,
        ]);
    }

    public function store(): void
    {
        $this->requireCsrf();

        $type = $_POST['type'] ?? '';
        $name = trim($_POST['name'] ?? '');
        $slug = trim($_POST['slug'] ?? '');
        $description = trim($_POST['description'] ?? '');
        $content = $_POST['content'] ?? '{}';
        $version = trim($_POST['version'] ?? '1.0');
        $status = $_POST['status'] ?? 'draft';
        $parentId = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null;

        if (!in_array($type, self::TYPES, true) || $name === '' || $slug === '') {
            $_SESSION['error'] = 'Typ, Name und Slug sind erforderlich.';
            header('Location: /config/new');
            exit;
        }

        $decoded = json_decode($content, true);
        if ($decoded === null && $content !== 'null') {
            $_SESSION['error'] = 'Ungültiges JSON-Format.';
            header('Location: /config/new');
            exit;
        }

        $id = $this->configRepo->create(
            $type,
            $name,
            $slug,
            $description !== '' ? $description : null,
            $content,
            $version,
            $status,
            $parentId
        );

        $_SESSION['success'] = 'Konfiguration erfolgreich erstellt.';
        header('Location: /config/' . $id);
        exit;
    }

    public function show(string $id): void
    {
        $config = $this->configRepo->findById((int) $id);
        if ($config === null) {
            $this->notFound('Konfiguration nicht gefunden');
        }

        $this->view('config.show', [
            'title' => $config['name'],
            'config' => $config,
            'children' => $this->configRepo->getChildren((int) $id),
            'history' => $this->configRepo->getHistory((int) $id),
            'typeLabels' => self::TYPE_LABELS,
        ]);
    }

    public function edit(string $id): void
    {
        $config = $this->configRepo->findById((int) $id);
        if ($config === null) {
            $this->notFound('Konfiguration nicht gefunden');
        }

        $this->view('config.form', [
            'title' => 'Bearbeiten: ' . $config['name'],
            'config' => $config,
            'types' => self::TYPES,
            'typeLabels' => self::TYPE_LABELS,
            'parents' => $this->configRepo->getParentOptions((int) $id),
            'isEdit' => true,
        ]);
    }

    public function update(string $id): void
    {
        $this->requireCsrf();

        $config = $this->configRepo->findById((int) $id);
        if ($config === null) {
            $this->notFound('Konfiguration nicht gefunden');
        }

        $name = trim($_POST['name'] ?? '');
        $slug = trim($_POST['slug'] ?? '');
        $description = trim($_POST['description'] ?? '');
        $content = $_POST['content'] ?? '{}';
        $newVersion = trim($_POST['new_version'] ?? '');
        $changeDescription = trim($_POST['change_description'] ?? '');
        $status = $_POST['status'] ?? $config['status'];
        $parentId = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null;

        if ($name === '' || $slug === '' || $newVersion === '') {
            $_SESSION['error'] = 'Name, Slug und neue Version sind erforderlich.';
            header('Location: /config/' . $id . '/edit');
            exit;
        }

        $decoded = json_decode($content, true);
        if ($decoded === null && $content !== 'null') {
            $_SESSION['error'] = 'Ungültiges JSON-Format.';
            header('Location: /config/' . $id . '/edit');
            exit;
        }

        $this->configRepo->saveHistory(
            (int) $id,
            $config['content'],
            $config['version'],
            'web-ui',
            $changeDescription !== '' ? $changeDescription : 'Update auf Version ' . $newVersion
        );

        $this->configRepo->update(
            (int) $id,
            $name,
            $slug,
            $description !== '' ? $description : null,
            $content,
            $newVersion,
            $status,
            $parentId
        );

        $_SESSION['success'] = 'Konfiguration auf Version ' . $newVersion . ' aktualisiert.';
        header('Location: /config/' . $id);
        exit;
    }

    public function delete(string $id): void
    {
        $this->requireCsrf();

        $config = $this->configRepo->findById((int) $id);
        if ($config === null) {
            $this->notFound('Konfiguration nicht gefunden');
        }

        if ($this->configRepo->countChildren((int) $id) > 0) {
            $_SESSION['error'] = 'Kann nicht gelöscht werden: Es existieren verknüpfte Einträge.';
            header('Location: /config/' . $id);
            exit;
        }

        $this->configRepo->deleteHistory((int) $id);
        $this->configRepo->delete((int) $id);

        $_SESSION['success'] = 'Konfiguration gelöscht.';
        header('Location: /config');
        exit;
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
2139 22 modified 6.1 KB 2025-12-30 20:32
2138 21 modified 6.1 KB 2025-12-30 20:32
2137 20 modified 5.9 KB 2025-12-30 20:32
2136 19 modified 5.7 KB 2025-12-30 20:31
2135 18 modified 5.6 KB 2025-12-30 20:31
2129 17 modified 5.6 KB 2025-12-30 20:28
1763 16 modified 5.3 KB 2025-12-27 12:53
1762 15 modified 5.1 KB 2025-12-27 12:53
1761 14 modified 4.9 KB 2025-12-27 12:52
864 13 modified 4.9 KB 2025-12-23 08:50
687 12 modified 4.8 KB 2025-12-23 07:52
466 11 modified 4.8 KB 2025-12-22 10:31
465 10 modified 4.8 KB 2025-12-22 10:31
464 9 modified 4.8 KB 2025-12-22 10:31
452 8 modified 6.7 KB 2025-12-22 10:26
446 7 modified 10.3 KB 2025-12-22 10:18
307 6 modified 10.3 KB 2025-12-22 08:05
232 5 modified 10.4 KB 2025-12-22 01:45
231 4 modified 10.4 KB 2025-12-22 01:45
230 3 modified 10.4 KB 2025-12-22 01:45
229 2 modified 10.5 KB 2025-12-22 01:45
149 1 modified 10.4 KB 2025-12-21 02:30

← Zurück zur Übersicht