Ejemplo n.º 1
0
 /**
  * Check-in a team for this specific race.
  *
  * @Route("/team/{registration}/checkIn", name="race_start_checkin")
  * @Method({"GET", "POST"})
  * @Security("has_role('ROLE_REGISTRATION')")
  */
 public function checkInAction(Request $request, Registration $registration)
 {
     if ($registration->isCheckedIn()) {
         $this->addFlash('error', 'Starter ist bereits eingecheckt!');
         if (!is_null($request->headers->get('referer'))) {
             return $this->redirect($request->headers->get('referer'));
         } else {
             return $this->redirectToRoute('homepage');
         }
     }
     $data = array();
     $form = $this->createFormBuilder($data)->add('token', TextType::class, array('label' => 'Token'))->add('ref', HiddenType::class, array('data' => $request->headers->get('referer')))->getForm();
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         // $data is a simply array with your form fields
         // like "query" and "category" as defined above.
         $data = $form->getData();
         // check if the token exists for another competitor
         $em = $this->getDoctrine()->getManager();
         /** @var RegistrationRepository $repo */
         $repo = $em->getRepository('AppBundle:Registration');
         if ($repo->isTokenExistent($data["token"])) {
             $this->addFlash('error', 'Token ist bereits eingecheckt!');
         } else {
             // if unique, then save
             $registration->setCheckedIn($data["token"]);
             $em = $this->getDoctrine()->getManager();
             $em->persist($registration);
             $em->flush();
         }
         return $this->redirect($data['ref']);
     }
     return $this->render('race/checkin.html.twig', array('group' => $registration, 'form' => $form->createView()));
 }