/**
  * Aanmelding voor nieuwe datum
  *
  * @param string $date
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addDateFormAction($date)
 {
     $securityContext = $this->container->get('security.context');
     $date = new DateTime($date);
     $user = $securityContext->getToken()->getUser();
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('ZabutoBuurtpreventieBundle:Loopschema');
     $afgemeld = $repo->findAllInactiveForDate($date, $user);
     $usergroup = new UserGroup($this->get('database_connection'));
     $loopschema = new Loopschema();
     $loopschema->setDatum($date);
     $toelichting = new Looptoelichting();
     $loopschema->addToelichting($toelichting);
     $form = $this->createForm(new LoopschemaNieuwFormType(), $loopschema);
     $form->setData($loopschema);
     $isAdmin = false;
     if ($securityContext->isGranted('ROLE_ADMIN')) {
         $isAdmin = true;
     }
     // Aanpassing m.b.t. tijden voor loopschemas
     // Men kan zelf een tijd aangeven voor een loopschema
     // of een bestaande tijd selecteren.
     $schemas = $repo->findAllActiveForDate($date);
     $tijden = [];
     $aangemeld = [];
     foreach ($schemas as $schema) {
         $tijd = $schema->getDatum()->format('H:i');
         $actueel = $schema->getActueel();
         if ($actueel == 1 && $tijd != '00:00') {
             $loperId = $schema->getLoper()->getId();
             $tijden[] = $tijd;
             if (array_key_exists($tijd, $aangemeld)) {
                 $aangemeld[$tijd][] = $loperId;
             } else {
                 $aangemeld[$tijd] = [$loperId];
             }
         }
     }
     $toelichtingen = $em->getRepository('ZabutoBuurtpreventieBundle:Looptoelichting')->findForDate($date);
     $tijden = array_unique($tijden);
     $lopers = [];
     // Aanpassing voor de beheerder: de beheerder kan voortaan
     // zelf lopers inplannen voor een bepaalde datum.
     if ($isAdmin) {
         $groupId = $usergroup->findGroupId("Loper");
         // Genereer een lijst met lopers
         if ($groupId !== false) {
             $lopers = $usergroup->findGroupMembers($groupId);
         }
     }
     $data = array('entity' => $loopschema, 'form' => $form->createView(), 'action' => $this->generateUrl('buurtpreventie_loper_nieuwe_datum_schema_post', array('date' => $loopschema->getDatum()->format('Y-m-d'))), 'afgemeld' => $afgemeld, 'tijden' => $tijden, 'lopers' => $lopers, 'is_admin' => $isAdmin, 'aangemeld' => $aangemeld, 'toelichtingen' => $toelichtingen);
     return $this->render('ZabutoBuurtpreventieBundle:Loperschema:add-form.html.twig', $data);
 }