コード例 #1
0
 /**
  * Add new club
  * @Route("/admin/club/add", name="_edit_club_add")
  * @Template("ICupPublicSiteBundle:Edit:editclub.html.twig")
  */
 public function addAction(Request $request)
 {
     $returnUrl = $this->get('util')->getReferer();
     $country = $request->get('country');
     if ($country == null) {
         $country = $this->get('util')->getCountryByLocale($request->getLocale());
     }
     $club = new Club();
     // If country is a part of the request parameters - use it
     $club->setCountry($country);
     $form = $this->makeClubForm($club, 'add');
     $form->handleRequest($request);
     if ($form->get('cancel')->isClicked()) {
         return $this->redirect($returnUrl);
     }
     if ($this->checkForm($form, $club)) {
         $otherclub = $this->get('logic')->getClubByName($club->getName(), $club->getCountry());
         if ($otherclub != null) {
             $form->addError(new FormError($this->get('translator')->trans('FORM.CLUB.NAMEEXIST', array(), 'admin')));
         } else {
             $em = $this->getDoctrine()->getManager();
             $em->persist($club);
             $em->flush();
             return $this->redirect($returnUrl);
         }
     }
     return array('form' => $form->createView(), 'action' => 'add', 'club' => $club);
 }
コード例 #2
0
 private function listEnrolled(Tournament $tmnt, Club $club)
 {
     $host = $tmnt->getHost();
     $enrolled = $this->get('logic')->listEnrolledByClub($tmnt->getId(), $club->getId());
     $enrolledList = array();
     /* @var $enroll Enrollment */
     foreach ($enrolled as $enroll) {
         $enrolledList[$enroll->getCategory()->getId()][] = $enroll;
     }
     $classMap = array();
     $categoryMap = array();
     /* @var $category Category */
     foreach ($tmnt->getCategories() as $category) {
         $classification = $category->getClassification() . $category->getAge();
         $classMap[$classification] = $classification;
         $cls = $category->getGender() . $classification;
         $categoryMap[$cls][] = $category;
     }
     return array('host' => $host, 'tournament' => $tmnt, 'club' => $club, 'classifications' => $classMap, 'enrolled' => $enrolledList, 'categories' => $categoryMap);
 }
コード例 #3
0
 private function mergeClubs(Club $source_club, Club $target_club)
 {
     $em = $this->getDoctrine()->getManager();
     $teams = $source_club->getTeams();
     /* @var $category Category */
     foreach ($teams as $team) {
         try {
             $category = $this->get('logic')->getEnrolledCategory($team->getId());
         } catch (ValidationException $ex) {
             $category = $this->get('logic')->getAssignedCategory($team->getId());
         }
         $enrolledteams = $this->get('logic')->listEnrolledTeamsByCategory($category->getId(), $target_club->getId());
         $noTeams = count($enrolledteams);
         if ($noTeams >= 26) {
             // Can not add more than 26 teams to same category - Team A -> Team Z - make an exception here...
             $division = 'm' . $team->getDivision();
         } else {
             if ($noTeams == 0) {
                 $division = '';
             } else {
                 if ($noTeams == 1) {
                     $division = 'B';
                     $firstteam = array_shift($enrolledteams);
                     $firstteam->setDivision('A');
                 } else {
                     $division = chr($noTeams + 65);
                 }
             }
         }
         $team->setClub($target_club);
         $team->setName($target_club->getName());
         $team->setDivision($division);
         $em->flush();
     }
     $em->remove($source_club);
     $em->flush();
 }
コード例 #4
0
 /**
  * Add new club for for selected tournament
  * - Editor version only -
  * @Route("/edit/club/new/{tournamentid}", name="_host_club_new")
  * @Template("ICupPublicSiteBundle:Host:new_club.html.twig")
  */
 public function hostNewClubAction($tournamentid, Request $request)
 {
     /* @var $utilService Util */
     $utilService = $this->get('util');
     /* @var $user User */
     $user = $utilService->getCurrentUser();
     /* @var $tournament Tournament */
     $tournament = $this->get('entity')->getTournamentById($tournamentid);
     $host = $tournament->getHost();
     $utilService->validateEditorAdminUser($user, $host);
     // Prepare default data for form
     $clubFormData = $this->getClubDefaults($request);
     $form = $this->makeClubForm($clubFormData);
     $form->handleRequest($request);
     if ($form->get('cancel')->isClicked()) {
         return $this->redirect($this->generateUrl('_host_list_clubs', array('tournamentid' => $tournamentid)));
     }
     if ($this->checkForm($form, $clubFormData)) {
         $club = $this->get('logic')->getClubByName($clubFormData->getName(), $clubFormData->getCountry());
         if ($club == null) {
             $club = new Club();
             $club->setName($clubFormData->getName());
             $club->setCountry($clubFormData->getCountry());
             $em = $this->getDoctrine()->getManager();
             $em->persist($club);
             $em->flush();
         }
         return $this->redirect($this->generateUrl('_club_enroll_list_admin', array('tournament' => $tournamentid, 'club' => $club->getId())));
     }
     return array('form' => $form->createView(), 'action' => 'add', 'user' => $user, 'tournament' => $tournament);
 }
