Пример #1
0
 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;
 }
Пример #2
0
 public function getGroupByCategoryAction($idCategory)
 {
     $this->groupService->setManager($this->getDoctrine()->getManager());
     $groups = $this->groupService->getGroupsByCategory($idCategory);
     $categoryService = new CategoryService();
     $categoryService->setManager($this->getDoctrine()->getManager());
     $category = $categoryService->getCategory($idCategory);
     if (!$category instanceof Category) {
         return $this->util->setResponse(400, Literals::CategoryNotFound);
     } else {
         $dataToSend = json_encode(array('group' => $groups));
         return $this->util->setJsonResponse(200, $dataToSend);
     }
 }
Пример #3
0
 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;
 }
Пример #4
0
 public function testGenerateDraw2()
 {
     $inscriptions = [$this->inscription1, $this->inscription2];
     $categoryService = new CategoryService();
     $categoryService->setManager($this->em);
     $category = $this->category->getId();
     $tournament = $this->tournament->getId();
     $this->games = $categoryService->generateDraw($inscriptions, 1, $category, $tournament);
     $this->assertContains('' . $this->pair1->getId(), json_encode($this->games));
     $this->assertContains('' . $this->pair2->getId(), json_encode($this->games));
     foreach ($this->games as $game) {
         $this->em->remove($game);
     }
     if (count($this->games) > 0) {
         $this->em->flush();
     }
 }
Пример #5
0
 private function getCategoryFromParams($params)
 {
     $categoryService = new CategoryService();
     $categoryService->setManager($this->em);
     $category = $categoryService->getCategory(isset($params['category']) ? $params['category'] : '');
     return $category;
 }
Пример #6
0
 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);
     }
 }