Пример #1
0
 public function testWonGamePairs()
 {
     $gameService = new GameService();
     $gameService->setManager($this->em);
     $wonMatch = $gameService->wonGameByPairs(1, 2, []);
     $this->assertEquals($wonMatch, null);
 }
Пример #2
0
 public function setDatesToMatchsInTournament($gamesInTournament, $inscriptionsTournament, $idTournament)
 {
     $gameService = new GameService();
     $gameService->setManager($this->em);
     $scheduleEntity = $this->getScheduleByTournamentId($idTournament);
     if ($scheduleEntity instanceof Schedule) {
         $schedule = $this->scheduleCompose($scheduleEntity->getId(), null);
         foreach ($gamesInTournament as $game) {
             $schedule = $this->insertInSchedule($game, $schedule, $scheduleEntity);
         }
         $schedule = $this->scheduleCompose($scheduleEntity->getId(), $gamesInTournament);
         $scheduleResources = $this->scheduleResourcesCompose($scheduleEntity->getId());
         $scheduleEntity->setScheduleJson(json_encode($schedule));
         $scheduleEntity->setScheduleResourcesJson(json_encode($scheduleResources));
         $scheduleEntity->setStartDate($this->scheduleCalculateStartDate($scheduleEntity->getId()));
         $scheduleEntity->setMinRange($this->scheduleCalculateMinRange($scheduleEntity->getId()));
         $scheduleEntity->setMaxRange($this->scheduleCalculateMaxRange($scheduleEntity->getId()));
         $this->em->persist($scheduleEntity);
         $this->em->flush();
         return $scheduleEntity->getScheduleJson();
     } else {
         return null;
     }
 }
Пример #3
0
 public function resolveDraw($pair1, $pair2, $rank, $games)
 {
     $gameService = new GameService();
     $gameService->setManager($this->em);
     $resultWonGame = $gameService->wonGameByPairs($pair1, $pair2, $games);
     if ($resultWonGame == $pair2) {
         $first = 0;
         foreach ($rank as $r) {
             if ($r['pair'] == $pair1) {
                 $tmp1 = $r;
             } else {
                 if ($r['pair'] == $pair2) {
                     $tmp2 = $r;
                 }
             }
         }
         $rankNew = array();
         foreach ($rank as $r) {
             if ($r['pair'] == $pair1 || $r['pair'] == $pair2) {
                 if ($first == 0) {
                     $rankNew[] = $tmp2;
                     $first = 1;
                 } else {
                     $rankNew[] = $tmp1;
                 }
             } else {
                 $rankNew[] = $r;
             }
         }
         return $rankNew;
     }
     return $rank;
 }
Пример #4
0
 public function generateDraw($inscriptions, $numMatchs, $categoryId, $tournamentId)
 {
     $gameService = new GameService();
     $gameService->setManager($this->em);
     $gamesOnDraw = array();
     $flagRound = 0;
     while ($numMatchs > 0) {
         for ($i = 0; $i < $numMatchs; $i++) {
             $paramsForDoGame = array('category' => $categoryId, 'tournament' => $tournamentId, 'isDrawGame' => true);
             $paramsForDoGame['description'] = $tournamentId . ';' . $categoryId . '|' . $numMatchs . '/' . $i;
             if ($flagRound == 0) {
                 $paramsForDoGame['pair1'] = $this->assignPairForDrawGame($inscriptions, $numMatchs, $i, 'pair1');
                 $paramsForDoGame['pair2'] = $this->assignPairForDrawGame($inscriptions, $numMatchs, $i, 'pair2');
             } else {
                 if ($flagRound == 1) {
                     $descriptionPair1 = $tournamentId . ';' . $categoryId . '|' . $numMatchs * 2 . '/' . $i * 2;
                     $paramsForDoGame['pair1'] = $this->checkPairToAddDraw($descriptionPair1);
                     $index = $i * 2;
                     $index = $index + 1;
                     $descriptionPair2 = $tournamentId . ';' . $categoryId . '|' . $numMatchs * 2 . '/' . $index;
                     $paramsForDoGame['pair2'] = $this->checkPairToAddDraw($descriptionPair2);
                 }
             }
             $gameSaved = $gameService->saveGame($paramsForDoGame);
             $gamesOnDraw[] = $gameSaved['message'];
         }
         $flagRound++;
         $numMatchs = $numMatchs / 2;
         $numMatchs = intval($numMatchs);
     }
     return $gamesOnDraw;
 }