_em->createQuery( "SELECT COUNT(g.id) FROM ". Game::class ." g WHERE g.score < :score AND g.level = :level" ) ->setParameters([ 'score' => $game->getScore(), 'level' => $game->getLevel(), ]); $position = $query->getSingleScalarResult(); $total = $this->getGameCountForLevel($game->getLevel()); $highscore = $this->getHighscoreForLevel($game->getLevel()); return new Position($position, $total, $game->getScore(), $highscore); } public function getGameCountForLevel(Level $level) { $query = $this->_em->createQuery( "SELECT COUNT(g.id) FROM ".Game::class." g WHERE g.level = :level" ) ->setParameters([ 'level' => $game->getLevel(), ]); return $query->getSingleScalarResult(); } /** * @return float */ public function getHighscoreForLevel(Level $level) { $query = $this->_em->createQuery( "SELECT MAX(g.score) FROM ".Game::class." g WHERE g.level = :level" ) ->setParameters([ 'level' => $game->getLevel(), ]); return $query->getSingleScalarResult(); } }