/** * Add a Pool to the Phase * * @Route("/{id}/new") * @param Phase $phase * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function newAction(Phase $phase) { $pool = new Pool(); $pool->setName("Groupe " . (count($phase->getPools()) + 1)); $phase->addPool($pool); $em = $this->getDoctrine()->getManager(); $em->flush(); return $this->redirect($this->generateUrl('abienvenu_kyjoukan_phase_index', ['slug_event' => $phase->getEvent()->getSlug(), 'slug' => $phase->getSlug()]) . "#pools"); }
public function checkPhaseGames(Phase $phase) { $errors = []; // Check a team does not play on several ground at the same time foreach ($phase->getRounds() as $round) { $busyTeams = []; foreach ($round->getGames() as $game) { if (in_array($game->getTeam1(), $busyTeams)) { $errors[] = "L'équipe {$game->getTeam1()->getName()} est à deux endroits dans le round {$round->getNumber()}"; } $busyTeams[] = $game->getTeam1(); if (in_array($game->getTeam2(), $busyTeams)) { $errors[] = "L'équipe {$game->getTeam2()->getName()} est à deux endroits dans le round {$round->getNumber()}"; } $busyTeams[] = $game->getTeam2(); if (in_array($game->getReferee(), $busyTeams)) { $errors[] = "L'arbitre {$game->getReferee()->getName()} joue déjà dans le round {$round->getNumber()}"; } $busyTeams[] = $game->getReferee(); // Check all teams belong to the same pool if (!$game->getPool()->hasTeam($game->getTeam1())) { $errors[] = "L'équipe {$game->getTeam1()->getName()} est programmée sur match du groupe {$game->getPool()->getName()} dans le round {$round->getNumber()}"; } if (!$game->getPool()->hasTeam($game->getTeam2())) { $errors[] = "L'équipe {$game->getTeam2()->getName()} est programmée sur match du groupe {$game->getPool()->getName()} dans le round {$round->getNumber()}"; } if (!$game->getPool()->hasTeam($game->getReferee())) { $errors[] = "L'équipe {$game->getReferee()->getName()} arbitre un match du groupe {$game->getPool()->getName()} dans le round {$round->getNumber()}"; } } } // Check all pools are fully scheduled foreach ($phase->getPools() as $pool) { $scheduledRate = $pool->getScheduledRate(); if ($scheduledRate < 1) { $errors[] = "Il manque des matchs dans le groupe {$pool->getName()}"; } if ($scheduledRate > 1) { $errors[] = "Il y a des matchs en trop dans le groupe {$pool->getName()}"; } } return $errors; }
/** * @Route("/ranking") * @param Phase $phase * @return \Symfony\Component\HttpFoundation\Response */ public function rankingAction(Phase $phase) { $rankings = []; foreach ($phase->getPools() as $pool) { $index = 0; $key = $pool->getName(); while (array_key_exists($key, $rankings)) { $index++; $key = "{$pool->getName()}_{$index}"; } $rankings[$key] = $this->get('kyjoukan.ranker')->getPoolRanks($pool); } return $this->render("KyjoukanBundle:Phase:ranking.html.twig", ['rankings' => $rankings]); }
public function removeTeamFromPhase(Phase $phase, Team $team) { $isClear = true; foreach ($phase->getPools() as $pool) { $isClear &= $this->removeTeamFromPool($pool, $team); } if ($isClear) { $phase->removeTeam($team); } $this->em->flush(); return $isClear; }