Backup #104

ID104
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/ContractController.php
Version1
Typ modified
Größe5.6 KB
Hash44e90115f0a3c79d6add54ff1095a5ede35dee641b9605c6b72157e23778b645
Datum2025-12-20 19:19:20
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Controller;

use Framework\Controller;
use Infrastructure\Persistence\ContractRepository;

class ContractController extends Controller
{
    private ContractRepository $repository;

    public function __construct()
    {
        $this->repository = new ContractRepository();
    }

    /**
     * GET /contracts
     */
    public function index(): void
    {
        $filters = [];
        if (isset($_GET['status']) && $_GET['status'] !== '') {
            $filters['status'] = $_GET['status'];
        }

        $contracts = $this->repository->findAll($filters);
        $stats = $this->repository->getStatistics();

        $this->view('contracts.index', [
            'title' => 'Contracts',
            'contracts' => $contracts,
            'stats' => $stats,
            'currentStatus' => $_GET['status'] ?? '',
        ]);
    }

    /**
     * GET /contracts/new
     */
    public function contractNew(): void
    {
        $this->view('contracts.new', [
            'title' => 'Neuer Contract',
        ]);
    }

    /**
     * POST /contracts
     */
    public function store(): void
    {
        $name = trim($_POST['name'] ?? '');
        $version = trim($_POST['version'] ?? '1.0');
        $yamlContent = $_POST['yaml_content'] ?? '';
        $scopeDescription = trim($_POST['scope_description'] ?? '');
        $status = $_POST['status'] ?? 'active';

        if ($name === '' || $yamlContent === '') {
            $_SESSION['error'] = 'Name und YAML-Inhalt sind erforderlich.';
            header('Location: /contracts/new');
            exit;
        }

        // YAML-Syntax validieren
        try {
            yaml_parse($yamlContent);
        } catch (\Exception $e) {
            $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();
            header('Location: /contracts/new');
            exit;
        }

        $contractId = $this->repository->create([
            'name' => $name,
            'version' => $version,
            'yaml_content' => $yamlContent,
            'scope_description' => $scopeDescription,
            'status' => $status,
        ]);

        $_SESSION['success'] = 'Contract erfolgreich erstellt.';
        header('Location: /contracts/' . $contractId);
        exit;
    }

    /**
     * GET /contracts/{id}
     */
    public function show(string $id): void
    {
        $contract = $this->repository->findById((int) $id);

        if ($contract === null) {
            http_response_code(404);
            echo 'Contract nicht gefunden';

            return;
        }

        $history = $this->repository->getHistory((int) $id);
        $validations = $this->repository->getValidations((int) $id, 10);

        $this->view('contracts.show', [
            'title' => $contract['name'],
            'contract' => $contract,
            'history' => $history,
            'validations' => $validations,
        ]);
    }

    /**
     * GET /contracts/{id}/edit
     */
    public function edit(string $id): void
    {
        $contract = $this->repository->findById((int) $id);

        if ($contract === null) {
            http_response_code(404);
            echo 'Contract nicht gefunden';

            return;
        }

        $this->view('contracts.edit', [
            'title' => 'Contract bearbeiten: ' . $contract['name'],
            'contract' => $contract,
        ]);
    }

    /**
     * POST /contracts/{id}
     */
    public function update(string $id): void
    {
        $contract = $this->repository->findById((int) $id);

        if ($contract === null) {
            http_response_code(404);
            echo 'Contract nicht gefunden';

            return;
        }

        $yamlContent = $_POST['yaml_content'] ?? '';
        $newVersion = trim($_POST['new_version'] ?? '');
        $changeDescription = trim($_POST['change_description'] ?? '');

        if ($yamlContent === '' || $newVersion === '') {
            $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.';
            header('Location: /contracts/' . $id . '/edit');
            exit;
        }

        // YAML-Syntax validieren
        try {
            yaml_parse($yamlContent);
        } catch (\Exception $e) {
            $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();
            header('Location: /contracts/' . $id . '/edit');
            exit;
        }

        $this->repository->createNewVersion(
            (int) $id,
            $yamlContent,
            $newVersion,
            $changeDescription
        );

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

    /**
     * POST /contracts/{id}/validate
     */
    public function validate(string $id): void
    {
        $contract = $this->repository->findById((int) $id);

        if ($contract === null) {
            http_response_code(404);
            echo 'Contract nicht gefunden';

            return;
        }

        $result = $this->repository->runValidation((int) $id);

        $_SESSION['validation_result'] = $result;
        header('Location: /contracts/' . $id);
        exit;
    }

    /**
     * POST /contracts/{id}/deprecate
     */
    public function deprecate(string $id): void
    {
        $contract = $this->repository->findById((int) $id);

        if ($contract === null) {
            http_response_code(404);
            echo 'Contract nicht gefunden';

            return;
        }

        $this->repository->deprecate((int) $id);

        $_SESSION['success'] = 'Contract als deprecated markiert.';
        header('Location: /contracts/' . $id);
        exit;
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
107 4 modified 5.7 KB 2025-12-20 19:19
106 3 modified 5.6 KB 2025-12-20 19:19
105 2 modified 5.6 KB 2025-12-20 19:19
104 1 modified 5.6 KB 2025-12-20 19:19

← Zurück zur Übersicht