Example #1
0
 public function createOrUpdate(Boat $boat, Race $race, LoggerInterface $logger)
 {
     /** @var Team $dbItem */
     $dbItem = null;
     // first try to find by ID
     if (!empty($boat->id)) {
         $dbItem = $this->findOneByDrvId($boat->id);
     }
     // if this does not help, do a fuzzy search
     if (null == $dbItem) {
         // TODO search by club + representative + name + race?
     }
     if (null != $dbItem) {
         // TODO updating
         $logger->warning("Implementation missing for updating teams in TeamRepository::createOrUpdate");
     } else {
         // create new team
         $em = $this->getEntityManager();
         $dbItem = new Team();
         /** @var \AppBundle\Entity\Club $club */
         $club = $this->getEntityManager()->getRepository('AppBundle:Club')->findOneByDrvId($boat->club_id);
         if (null == $club) {
             $message = "Found no club with DRV-ID {$boat->club_id}! No team created for " . "[{$boat->name}, {$boat->id}]";
             $logger->warning($message);
             throw new \Exception($message);
         }
         if ($race->getSections()->isEmpty()) {
             /** @var \AppBundle\Repository\RaceRepository $raceRepo */
             $raceRepo = $this->getEntityManager()->getRepository('AppBundle:Race');
             // create initial section
             $raceRepo->createSection($race, 1, $logger);
         }
         /** @var \AppBundle\Entity\RaceSection $raceSection */
         $raceSection = $race->getSections()->last();
         if (null == $raceSection) {
             $message = "Found no section for race {$race->getId()}! No team created for " . "[{$boat->name}, {$boat->id}]";
             $logger->warning($message);
             throw new \Exception($message);
         }
         // save to DB - bugfix: lane for section is always 1 (because section does not exist yet)
         $em->flush();
         $dbItem->setClub($club)->setDrvId($boat->id)->setName($boat->name);
         $em->persist($dbItem);
         /** @var \AppBundle\Repository\RegistrationRepository $regRepo */
         $regRepo = $this->getEntityManager()->getRepository('AppBundle:Registration');
         $section = new Registration();
         $section->setSection($raceSection)->setLane($regRepo->getNextLaneForSection($raceSection))->setTeam($dbItem);
         $em->persist($section);
     }
     return $dbItem;
 }
Example #2
0
 public function getNumberOfRegistrations(Race $race)
 {
     $result = 0;
     /** @var RaceSection $section */
     foreach ($race->getSections() as $section) {
         $result += $section->getValidRegistrations()->count();
     }
     return $result;
 }
 /**
  * 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()));
 }
Example #4
0
 /**
  * Remove all sections without competitors from this race.
  *
  * @Route("/race/{race}/section/clean", name="race_clean_sections")
  * @Method("POST")
  * @Security("has_role('ROLE_EVENT_ORGANIZER') or has_role('ROLE_REGISTRATION')")
  */
 public function cleanSectionsAction(Race $race)
 {
     $sectionOne = null;
     foreach ($race->getSections() as $section) {
         if (1 == $section->getNumber()) {
             $sectionOne = $section;
             break;
         }
     }
     if (is_null($sectionOne)) {
         // TODO better error message
         die("no section with number 1 found for this race!");
     }
     $em = $this->getDoctrine()->getManager();
     /** @var RaceSection $section */
     foreach ($race->getSections() as $section) {
         if (0 == $section->getValidRegistrations()->count()) {
             if (1 != $section->getNumber()) {
                 // are there some non-valids in this section?
                 if (0 < $section->getRegistrations()->count()) {
                     // move them all to section 1
                     /** @var Registration $registration */
                     foreach ($section->getRegistrations() as $registration) {
                         $registration->setSection($sectionOne);
                     }
                 }
                 //                    } else {
                 //                        // check if another section exists with
                 //                        // if so, then move them there
                 //                        // delete section one
                 //                        // make the new one to number one
                 $em->remove($section);
             }
         }
     }
     $em->flush();
     $em->refresh($race);
     $this->addFlash('notice', 'Leere Abteilungen entfernt.');
     return $this->redirectToRoute('race_show', array('event' => $race->getEvent()->getId(), 'race' => $race->getId()));
 }