public function addCategoryAction($idTournament) { $this->categoryService->setManager($this->getDoctrine()->getManager()); $tournamentService = new TournamentService(); $tournamentService->setManager($this->getDoctrine()->getManager()); $tournament = $tournamentService->getTournament($idTournament); if ($tournament instanceof Tournament) { $params = array(); $content = $this->get("request")->getContent(); if (!empty($content)) { $params = json_decode($content, true); if (!empty($params['category'])) { $tournament = $this->categoryService->addCategoriesToTournament($params['category'], $tournament, $this); $dataToSend = json_encode(array('tournament' => $tournament)); return $this->util->setJsonResponse(200, $dataToSend); } else { return $this->util->setResponse(400, Literals::CategoryNotFound); } } else { return $this->util->setResponse(400, Literals::EmptyContent); } } else { return $this->util->setResponse(400, Literals::TournamentNotFound); } }
private function setGroupSave($group, $params) { $group->setName(!empty($params['name']) ? $params['name'] : 'No name'); if (!empty($params['category'])) { if (is_int($params['category'])) { $categoryService = new CategoryService(); $categoryService->setManager($this->em); $cat = $categoryService->getCategory($params['category']); $group->setCategory($cat); } else { $group->setCategory($params['category']); } } else { $group->setCategory(null); } if (!empty($params['tournament'])) { if (is_int($params['tournament'])) { $tournamentService = new TournamentService(); $tournamentService->setManager($this->em); $cat = $tournamentService->getTournament($params['tournament']); $group->setTournament($cat); } else { $group->setTournament($params['tournament']); } } else { $group->setTournament(null); } $group->setNumPairs(is_int($params['numPairs']) ? $params['numPairs'] : null); return $group; }
public function getGroupByTournamentAction($idTournament) { $this->groupService->setManager($this->getDoctrine()->getManager()); $groups = $this->groupService->getGroupsByTournament($idTournament); $tournamentService = new TournamentService(); $tournamentService->setManager($this->getDoctrine()->getManager()); $tournament = $tournamentService->getTournament($idTournament); if (!$tournament instanceof Tournament) { return $this->util->setResponse(400, Literals::TournamentNotFound); } else { $dataToSend = json_encode(array('group' => $groups)); return $this->util->setJsonResponse(200, $dataToSend); } }
public function getGameByTournamentAction($idTournament, $isDraw) { $this->gameService->setManager($this->getDoctrine()->getManager()); if ($isDraw == "true") { $games = $this->gameService->getGamesInDrawByTournament($idTournament); } else { $games = $this->gameService->getGamesByTournament($idTournament); } $tournamentService = new TournamentService(); $tournamentService->setManager($this->getDoctrine()->getManager()); $tournament = $tournamentService->getTournament($idTournament); if (!$tournament instanceof Tournament) { return $this->util->setResponse(400, Literals::TournamentNotFound); } else { $dataToSend = json_encode(array('game' => $games)); return $this->util->setJsonResponse(200, $dataToSend); } }
private function setScheduleSave($schedule, $params) { if (!empty($params['tournament'])) { if (is_int($params['tournament'])) { $tournamentService = new TournamentService(); $tournamentService->setManager($this->em); $tournament = $tournamentService->getTournament($params['tournament']); $schedule->setTournament($tournament); } else { $schedule->setTournament($params['tournament']); } } else { $schedule->setTournament(null); } $schedule->setScheduleJson(!empty($params['scheduleJson']) ? $params['scheduleJson'] : ''); $schedule->setScheduleResourcesJson(!empty($params['scheduleResourcesJson']) ? $params['scheduleResourcesJson'] : ''); $schedule->setStartDate(!empty($params['startDate']) ? $params['startDate'] : ''); $schedule->setMaxRange(!empty($params['maxRange']) ? $params['maxRange'] : ''); $schedule->setMinRange(!empty($params['minRange']) ? $params['minRange'] : ''); $this->em->persist($schedule); $this->em->flush(); return $schedule; }
public function postNotificationAction() { $this->notificationService->setManager($this->getDoctrine()->getManager()); $params = array(); $content = $this->get("request")->getContent(); $params = json_decode($content, true); $tournamentService = new TournamentService(); $tournamentService->setManager($this->getDoctrine()->getManager()); if (!empty($params['tournament'])) { $tournament = $tournamentService->getTournament(trim($params['tournament'])); if (!$tournament instanceof Tournament) { return $this->util->setResponse(404, Literals::TournamentNotFound); } $notification = $this->notificationService->saveNotification($params, $tournament, $this); if ($notification['result'] == 'fail') { $dataToSend = json_encode(array('error' => $notification['message'])); return $this->util->setResponse(400, $dataToSend); } $dataToSend = json_encode(array('notification' => $notification['message'])); return $this->util->setJsonResponse(201, $dataToSend); } return $this->util->setResponse(404, Literals::TournamentNotFound); }
public function testCloseGroupTournament() { $this->setUpGroupsAndGames(); $tournamentService = new TournamentService(); $tournamentService->setManager($this->em); $groups = $tournamentService->closeGroupTournament($this->tournament); $this->assertEquals($this->inscription1->getClassifiedPositionInGroup(), 0); $this->assertEquals($this->inscription1->getClassifiedPositionByGroups(), 2); $this->assertEquals($this->inscription2->getClassifiedPositionInGroup(), 1); $this->assertEquals($this->inscription2->getClassifiedPositionByGroups(), 2); $this->assertEquals($this->inscription3->getClassifiedPositionInGroup(), 2); $this->assertEquals($this->inscription3->getClassifiedPositionByGroups(), 2); $this->assertEquals($this->inscription4->getClassifiedPositionInGroup(), 0); $this->assertEquals($this->inscription4->getClassifiedPositionByGroups(), 1); $this->assertEquals($this->inscription5->getClassifiedPositionInGroup(), 1); $this->assertEquals($this->inscription5->getClassifiedPositionByGroups(), 0); $this->assertEquals($this->inscription6->getClassifiedPositionInGroup(), 2); $this->assertEquals($this->inscription6->getClassifiedPositionByGroups(), 0); $this->assertEquals($this->inscription7->getClassifiedPositionInGroup(), 3); $this->assertEquals($this->inscription7->getClassifiedPositionByGroups(), 1); $this->assertEquals($this->inscription8->getClassifiedPositionInGroup(), 0); $this->assertEquals($this->inscription8->getClassifiedPositionByGroups(), 0); $this->assertEquals($this->inscription9->getClassifiedPositionInGroup(), 1); $this->assertEquals($this->inscription9->getClassifiedPositionByGroups(), 1); $this->assertEquals($this->inscription10->getClassifiedPositionInGroup(), 2); $this->assertEquals($this->inscription10->getClassifiedPositionByGroups(), 1); $this->assertEquals($this->inscription11->getClassifiedPositionInGroup(), 3); $this->assertEquals($this->inscription11->getClassifiedPositionByGroups(), 0); $this->tearDownGroupsAndGames(); }
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); } }
public function countInscriptionAction($idTournament) { $this->inscriptionService->setManager($this->getDoctrine()->getManager()); $inscriptions = $this->inscriptionService->getCountInscriptionsByTournamentByCategory($idTournament); $tournamentService = new TournamentService(); $tournamentService->setManager($this->getDoctrine()->getManager()); $tournament = $tournamentService->getTournament($idTournament); if (!$tournament instanceof Tournament) { return $this->util->setResponse(400, Literals::TournamentNotFound); } else { $dataToSend = json_encode(array('inscription' => $inscriptions)); return $this->util->setJsonResponse(200, $dataToSend); } }
private function getTournamentFromParams($params) { $tournamentService = new TournamentService(); $tournamentService->setManager($this->em); $tournament = $tournamentService->getTournament(isset($params['tournament']) ? $params['tournament'] : ''); return $tournament; }