public function getGamesInDrawByTournament($idTournament) { $categoryService = new CategoryService(); $categoryService->setManager($this->em); $categories = $categoryService->getCategoryByTournament($idTournament); $returnGames = array(); foreach ($categories as $category) { $games = $this->getGamesInDrawByCategory($category->getId()); $returnGames[$category->getName() . ';' . $category->getId()] = $games; } return $returnGames; }
public function getCountInscriptionsByTournamentByCategory($idTournament) { $categoryService = new CategoryService(); $categoryService->setManager($this->em); $categories = $categoryService->getCategoryByTournament($idTournament); $returnInscriptions = array(); foreach ($categories as $category) { $inscriptions = $this->getCountInscriptionsInCategory($category->getId()); $returnInscriptions[$category->getName()] = $inscriptions; } $returnInscriptionsTotal['totalTournament'] = $this->getCountInscriptionsInTournament($idTournament); $returnInscriptionsTotal['category'] = $returnInscriptions; return $returnInscriptionsTotal; }
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; }