Backup #2138

ID2138
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/ConfigController.php
Version21
Typ modified
Größe6.1 KB
Hash6bdeb8e6dc541140017fde5190f8d6520cf303da87b87e498b9989ad100b2f78
Datum2025-12-30 20:32:17
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 Content-Konfiguration (Profile, Strukturen, Contracts, Critics)

use Domain\Repository\PromptsRepositoryInterface;
use Framework\Controller;
use UseCases\Config\ManageConfigUseCase;

class ConfigController extends Controller
{
    private ManageConfigUseCase $configUseCase;
    private PromptsRepositoryInterface $promptsRepo;

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

    public function __construct(ManageConfigUseCase $configUseCase, PromptsRepositoryInterface $promptsRepo)
    {
        $this->configUseCase = $configUseCase;
        $this->promptsRepo = $promptsRepo;
    }

    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();

        $isHtmx = $this->isHtmxRequest();
        $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,
            promptId: !empty($_POST['prompt_id']) ? (int) $_POST['prompt_id'] : null,
            sortOrder: (int) ($_POST['sort_order'] ?? 0)
        );

        if (!$result->success) {
            if ($isHtmx) {
                $this->htmxError($result->message);

                return;
            }
            $_SESSION['error'] = $result->message;
            $this->redirect('/config/new');
        }

        if ($isHtmx) {
            $this->htmxRedirect('/config/' . $result->id);

            return;
        }

        $_SESSION['success'] = $result->message;
        $this->redirect('/config/' . $result->id);
    }

    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' => $config->toArray(),
            'types' => self::TYPES,
            'typeLabels' => self::TYPE_LABELS,
            'parents' => $this->configUseCase->getParentOptions((int) $id),
            'isEdit' => true,
        ]);
    }

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

        $isHtmx = $this->isHtmxRequest();
        $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,
            promptId: !empty($_POST['prompt_id']) ? (int) $_POST['prompt_id'] : null,
            sortOrder: (int) ($_POST['sort_order'] ?? 0)
        );

        if (!$result->success) {
            if ($isHtmx) {
                $this->htmxError($result->message);

                return;
            }
            $_SESSION['error'] = $result->message;
            $this->redirect('/config/' . $id . '/edit');
        }

        if ($isHtmx) {
            $this->htmxRedirect('/config/' . $id);

            return;
        }

        $_SESSION['success'] = $result->message;
        $this->redirect('/config/' . $id);
    }

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

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

        if (!$result->success) {
            if ($isHtmx) {
                $this->htmxError($result->message);

                return;
            }
            $_SESSION['error'] = $result->message;
            $this->redirect('/config/' . $id);
        }

        if ($isHtmx) {
            $this->htmxRedirect('/config');

            return;
        }

        $_SESSION['success'] = $result->message;
        $this->redirect('/config');
    }
}

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