Backup #466

ID466
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/ConfigController.php
Version11
Typ modified
Größe4.8 KB
Hash7df2efebf50e630326050305c6114a665eec91b7fb0b754d035fee56d52a6734
Datum2025-12-22 10:31:13
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Controller;

use Framework\Controller;
use UseCases\Config\ManageConfigUseCase;

class ConfigController extends Controller
{
    private ManageConfigUseCase $configUseCase;

    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(?ManageConfigUseCase $configUseCase = null)
    {
        $this->configUseCase = $configUseCase ?? new ManageConfigUseCase();
    }

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

        $this->view('config.index', [
            'title' => 'Content-Konfiguration',
            'configs' => array_map(fn ($dto) => $dto->toArray(), $this->configUseCase->getAll($typeFilter, $statusFilter)),
            'stats' => $this->configUseCase->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->configUseCase->getParentOptions(),
            'isEdit' => false,
        ]);
    }

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

        $result = $this->configUseCase->create(
            type: $_POST['type'] ?? '',
            name: $_POST['name'] ?? '',
            slug: $_POST['slug'] ?? '',
            description: $_POST['description'] ?? null,
            content: $_POST['content'] ?? '{}',
            version: $_POST['version'] ?? '1.0',
            status: $_POST['status'] ?? 'draft',
            parentId: !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null
        );

        if (!$result->success) {
            $_SESSION['error'] = $result->message;
            header('Location: /config/new');
            exit;
        }

        $_SESSION['success'] = $result->message;
        header('Location: /config/' . $result->id);
        exit;
    }

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

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

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

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

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

        $result = $this->configUseCase->update(
            id: (int) $id,
            name: $_POST['name'] ?? '',
            slug: $_POST['slug'] ?? '',
            description: $_POST['description'] ?? null,
            content: $_POST['content'] ?? '{}',
            newVersion: $_POST['new_version'] ?? '',
            changeDescription: $_POST['change_description'] ?? '',
            status: $_POST['status'] ?? 'draft',
            parentId: !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : null
        );

        if (!$result->success) {
            $_SESSION['error'] = $result->message;
            header('Location: /config/' . $id . '/edit');
            exit;
        }

        $_SESSION['success'] = $result->message;
        header('Location: /config/' . $id);
        exit;
    }

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

        $result = $this->configUseCase->delete((int) $id);

        if (!$result->success) {
            $_SESSION['error'] = $result->message;
            header('Location: /config/' . $id);
            exit;
        }

        $_SESSION['success'] = $result->message;
        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