public function saveObservationsPOST($params, $controller) { $resumeToObservationsInsert = null; $resumeToObservationsInsert['message'] = ""; $resumeToObservationsInsert['result'] = "ok"; $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->em); $inscription = $inscriptionService->getInscription($params['inscription']); $observations = $this->getObservationByInscription($params['inscription']); foreach ($observations as $obs) { $this->deleteObservation($obs); } foreach ($params['observations'] as $objObs) { $result = $this->saveObservation($objObs, $inscription, $controller); if ($result['result'] == 'fail') { $resumeToObservationsInsert['message'] .= $inscription->getId() . '|' . $result['message'] . ';'; $resumeToObservationsInsert['result'] = 'fail'; } } return $resumeToObservationsInsert; }
public function postOneObservationsAction() { $this->observationService->setManager($this->getDoctrine()->getManager()); $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->getDoctrine()->getManager()); $params = array(); $content = $this->get("request")->getContent(); $params = json_decode($content, true); if (!empty($params['inscription']) && !empty($params['observation'])) { $inscription = $inscriptionService->getInscription($params['inscription']); $observations = $this->observationService->saveObservation($params['observation'], $inscription, $this); if ($observations['result'] == 'fail') { $dataToSend = json_encode(array('error' => $observations['message'])); return $this->util->setResponse(400, $dataToSend); } $dataToSend = json_encode(array('observations' => $observations['message'])); return $this->util->setJsonResponse(201, $dataToSend); } else { return $this->util->setResponse(400, Literals::ObservationBadFormat); } }
public function testSortByClassified() { $inscriptions = [$this->inscription1, $this->inscription2, $this->inscription3, $this->inscription4, $this->inscription5]; $inscriptionsExpected = [$this->inscription2, $this->inscription3, $this->inscription5, $this->inscription4, $this->inscription1]; $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->em); $inscriptionsResult = $inscriptionService->orderByClassified($inscriptions); $this->assertEquals($inscriptionsResult, $inscriptionsExpected); }
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 checkPairsInGroup($group, $categoryId, $pairs) { $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->em); $inscirptions = array(); foreach ($pairs as $pair) { $inscriptionEntity = $inscriptionService->getInscriptionsByPairAndCategory($pair, $categoryId); if ($inscriptionEntity instanceof Inscription) { if ($inscriptionEntity->getGroup()->getId() != $group->getId()) { $inscriptionEntity->setGroup($group); $this->em->persist($inscriptionEntity); } } } $this->em->flush(); }
public function createDrawForCategory($inscriptions, $categoryId, $tournamentId) { $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->em); $inscriptions = $inscriptionService->orderByClassified($inscriptions); $numInscriptions = count($inscriptions); $drawLength = $this->getDrawLength($numInscriptions); $numPairsBye = $drawLength - $numInscriptions; for ($i = 0; $i < $numPairsBye; $i++) { $inscriptions[] = Literals::ByePairName; } $numMatchs = $drawLength / 2; $numMatchs = intval($numMatchs); $gamesOnDraw = $this->generateDraw($inscriptions, $numMatchs, $categoryId, $tournamentId); return $gamesOnDraw; }
public function createDrawTournament($tournament, $params) { $categoryService = new CategoryService(); $categoryService->setManager($this->em); $inscriptionService = new InscriptionService(); $inscriptionService->setManager($this->em); $gamesForDraw = array(); $saveChangesCorrect = true; if (!empty($params)) { foreach ($params as $categoryId => $category) { $categoryEntity = $categoryService->getCategory($categoryId); if (!is_null($categoryEntity)) { $inscriptionsInCategory = array(); foreach ($category as $pairId) { $inscriptionsInCategory[] = $inscriptionService->getInscriptionsByPairAndCategory($pairId, $categoryId); } $gamesForDraw[$categoryEntity->getName() . ';' . $categoryId] = $categoryService->createDrawForCategory($inscriptionsInCategory, $categoryId, $tournament->getId()); } else { $saveChangesCorrect = false; } } } else { $saveChangesCorrect = false; } if ($saveChangesCorrect) { $tournament->setStatus($this->statusService->getStatus('tournament', Literals::In_Finals_DateTournamentStatus)); $this->em->persist($tournament); $this->em->flush(); $result = array('result' => 'ok', 'message' => $gamesForDraw); return $result; } else { return $result = array('result' => 'fail', 'message' => Literals::TournamentChangesNotSaved); } }