コード例 #1
0
ファイル: GameController.php プロジェクト: albertoml/padelTFG
 public function getGameByGroupAction($idGroup)
 {
     $this->gameService->setManager($this->getDoctrine()->getManager());
     $games = $this->gameService->getGamesByGroup($idGroup);
     $groupService = new GroupService();
     $groupService->setManager($this->getDoctrine()->getManager());
     $group = $groupService->getGroup($idGroup);
     if (!$group instanceof GroupCategory) {
         return $this->util->setResponse(400, Literals::GroupNotFound);
     } else {
         $dataToSend = json_encode(array('game' => $games));
         return $this->util->setJsonResponse(200, $dataToSend);
     }
 }
コード例 #2
0
ファイル: GameService.php プロジェクト: albertoml/padelTFG
 private function setGameSave($game, $params)
 {
     $game->setDescription(!empty($params['description']) ? $params['description'] : '');
     if (!empty($params['category'])) {
         if (is_int($params['category'])) {
             $categoryService = new CategoryService();
             $categoryService->setManager($this->em);
             $cat = $categoryService->getCategory($params['category']);
             $game->setCategory($cat);
         } else {
             $game->setCategory($params['category']);
         }
     } else {
         $game->setCategory(null);
     }
     if (!empty($params['tournament'])) {
         if (is_int($params['tournament'])) {
             $tournamentService = new TournamentService();
             $tournamentService->setManager($this->em);
             $tournament = $tournamentService->getTournament($params['tournament']);
             $game->setTournament($tournament);
         } else {
             $game->setTournament($params['tournament']);
         }
     } else {
         $game->setTournament(null);
     }
     if (!empty($params['group'])) {
         if (is_int($params['group'])) {
             $groupService = new GroupService();
             $groupService->setManager($this->em);
             $group = $groupService->getGroup($params['group']);
             $game->setGroup($group);
         } else {
             $game->setGroup($params['group']);
         }
     } else {
         $game->setGroup(null);
     }
     $game->setPair1(!empty($params['pair1']) ? $params['pair1'] : null);
     $game->setPair2(!empty($params['pair2']) ? $params['pair2'] : null);
     $game->setScore(!empty($params['score']) ? $params['score'] : '');
     $game->setStatus($this->statusService->getStatus('game', Literals::CreatedGameStatus));
     $game->setStartDate(!empty($params['startDate']) ? $params['startDate'] : null);
     $game->setEndDate(!empty($params['endDate']) ? $params['endDate'] : null);
     $game->setTrack(!empty($params['track']) ? $params['track'] : '');
     $game->setBgColor(!empty($params['bgColor']) ? $params['bgColor'] : '');
     $game->setIsDrawGame(!empty($params['isDrawGame']) ? $params['isDrawGame'] : false);
     return $game;
 }
コード例 #3
0
 public function orderByClassified($inscriptions)
 {
     $groupService = new GroupService();
     $groupService->setManager($this->em);
     if (!is_null($inscriptions) && count($inscriptions) > 0) {
         $numGroups = $groupService->getNumGroupsByCategory($inscriptions[0]->getCategory()->getId());
         $inscriptionsOrder = array();
         $pivot = 0;
         $pivotGroup = 0;
         while (count($inscriptionsOrder) != count($inscriptions)) {
             foreach ($inscriptions as $inscription) {
                 if ($inscription->getClassifiedPositionInGroup() == $pivotGroup && $inscription->getClassifiedPositionByGroups() == $pivot) {
                     $inscriptionsOrder[] = $inscription;
                 }
             }
             $pivot = $pivot + 1;
             if ($pivot >= $numGroups) {
                 $pivot = 0;
                 $pivotGroup = $pivotGroup + 1;
             }
         }
         return $inscriptionsOrder;
     } else {
         return $inscriptions;
     }
 }
コード例 #4
0
 public function testCalculateClassficationByGroupDoubleTie()
 {
     $this->game1->setScore("6/0 6/0");
     $this->game2->setScore("2/6 1/6");
     $this->game3->setScore("4/6 2/6");
     $this->game4->setScore("1/6 2/6");
     $this->game5->setScore("6/1 6/2");
     $this->game6->setScore("6/1 6/1");
     $this->game7->setScore("6/0 6/4");
     $this->game8->setScore("6/0 6/3");
     $this->game9->setScore("6/1 6/2");
     $this->game10->setScore("6/1 6/3");
     $this->em->persist($this->game1);
     $this->em->persist($this->game2);
     $this->em->persist($this->game3);
     $this->em->persist($this->game4);
     $this->em->persist($this->game5);
     $this->em->persist($this->game6);
     $this->em->persist($this->game7);
     $this->em->persist($this->game8);
     $this->em->persist($this->game9);
     $this->em->persist($this->game10);
     $inscriptions = [$this->inscription1, $this->inscription2, $this->inscription3, $this->inscription4, $this->inscription5];
     $groupService = new GroupService();
     $groupService->setManager($this->em);
     $rankResult = $groupService->calculateClassficationByGroup($inscriptions, $this->group);
     $this->assertEquals(json_encode($rankResult), '[{"matchsWon":3,"setsWon":6,"setsLost":2,"gamesWon":36,"gamesLost":21,"points":9,"pair":' . $this->pair2->getId() . '},{"matchsWon":3,"setsWon":6,"setsLost":2,"gamesWon":39,"gamesLost":21,"points":9,"pair":' . $this->pair3->getId() . '},{"matchsWon":2,"setsWon":4,"setsLost":4,"gamesWon":29,"gamesLost":34,"points":6,"pair":' . $this->pair4->getId() . '},{"matchsWon":1,"setsWon":2,"setsLost":6,"gamesWon":23,"gamesLost":39,"points":3,"pair":' . $this->pair5->getId() . '},{"matchsWon":1,"setsWon":2,"setsLost":6,"gamesWon":24,"gamesLost":36,"points":3,"pair":' . $this->pair1->getId() . '}]');
     $this->assertEquals($this->inscription1->getClassifiedPositionInGroup(), 4);
     $this->assertEquals($this->inscription2->getClassifiedPositionInGroup(), 0);
     $this->assertEquals($this->inscription3->getClassifiedPositionInGroup(), 1);
     $this->assertEquals($this->inscription4->getClassifiedPositionInGroup(), 2);
     $this->assertEquals($this->inscription5->getClassifiedPositionInGroup(), 3);
 }
コード例 #5
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;
 }