Пример #1
0
 public function testSortByScore()
 {
     $rank[1] = array('matchsWon' => 2, 'setsWon' => 5, 'setsLost' => 3, 'gamesWon' => 35, 'gamesLost' => 38, 'points' => 6, 'pair' => 1);
     $rank[2] = array('matchsWon' => 1, 'setsWon' => 3, 'setsLost' => 5, 'gamesWon' => 38, 'gamesLost' => 35, 'points' => 3, 'pair' => 2);
     $rank[3] = array('matchsWon' => 3, 'setsWon' => 6, 'setsLost' => 0, 'gamesWon' => 55, 'gamesLost' => 20, 'points' => 9, 'pair' => 3);
     $rank[4] = array('matchsWon' => 0, 'setsWon' => 2, 'setsLost' => 8, 'gamesWon' => 21, 'gamesLost' => 60, 'points' => 0, 'pair' => 4);
     $rank[5] = array('matchsWon' => 2, 'setsWon' => 4, 'setsLost' => 0, 'gamesWon' => 40, 'gamesLost' => 20, 'points' => 6, 'pair' => 5);
     $rank[6] = array('matchsWon' => 1, 'setsWon' => 3, 'setsLost' => 5, 'gamesWon' => 39, 'gamesLost' => 35, 'points' => 3, 'pair' => 6);
     $groupService = new GroupService();
     $groupService->setManager($this->em);
     $rankResult = $groupService->sortByScore($rank);
     $this->assertEquals(json_encode($rankResult), '[{"matchsWon":3,"setsWon":6,"setsLost":0,"gamesWon":55,"gamesLost":20,"points":9,"pair":3},{"matchsWon":2,"setsWon":5,"setsLost":3,"gamesWon":35,"gamesLost":38,"points":6,"pair":1},{"matchsWon":2,"setsWon":4,"setsLost":0,"gamesWon":40,"gamesLost":20,"points":6,"pair":5},{"matchsWon":1,"setsWon":3,"setsLost":5,"gamesWon":39,"gamesLost":35,"points":3,"pair":6},{"matchsWon":1,"setsWon":3,"setsLost":5,"gamesWon":38,"gamesLost":35,"points":3,"pair":2},{"matchsWon":0,"setsWon":2,"setsLost":8,"gamesWon":21,"gamesLost":60,"points":0,"pair":4}]');
 }
Пример #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;
 }