コード例 #5
0
 private function addTeam(Category $category, Group $group, Club $club, $division, User $user)
 {
     $team = new Team();
     $team->setName($club->getName());
     $team->setColor($category->getName() . $group->getName() . ($group->getGroupOrder()->count() + 1));
     $team->setDivision($division);
     $team->setVacant(false);
     $team->setClub($club);
     $club->getTeams()->add($team);
     $this->em->persist($team);
     $grouporder = new GroupOrder();
     $grouporder->setGroup($group);
     $grouporder->setTeam($team);
     $team->getGroupOrder()->add($grouporder);
     $group->getGroupOrder()->add($grouporder);
     $this->em->persist($grouporder);
     $enrollment = new Enrollment();
     $enrollment->setTeam($team);
     $enrollment->setCategory($category);
     $enrollment->setDate(Date::getDate(new DateTime()));
     $enrollment->setUser($user);
     $team->getEnrollments()->add($enrollment);
     $category->getEnrollments()->add($enrollment);
     $user->getEnrollments()->add($enrollment);
     $this->em->persist($enrollment);
 }
コード例 #6
0
 public function assignVacant($groupid, User $user)
 {
     /* @var $group Group */
     $group = $this->entity->getGroupById($groupid);
     $club = $this->getClubByName(BusinessLogic::$VACANT_CLUB_NAME, BusinessLogic::$VACANT_CLUB_COUNTRYCODE);
     if ($club == null) {
         $club = new Club();
         $club->setName(BusinessLogic::$VACANT_CLUB_NAME);
         $club->setCountry(BusinessLogic::$VACANT_CLUB_COUNTRYCODE);
         $this->em->persist($club);
         $this->em->flush();
     }
     $enrolled = $this->addEnrolled($group->getCategory(), $club, $user, true);
     $groupOrder = new GroupOrder();
     $groupOrder->setTeam($enrolled->getTeam());
     $groupOrder->setGroup($group);
     $this->em->persist($groupOrder);
     $this->em->flush();
     return $groupOrder;
 }
コード例 #7
0
ファイル: Util.php プロジェクト: armandomeeuwenoord/icup
 /**
  * Verify that user is admin or a club user allowed to administer the club specified by clubid
  * This function does not ensure that user->cid is referring to a valid club - if user is an admin.
  * @param User $user
  * @param Club $club
  * @throws ValidationException
  */
 public function validateClubAdminUser(User $user, Club $club)
 {
     // If user is admin anything is allowed...
     if (!$this->isAdminUser($user)) {
         // Since this is not the admin - validate for club admin
         if (!$user->isClub()) {
             // Controller is called by club user user
             throw new ValidationException("NOTCLUBADMIN", "user="******"NOTCLUBADMIN", "user="******", clubid=" . $club->getId());
         }
     }
 }
コード例 #8
0
 private function commitImport($parseObj, User $user)
 {
     $em = $this->getDoctrine()->getManager();
     $category = $parseObj['category'];
     $team = $parseObj['teamA'];
     $name = $parseObj['team']['name'];
     $division = $parseObj['team']['division'];
     $country = $parseObj['team']['country'];
     if (!$team) {
         $club = $this->get('logic')->getClubByName($name, $country);
         if ($club == null) {
             $club = new Club();
             $club->setName($name);
             $club->setCountry($country);
             $em->persist($club);
             $em->flush();
         }
         $enroll = $this->get('logic')->enrollTeam($category, $user, $club, $name, $division);
         $team = $enroll->getTeam();
     }
     if (!$this->get('logic')->isTeamAssigned($category->getId(), $team->getId())) {
         $group = $parseObj['group'];
         $this->get('logic')->assignEnrolled($team->getId(), $group->getId());
     }
 }