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;
 }
 /**
  * Show page to modify participation (re-register for different race or de-register from this race)
  *
  * @Route("/race/{race}/change", name="registration_edit")
  * @Method("POST")
  * @Security("has_role('ROLE_REGISTRATION')")
  */
 public function editAction(Request $request, Race $race)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var \AppBundle\Repository\RaceRepository $repo */
     $repo = $em->getRepository('AppBundle:Race');
     $all_races = $repo->findAllForEvent($race->getEvent()->getId());
     $form = $this->getEditForm($all_races);
     $csrf_token = $this->getCsrfToken($form);
     $form->handleRequest($request);
     if (count($form->getErrors(true)) > 0) {
         /** @var \Psr\Log\LoggerInterface $logger */
         $logger = $this->get('logger');
         $errors = array();
         /** @var \Symfony\Component\Form\FormError $err */
         foreach ($form->getErrors(true) as $err) {
             if ('Symfony\\Component\\Validator\\ConstraintViolation' == get_class($err->getCause())) {
                 /** @var \Symfony\Component\Validator\ConstraintViolation $cause */
                 $cause = $err->getCause();
                 $logger->warning("Error while evaluating form: " . $err->getMessage() . ' ' . $cause->getPropertyPath() . ' got: ' . $cause->getInvalidValue());
             } elseif (get_class($this) == get_class($err->getCause())) {
                 $errors[] = $err->getMessage();
             }
         }
         $this->addFlash('error', 'Beim Ummelden sind Fehler aufgetreten!');
         foreach ($errors as $e) {
             $this->addFlash('error', $e);
         }
     }
     if ($form->isSubmitted() && $form->isValid()) {
         $formData = $form->getData();
         /** @var Race $newRace */
         $newRace = $formData["race"];
         /** @var integer $regId */
         $regId = (int) $formData["registration"];
         if ($newRace == $race) {
             $this->addFlash('error', 'Ummelden in das identische Rennen nicht sinnvoll!');
         } else {
             /** @var \AppBundle\Repository\RegistrationRepository $regRepo */
             $regRepo = $em->getRepository('AppBundle:Registration');
             /** @var \AppBundle\Entity\Registration $registration */
             $registration = $regRepo->find($regId);
             $regRepo->changeRace($registration, $race, $newRace);
             $this->addFlash('notice', 'Mannschaft umgemeldet!');
         }
     }
     return $this->redirectToRoute('race_show', array('event' => $race->getEvent()->getId(), 'race' => $race->getId()));
 }
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()));
 }