Backup #2166

ID2166
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Infrastructure/Persistence/ContentVersionRepository.php
Version1
Typ modified
Größe2.2 KB
Hashf490e5b3034bd43d4013aed7ed03d4eb88165871690c38d9d746d86d09477fef
Datum2025-12-30 22:27:12
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

declare(strict_types=1);

namespace Infrastructure\Persistence;

// @responsibility: Persistenz für Content-Versions

use Domain\Repository\ContentVersionRepositoryInterface;
use Infrastructure\Traits\JsonDecodeTrait;

class ContentVersionRepository implements ContentVersionRepositoryInterface
{
    use JsonDecodeTrait;

    private \PDO $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    public function findVersionsByOrder(int $orderId): array
    {
        $stmt = $this->pdo->prepare('
            SELECT * FROM content_versions
            WHERE order_id = :order_id
            ORDER BY version_number DESC
        ');
        $stmt->execute(['order_id' => $orderId]);

        return $stmt->fetchAll();
    }

    public function findLatestVersion(int $orderId): ?array
    {
        $stmt = $this->pdo->prepare('
            SELECT * FROM content_versions
            WHERE order_id = :order_id
            ORDER BY version_number DESC
            LIMIT 1
        ');
        $stmt->execute(['order_id' => $orderId]);
        $result = $stmt->fetch();

        return $result !== false ? $result : null;
    }

    public function findVersion(int $id): ?array
    {
        $stmt = $this->pdo->prepare('SELECT * FROM content_versions WHERE id = :id');
        $stmt->execute(['id' => $id]);
        $result = $stmt->fetch();

        return $result !== false ? $result : null;
    }

    public function findCritiquesByVersion(int $versionId): array
    {
        $stmt = $this->pdo->prepare('
            SELECT cc.*, c.name as critic_name
            FROM content_critiques cc
            JOIN critics c ON cc.critic_id = c.id
            WHERE cc.version_id = :version_id
            ORDER BY cc.round DESC, c.sort_order ASC
        ');
        $stmt->execute(['version_id' => $versionId]);

        $results = $stmt->fetchAll();

        // Parse feedback JSON and merge with row
        foreach ($results as &$row) {
            if (isset($row['feedback']) && $row['feedback'] !== '') {
                $feedback = $this->decodeJsonArray($row['feedback']);
                if ($feedback !== []) {
                    $row = array_merge($row, $feedback);
                }
            }
        }

        return $results;
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

← Zurück zur Übersicht