/** * @inheritDoc */ protected function initializeRoundEntity(Round $round) { // TODO: Implement initializeRoundEntity() method. // foreach setup-group check for and/or create group-entity // just associate them properly, cascade operations should take care of persistence $tournament = $round->getTournament(); $getPlayer = function ($playerId) use($tournament) { foreach ($tournament->getPlayers() as $player) { if ($player->getId() == $playerId) { return $player; } } throw new \RuntimeException(sprintf('failed to fetch player by id %d from tournament', $playerId)); }; /** @var RoundSetupSeed $roundSetup */ $roundSetup = $this->setup; foreach ($roundSetup->getPlayerIdsGrouped() as $groupNumber => $groupPlayers) { $group = $round->getGroupByNumber($groupNumber); if (null === $group) { $group = $round->createGroup($groupNumber); // this could create the game-entities too... } $players = array(); foreach ($groupPlayers as $playerId) { $players[] = $getPlayer($playerId); } $group->setPlayers($players); } }
/** * this will be called upon first request to the round-entity(-getter) * sub classes should implement this function and should initialize the round-entity * with group-entities and game-entities * * the default implementation uses the configured input filter to initialize the groups and games * * @param Round $round as the round is private and should only be accessed via getter it is provided as parameter */ protected function initializeRoundEntity(Round $round) { $inputFilter = $this->setup->getInput(); $playersGrouped = $inputFilter->filter($this->previousRound); foreach ($playersGrouped as $groupNumber => $players) { $group = $round->getGroupByNumber($groupNumber); if (null === $group) { $group = $round->createGroup($groupNumber); // this could create the game-entities too... } $group->setPlayers($players); } }