public function getPointsByAttempt(Attempt $attempt) { $points = $this->getEntityManager()->createQuery("SELECT SUM(answer.points) FROM AppBundle:UserAnswer u\n INNER JOIN u.answer answer\n WHERE u.attempt=" . $attempt->getId())->getSingleScalarResult(); if ($points != null) { return $points; } else { return 0; } }