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([ 'id' => $project->getId(), 'code' => $project->getCode(), 'name' => $project->getName(), 'description' => $project->getDescription(), 'color' => $project->getColor(), 'client' => $project->getClient() ? [ 'id' => $project->getClient()->getId(), 'name' => $project->getClient()->getName(), ] : null, 'archived' => $project->isArchived(), 'taskSummary' => $statusCounts, 'totalTasks' => $totalTasks, ]); } }