Exemplo n.º 1
0
 /**
  * @Route("/book/{course}", name="oktothek_academy_book_course")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function bookCourseAction(Request $request, Course $course)
 {
     $attendee = new Attendee();
     $course->addAttendee($attendee);
     $form = $this->createForm(new AttendeeType(), $attendee);
     if ($course->getCoursetype()->getPrice() <= 0) {
         $form->add('register', 'submit', ['label' => 'oktothek.register_attendee_button', 'attr' => ['class' => 'btn btn-primary']]);
     } else {
         $form->add('sofort', 'submit', ['label' => 'oktothek.book_sofort_button', 'attr' => ['class' => 'btn btn-primary']]);
         $form->add('submit', 'submit', ['label' => 'oktothek.attendee_create_button', 'attr' => ['class' => 'btn btn-default']]);
     }
     if ($request->getMethod() == "POST") {
         //sends form
         $form->handleRequest($request);
         if ($form->isValid()) {
             // die(var_dump($form->getClickedButton()));
             if ($form->has('sofort') && $form->get('sofort')->isClicked()) {
                 if ($url = $this->get('oktothek_academy')->bookCourseSOFORT($attendee, $course)) {
                     return $this->redirect($url);
                 }
                 $this->get('session')->getFlashBag()->add('error', 'oktothek.error_sofort_book_course');
             } elseif ($form->has('register') && $form->get('register')->isClicked()) {
                 $this->get('oktothek_academy')->registerCourse($attendee, $course);
                 $this->get('session')->getFlashBag()->add('success', 'oktothek.success_register_course');
                 return $this->redirect($this->generateUrl('oktothek_academy_coursetype', ['coursetype' => $course->getCoursetype()->getId()]));
             } else {
                 $this->get('oktothek_academy')->bookCourse($attendee, $course);
                 $this->get('session')->getFlashBag()->add('success', 'oktothek.success_book_course');
                 return $this->redirect($this->generateUrl('oktothek_academy_coursetype', ['coursetype' => $course->getCoursetype()->getId()]));
             }
         } else {
             $this->get('session')->getFlashBag()->add('error', 'oktothek.error_book_course');
         }
     }
     return ['form' => $form->createView(), 'course' => $course];
 }
Exemplo n.º 2
0
 /**
  * @Route("/course/{coursetype}/new", name="oktothek_backend_new_course")
  * @Template()
  */
 public function newCourseAction(Request $request, Coursetype $coursetype)
 {
     $course = new Course();
     $course->setCoursetype($coursetype);
     $form = $this->createForm(new CourseFormType(), $course);
     $form->add('submit', 'submit', ['label' => 'oktothek.course_create_button', 'attr' => ['class' => 'btn btn-primary']]);
     if ($request->getMethod() == "POST") {
         //sends form
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $em->persist($course);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', 'oktothek.success_create_course');
             return $this->redirect($this->generateUrl('oktothek_backend_courses'));
         } else {
             $this->get('session')->getFlashBag()->add('error', 'oktothek.error_create_course');
         }
     }
     return ['form' => $form->createView()];
 }