Yaron-NL

controllerPLanning

May 13th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <?php
  2. namespace AppBundle\Controller;
  3.  
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use AppBundle\Entity\Book;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use AppBundle\Configuration;
  10.  
  11. class PlanController extends Controller
  12. {
  13.     /**
  14.      * @Route("/plan", name="planning")
  15.      */
  16.     public function indexAction(Request $request)
  17.     {
  18.         $errorMsg = ""; // error message
  19.  
  20.         $req = new book();
  21.         $req->setDate(new \DateTime());
  22. //        $entity = new Element();
  23.  
  24.          /* form create */
  25.         $form = $this->createFormBuilder($req)
  26.             ->add('date', 'date')
  27.             ->add('name', 'text', array('label' => 'Voornaam en achternaam '))
  28. //            ->add('plan', 'text', array('label' => 'Plan'))
  29.             ->add('participants', 'text', array('label' => 'Deelnemers'))
  30.             ->add('timeStart', 'time', array('label' => 'begin tijd'))
  31.             ->add('timeEnd', 'time', array('label' => 'eind tijd'))
  32.             ->add('reason', 'text', array('label' => 'reden'))
  33.             ->add('save', 'submit', array('label' => "Verzenden"))
  34.  
  35.             ->getForm();
  36.  
  37.         $form->handleRequest($request);
  38.  
  39.         /* post in database */
  40.         if ($form->isValid()) {
  41.             $em = $this->getDoctrine()->getManager();
  42.             $bookEntity = $em->getRepository("AppBundle:book")->findBy(array("date" => $req->getDate()));
  43.             $time_start = $em->getRepository("AppBundle:book")->findByName($form->get("timeStart") -> getViewData());
  44.             $time_end = $em->getRepository("AppBundle:book")->findByName($form->get("timeEnd") -> getViewData());
  45.  
  46.             if (count($bookEntity) == 0) {
  47.                 if (count($time_start) == 0){
  48.                     $em->persist($req);
  49.                     $em->flush();
  50.                     //return $this->redirectToRoute("homepage");
  51.                 }
  52.             }elseif(count($bookEntity) == 1){
  53.                // return new Response ('Er is al iets gepland');
  54.                 $errorMsg = "Er is al iets gepland";
  55.             }
  56.         }
  57.  
  58. //      $time_start = $em->getRepository("AppBundle:book")->findOneBy(array("time" => $req->getTimeStart()));
  59. //      $time_end = $em->getRepository("AppBundle:book")->findOneBy(array("timeEnd" => $req->getTimeEnd()));
  60.  
  61.         /* informatie uit de database */
  62.  
  63.         $allBook = $this->getDoctrine()
  64.             ->getRepository('AppBundle:Book')
  65.             ->findAll();
  66.  
  67.         return $this->render('default/plan.html.twig',
  68.             array(
  69.                 "form_book" => $form->createView(),
  70.                 "allBook" => $allBook,
  71.                 "errorMessage" => $errorMsg
  72.             ));
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment