/** * Remove all unplayed games and empty rounds * * @param Phase $phase */ public function cleanGames(Phase $phase) { // Delete all games that have not been played foreach ($phase->getPools() as $pool) { /** @var Game $game */ foreach ($pool->getGames() as $game) { if (!$game->isPlayed()) { $pool->removeGame($game); $game->getRound()->removeGame($game); $this->em->remove($game); } } } // Delete empty rounds foreach ($phase->getRounds() as $round) { if (!count($round->getGames())) { $phase->removeRound($round); $this->em->remove($round); } } $this->em->flush(); }