コード例 #1
0
ファイル: PoolController.php プロジェクト: abienvenu/kyjoukan
 /**
  * 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");
 }
コード例 #2
0
ファイル: RankService.php プロジェクト: abienvenu/kyjoukan
 public function getPoolRanks(Pool $pool)
 {
     $rankings = [];
     /** @var Team $team */
     foreach ($pool->getTeams() as $team) {
         $rankings[$team->getId()] = ["team" => $team->getName(), "win" => 0, "played" => 0, "loose" => 0, "advantage" => 0, "points" => 0];
     }
     /** @var Game $game */
     foreach ($pool->getGames() as $game) {
         if ($game->getScore1() || $game->getScore2()) {
             if ($game->getScore1() >= $game->getScore2()) {
                 $rankings[$game->getTeam1()->getId()]["win"]++;
                 $rankings[$game->getTeam2()->getId()]["loose"]++;
             } else {
                 $rankings[$game->getTeam1()->getId()]["loose"]++;
                 $rankings[$game->getTeam2()->getId()]["win"]++;
             }
             $rankings[$game->getTeam1()->getId()]["played"]++;
             $rankings[$game->getTeam2()->getId()]["played"]++;
             $rankings[$game->getTeam1()->getId()]["advantage"] += $game->getScore1() - $game->getScore2();
             $rankings[$game->getTeam2()->getId()]["advantage"] += $game->getScore2() - $game->getScore1();
             $rankings[$game->getTeam1()->getId()]["points"] += $game->getScore1();
             $rankings[$game->getTeam2()->getId()]["points"] += $game->getScore2();
         }
     }
     usort($rankings, function (array $rank1, array $rank2) {
         foreach (["win", "advantage", "points", "played"] as $criteria) {
             if ($rank1[$criteria] > $rank2[$criteria]) {
                 return -1;
             }
             if ($rank1[$criteria] < $rank2[$criteria]) {
                 return 1;
             }
         }
         return -1;
     });
     return $rankings;
 }
コード例 #3
0
ファイル: LoadExample.php プロジェクト: abienvenu/kyjoukan
 public function load(ObjectManager $manager)
 {
     // Event
     $event = new Event();
     $event->setName("Exemple de tournoi");
     $manager->persist($event);
     // Teams
     $teams = ["Les incorruptibles", "Boit-sans-soif", "Les intouchables", "Oclomosimanapa", "Chauds les marrons, chaud!", "Nevguen", "Chanteloup Badminton", "C'est sur la ligne", "972", "Pathinacé", "ONSPJ", "La prévière", "Kikonféla", "ZEbet", "Gibon", "Sardines", "Les cressonnettes", "Loulou coptères"];
     foreach ($teams as $teamName) {
         $team = new Team();
         $team->setName($teamName);
         $event->addTeam($team);
     }
     // Grounds
     $grounds = ["A", "B", "C"];
     foreach ($grounds as $groundName) {
         $ground = new Ground();
         $ground->setName($groundName);
         $event->addGround($ground);
     }
     // Phase
     $phase = new Phase();
     $phase->setName("Poules phase 1");
     $phase->setRule(Rule::ROUNDROBIN);
     $phase->setStartDateTime(new \DateTime());
     $phase->setRoundDuration(12 * 60);
     $event->addPhase($phase);
     // Pools
     $colors = [1 => "green", "red", "blue", "darkorange"];
     for ($i = 1; $i <= 4; $i++) {
         $pool = new Pool();
         $pool->setName("Pool {$i}");
         $pool->setColor($colors[$i]);
         $phase->addPool($pool);
     }
     $manager->flush();
 }
コード例 #4
0
ファイル: Phase.php プロジェクト: abienvenu/kyjoukan
 /**
  * Add pool
  *
  * @param Pool $pool
  * @return Phase
  */
 public function addPool(Pool $pool)
 {
     $this->pools[] = $pool;
     $pool->setPhase($this);
     return $this;
 }
コード例 #5
0
 public function removePoolFromPhase(Pool $pool)
 {
     $isClear = true;
     /** @var Game $game */
     foreach ($pool->getGames() as $game) {
         if ($game->isPlayed()) {
             $isClear = false;
         } else {
             $pool->removeGame($game);
             $this->em->remove($game);
         }
     }
     if ($isClear) {
         $pool->getPhase()->removePool($pool);
         $this->em->remove($pool);
     }
     $this->em->flush();
     return $isClear;
 }