conn = $connection->getConnection(); } public function create(Task $task): int { $data = $task->persist(); $stmt = $this->conn->prepare( "INSERT INTO Tasks (task_owner, created_at, updated_at, name, description, start, end, status_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); $stmt->bindParam(1, $data['task_owner']); $stmt->bindParam(2, $data['created_at']); $stmt->bindParam(3, $data['updated_at']); $stmt->bindParam(4, $data['name']); $stmt->bindParam(5, $data['description']); $stmt->bindParam(6, $data['start']); $stmt->bindParam(7, $data['end']); $stmt->bindParam(8, $data['status_id']); if ($stmt->execute()) { return (int) $this->conn->lastInsertId(); } return 0; } public function readAll(): array { $stmt = $this->conn->query('SELECT * FROM Tasks'); return $stmt->fetchAll(PDO::FETCH_ASSOC); } /** * @throws TaskNotFoundException */ public function readById($id): Task { $stmt = $this->conn->prepare('SELECT * FROM Tasks WHERE id = ?'); $stmt->execute([$id]); if (!$data = $stmt->fetch(PDO::FETCH_ASSOC)) { throw new TaskNotFoundException('Task not found.'); } return Task::fromArray($data); } public function update(Task $task): bool { $stmt = $this->conn->prepare( "UPDATE Tasks SET task_owner = ?, updated_at = ?, name = ?, description = ?, start = ?, end = ?, status_id = 0 WHERE id = ?" ); return $stmt->execute([ 1, // Mock user ID for now, we haven't implemented authentication yet Carbon::now(), $task->getName(), $task->getDescription(), $task->getStart(), $task->getEnd(), $task->getStatusId(), $task->getTaskId() ]); } public function delete(Task $task): bool { $stmt = $this->conn->prepare('DELETE FROM Tasks WHERE id = ?'); return $stmt->execute([$task->getTaskId()]); } }