Пример #1
0
 public function saveGamesTournament($params)
 {
     if (!empty($params['tournamentId'])) {
         $tournamentService = new TournamentService();
         $tournamentService->setManager($this->em);
         $tournament = $tournamentService->getTournament($params['tournamentId']);
         $allGamesToReturnInCategory = array();
         if ($tournament instanceof Tournament) {
             $inscriptionService = new InscriptionService();
             $inscriptionService->setManager($this->em);
             $inscriptionsTournament = $inscriptionService->getInscriptionsByGroupForATournament($params['tournamentId'], null);
             foreach ($inscriptionsTournament as $categoryKey => $inscriptionsCategory) {
                 $gamesForGroup = array();
                 foreach ($inscriptionsCategory as $groupKey => $inscriptionsGroup) {
                     $gamesForGroup[] = $this->doGamesByGroup($inscriptionsGroup);
                 }
                 $allGamesToReturnInCategory[$categoryKey] = $gamesForGroup;
             }
             $scheduleService = new ScheduleService();
             $scheduleService->setManager($this->em);
             $scheduleService->setDatesToMatchsInTournament($this->getGamesByTournamentInArray($tournament->getId()), $inscriptionService->getInscriptionsByTournamentInArray($tournament->getId()), $tournament->getId());
             $tournament->setStatus($this->statusService->getStatus('tournament', Literals::Matchs_DoneTournamentStatus));
             $this->em->persist($tournament);
             $this->em->flush();
             return array('result' => 'ok', 'message' => $this->getGamesByTournament($tournament->getId()));
         } else {
             return array('result' => 'fail', 'message' => Literals::TournamentIdNotCorrect);
         }
     } else {
         return array('result' => 'fail', 'message' => Literals::TournamentIdNotCorrect);
     }
 }
Пример #2
0
 public function closeGroupTournament($tournament)
 {
     $categoryService = new CategoryService();
     $inscriptionService = new InscriptionService();
     $groupService = new GroupService();
     $categoryService->setManager($this->em);
     $inscriptionService->setManager($this->em);
     $groupService->setManager($this->em);
     $categories = $categoryService->getCategoryByTournament($tournament->getId());
     foreach ($categories as $category) {
         $groupsRank = array();
         $numPairsByGroup = array();
         $allInscriptions = array();
         $groups = $groupService->getGroupsByCategory($category->getId());
         if (!is_null($groups)) {
             foreach ($groups as $group) {
                 $inscriptions = $inscriptionService->getInscriptionsByGroup($group->getId(), null);
                 $allInscriptions = array_merge($allInscriptions, $inscriptions);
                 $groupRank = $groupService->calculateClassficationByGroup($inscriptions, $group);
                 if (!is_null($groupRank)) {
                     $numPairsByGroup[] = count($groupRank);
                     $groupsRank[] = $groupRank;
                 }
             }
         }
         if (!empty($groupsRank)) {
             rsort($numPairsByGroup);
             for ($i = 0; $i < $numPairsByGroup[0]; $i++) {
                 $rankByGroupPositions = array();
                 foreach ($groupsRank as $groupRank) {
                     if (count($groupRank) > $i && !is_null($groupRank[$i])) {
                         $rankByGroupPositions[] = $groupRank[$i];
                     }
                 }
                 $rankByGroupPositions = $groupService->sortByScore($rankByGroupPositions);
                 foreach ($allInscriptions as $inscription) {
                     $position = 0;
                     foreach ($rankByGroupPositions as $rank) {
                         if ($inscription->getPair()->getId() == $rank['pair']) {
                             $inscription->setClassifiedPositionByGroups($position);
                             $this->em->persist($inscription);
                         }
                         $position = $position + 1;
                     }
                 }
             }
         }
     }
     $this->em->flush();
     $result = array('result' => 'ok', 'message' => $inscriptionService->getInscriptionsByGroupForATournament($tournament->getId(), 'classifiedPositionInGroup'));
     return $result;
 }