Backup #434

ID434
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Infrastructure/Persistence/TaskCommentRepository.php
Version1
Typ modified
Größe2.8 KB
Hash0532245b78e48a59345ca7d95b7fd93380ae5cbf610a11b5add8dabf2e49ab15
Datum2025-12-22 10:11:58
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Infrastructure\Persistence;

use Domain\Entity\TaskComment;

class TaskCommentRepository
{
    private \PDO $pdo;

    public function __construct()
    {
        $this->pdo = new \PDO(
            'mysql:host=' . KI_DEV_DB_HOST . ';dbname=' . KI_DEV_DB_NAME . ';charset=utf8mb4',
            KI_DEV_DB_USER,
            KI_DEV_DB_PASS,
            [
                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
            ]
        );
    }

    public function find(int $id): ?TaskComment
    {
        $stmt = $this->pdo->prepare('SELECT * FROM task_comments WHERE id = :id');
        $stmt->execute(['id' => $id]);
        $row = $stmt->fetch();

        return $row !== false ? TaskComment::fromArray($row) : null;
    }

    public function findByTaskId(int $taskId, int $limit = 50): array
    {
        $stmt = $this->pdo->prepare(
            'SELECT * FROM task_comments WHERE task_id = :task_id ORDER BY created_at DESC LIMIT :limit'
        );
        $stmt->bindValue(':task_id', $taskId, \PDO::PARAM_INT);
        $stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
        $stmt->execute();

        $comments = [];
        while ($row = $stmt->fetch()) {
            $comments[] = TaskComment::fromArray($row);
        }

        return $comments;
    }

    public function findByType(int $taskId, string $commentType): array
    {
        $stmt = $this->pdo->prepare(
            'SELECT * FROM task_comments WHERE task_id = :task_id AND comment_type = :type ORDER BY created_at DESC'
        );
        $stmt->execute(['task_id' => $taskId, 'type' => $commentType]);

        $comments = [];
        while ($row = $stmt->fetch()) {
            $comments[] = TaskComment::fromArray($row);
        }

        return $comments;
    }

    public function save(TaskComment $comment): int
    {
        $sql = 'INSERT INTO task_comments (
            task_id, author, author_type, comment_type,
            content, metadata, created_at
        ) VALUES (
            :task_id, :author, :author_type, :comment_type,
            :content, :metadata, :created_at
        )';

        $stmt = $this->pdo->prepare($sql);
        $data = $comment->toArray();

        $stmt->execute([
            'task_id' => $data['task_id'],
            'author' => $data['author'],
            'author_type' => $data['author_type'],
            'comment_type' => $data['comment_type'],
            'content' => $data['content'],
            'metadata' => json_encode($data['metadata']),
            'created_at' => $data['created_at'],
        ]);

        return (int) $this->pdo->lastInsertId();
    }

    public function delete(int $id): bool
    {
        $stmt = $this->pdo->prepare('DELETE FROM task_comments WHERE id = :id');

        return $stmt->execute(['id' => $id]);
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
1265 5 modified 2.6 KB 2025-12-25 12:51
1190 4 modified 2.6 KB 2025-12-25 10:32
1173 3 modified 2.7 KB 2025-12-25 10:32
774 2 modified 2.6 KB 2025-12-23 08:04
434 1 modified 2.8 KB 2025-12-22 10:11

← Zurück zur Übersicht