Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use AppBundle\Entity\Book;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use AppBundle\Configuration;
- class PlanController extends Controller
- {
- /**
- * @Route("/plan", name="planning")
- */
- public function indexAction(Request $request)
- {
- $errorMsg = ""; // error message
- $req = new book();
- $req->setDate(new \DateTime());
- // $entity = new Element();
- /* form create */
- $form = $this->createFormBuilder($req)
- ->add('date', 'date')
- ->add('name', 'text', array('label' => 'Voornaam en achternaam '))
- // ->add('plan', 'text', array('label' => 'Plan'))
- ->add('participants', 'text', array('label' => 'Deelnemers'))
- ->add('timeStart', 'time', array('label' => 'begin tijd'))
- ->add('timeEnd', 'time', array('label' => 'eind tijd'))
- ->add('reason', 'text', array('label' => 'reden'))
- ->add('save', 'submit', array('label' => "Verzenden"))
- ->getForm();
- $form->handleRequest($request);
- /* post in database */
- if ($form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $bookEntity = $em->getRepository("AppBundle:book")->findBy(array("date" => $req->getDate()));
- $time_start = $em->getRepository("AppBundle:book")->findByName($form->get("timeStart") -> getViewData());
- $time_end = $em->getRepository("AppBundle:book")->findByName($form->get("timeEnd") -> getViewData());
- if (count($bookEntity) == 0) {
- if (count($time_start) == 0){
- $em->persist($req);
- $em->flush();
- //return $this->redirectToRoute("homepage");
- }
- }elseif(count($bookEntity) == 1){
- // return new Response ('Er is al iets gepland');
- $errorMsg = "Er is al iets gepland";
- }
- }
- // $time_start = $em->getRepository("AppBundle:book")->findOneBy(array("time" => $req->getTimeStart()));
- // $time_end = $em->getRepository("AppBundle:book")->findOneBy(array("timeEnd" => $req->getTimeEnd()));
- /* informatie uit de database */
- $allBook = $this->getDoctrine()
- ->getRepository('AppBundle:Book')
- ->findAll();
- return $this->render('default/plan.html.twig',
- array(
- "form_book" => $form->createView(),
- "allBook" => $allBook,
- "errorMessage" => $errorMsg
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment