public function addEnrolled(Category $category, Club $club, User $user, $vacant = false) { $qb = $this->em->createQuery("select e " . "from " . $this->entity->getRepositoryPath('Enrollment') . " e, " . $this->entity->getRepositoryPath('Team') . " t " . "where e.category=:category and e.team=t.id and t.club=:club " . "order by e.category"); $qb->setParameter('category', $category->getId()); $qb->setParameter('club', $club->getId()); $enrolled = $qb->getResult(); $noTeams = count($enrolled); if ($noTeams >= 26) { // Can not add more than 26 teams to same category - Team A -> Team Z throw new ValidationException("NOMORETEAMS", "More than 26 enrolled - club=" . $club->getId() . ", category=" . $category->getId()); } else { if ($noTeams == 0) { $division = ''; } else { if ($noTeams == 1) { $division = 'B'; $this->updateDivision(array_shift($enrolled), 'A'); } else { $division = chr($noTeams + 65); } } } return $this->enrollTeam($category, $user, $club, $club->getName(), $division, $vacant); }
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); }
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(); }
/** * 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()); } } }