security->isGranted('ROLE_USER')) { throw new AccessDeniedException('Access denied: ROLE_USER required.'); } $project = $this->projectRepository->find($id); if (null === $project) { throw new InvalidArgumentException(sprintf('Project with ID %d not found.', $id)); } // Count tasks per status $qb = $this->taskRepository->createQueryBuilder('t') ->select('s.label AS statusLabel, COUNT(t.id) AS taskCount') ->leftJoin('t.status', 's') ->where('t.project = :project') ->setParameter('project', $project) ->groupBy('s.id, s.label') ; $statusCounts = []; $totalTasks = 0; foreach ($qb->getQuery()->getResult() as $row) { $label = $row['statusLabel'] ?? 'No status'; $count = (int) $row['taskCount']; $statusCounts[$label] = $count; $totalTasks += $count; } return json_encode(Serializer::project($project) + [ 'taskSummary' => $statusCounts, 'totalTasks' => $totalTasks, ]); } }