Example #1
0
 public static function getOfficialName(Race $race)
 {
     $name = '';
     switch ($race->getAgeClass()) {
         case 'Kind':
             if ($race->getGender() == Competitor::GENDER_FEMALE) {
                 $name = 'Mädchen';
             } elseif ($race->getGender() == Competitor::GENDER_MALE) {
                 $name = 'Jungen';
             } else {
                 $name = 'JuM';
             }
             $name .= ' (';
             if ($race->getAgeMin() == $race->getAgeMax()) {
                 $name .= $race->getAgeMin();
             } else {
                 $name .= $race->getAgeMin() . ' bis ' . $race->getAgeMax();
             }
             $name .= ' Jahre)';
             break;
         case 'Junior':
             if ($race->getGender() == Competitor::GENDER_FEMALE) {
                 $name = 'Juniorinnen';
             } else {
                 $name = 'Junioren';
             }
             if ($race->getAgeMin() == 15 && ($race->getAgeMax() == 16 || $race->getAgeMax() == $race->getAgeMin())) {
                 $name .= ' B';
             } elseif ($race->getAgeMin() == 17 && ($race->getAgeMax() == 18 || $race->getAgeMax() == $race->getAgeMin())) {
                 $name .= ' A';
             }
             break;
         case 'Senior':
             if ($race->getGender() == Competitor::GENDER_FEMALE) {
                 $name = 'Frauen';
             } elseif ($race->getGender() == Competitor::GENDER_MALE) {
                 $name = 'Männer';
             } else {
                 $name = 'Senioren';
             }
             if ($race->getAgeMax() < 23) {
                 $name .= ' B';
             } elseif ($race->getAgeMin() > 22 && $race->getAgeMax() < 27) {
                 $name .= ' A';
             } else {
                 $name .= ' (' . $race->getAgeMin() . ' bis ' . $race->getAgeMax() . ' Jahre)';
             }
             break;
         case 'Master':
             if ($race->getGender() == Competitor::GENDER_FEMALE) {
                 $name = 'Frauen (Masters)';
             } elseif ($race->getGender() == Competitor::GENDER_MALE) {
                 $name = 'Männer (Masters)';
             } else {
                 $name = 'Masters';
             }
             $name .= ' (' . $race->getAgeMin() . ' bis ' . $race->getAgeMax() . ' Jahre)';
             break;
         case 'Offen':
             $name = 'Offen';
             $name .= ' (' . $race->getAgeMin() . ' bis ' . $race->getAgeMax() . ' Jahre)';
             break;
     }
     if ($race->getTeamsize() > 1) {
         $name .= ' [' . $race->getTeamsize() . ' Pers.]';
     }
     return $name;
 }
 /**
  * Creates a new Event entity.
  *
  * @Route("/event/{event}/race/{race}/new", name="registration_new")
  * @Method({"GET", "POST"})
  * @Security("has_role('ROLE_REGISTRATION')")
  */
 public function newAction(Request $request, Event $event, Race $race)
 {
     $em = $this->getDoctrine()->getManager();
     $registration = new Registration();
     /** @var QueryBuilder $qb */
     $qb = $em->createQueryBuilder();
     $now = (new \DateTime('now'))->format('Y');
     $minYear = $now - $race->getAgeMax();
     $maxYear = $now - $race->getAgeMin();
     if (Competitor::GENDER_BOTH == $race->getGender()) {
         // mixed
         $whereGender = $qb->expr()->neq('p.gender', ':gender');
     } else {
         $whereGender = $qb->expr()->eq('p.gender', ':gender');
     }
     $whereYear = $qb->expr()->between('p.yearOfBirth', $minYear, $maxYear);
     $whereSameRace = $qb->expr()->orX();
     $whereSameRace->add($qb->expr()->neq('s.race', ':raceId'));
     $whereSameRace->add($qb->expr()->isNull('s.race'));
     $where = $qb->expr()->andX();
     $where->add($whereYear);
     $where->add($whereGender);
     $where->add($whereSameRace);
     $query = $qb->select('t')->from('AppBundle:Team', 't')->leftJoin('t.registrations', 'r')->leftJoin('r.section', 's')->join('t.members', 'tp')->join('tp.membership', 'membership')->join('membership.person', 'p')->where($where)->setParameter('gender', $race->getGender())->setParameter(':raceId', $race->getId())->addOrderBy('t.id', 'ASC')->getQuery();
     $teamResult = $query->getResult();
     $alreadyRegistered = array();
     foreach ($race->getSections() as $s) {
         /** @var RaceSection $s */
         foreach ($s->getRegistrations() as $r) {
             /** @var Registration $r */
             $alreadyRegistered[] = $r->getTeam();
         }
     }
     // filter by number of members and show only those with the correct team size
     $teams = array();
     /** @var Team $t */
     foreach ($teamResult as $t) {
         if ($t->getMembers()->count() == $race->getTeamsize()) {
             if (!in_array($t, $alreadyRegistered)) {
                 $teams[] = $t;
             }
         }
     }
     if (0 == count($teams)) {
         $this->addFlash('error', 'Keine passenden Teams gefunden, die noch hinzugefügt werden könnten!');
         return $this->redirectToRoute('race_show', array('event' => $event->getId(), 'race' => $race->getId()));
     }
     $form = $this->createForm('AppBundle\\Form\\RegistrationType', $registration, array('teams' => $teams));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         if (is_null($registration->getTeam())) {
             $this->addFlash('error', 'Kein Team angegeben!');
             return $this->redirectToRoute('race_show', array('event' => $event->getId(), 'race' => $race->getId()));
         }
         if (is_null($registration->getSection())) {
             if ($race->getSections()->count() > 0) {
                 $registration->setSection($race->getSections()->last());
             } else {
                 $raceRepo = $em->getRepository('AppBundle:Race');
                 $section = $raceRepo->createSection($race, 1);
                 $registration->setSection($section);
             }
         }
         if (is_null($registration->getLane())) {
             // find highest existing lane
             $highestLane = 0;
             /** @var Registration $r */
             foreach ($registration->getSection()->getRegistrations() as $r) {
                 if ($r->getLane() > $highestLane) {
                     $highestLane = $r->getLane();
                 }
             }
             $registration->setLane(1 + $highestLane);
         }
         $em->persist($registration);
         $em->flush();
         $this->addFlash('notice', 'Neue Meldung wurde angelegt!');
         return $this->redirectToRoute('race_show', array('event' => $event->getId(), 'race' => $race->getId()));
     }
     return $this->render('registration/new.html.twig', array('race' => $race, 'form' => $form->createView()));
 }