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]); } }