/**
  * Create a course subscrition
  *
  * @param User $user
  * @param Course $course
  * @return Subscription
  */
 public function subscribe($user, $course)
 {
     $subscription = new Subscription();
     $subscription->setUser($user);
     $subscription->setCourse($course);
     $em = $this->getEntityManager();
     $em->persist($subscription)->{$em}->flush();
     return $subscription;
 }
示例#2
0
 /**
  * @Route("/course/new")
  * @Template()
  */
 public function newAction()
 {
     if (!$this->get('security.context')->isGranted('ROLE_USER')) {
         //throw new AccessDeniedHttpException('Accès limité aux USERS!');
         return $this->redirect($this->generateUrl('fos_user_security_login'));
     }
     $course = new Course();
     $form = $this->createForm(new CourseType(), $course);
     $validator = $this->get('validator');
     $liste_erreurs = $validator->validate($course);
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($course);
             $address_start = $form->get('start_point')->get('address')->getData();
             $city_start = $form->get('start_point')->get('city')->getData();
             $zip_code_start = $form->get('start_point')->get('zip_code')->getData();
             $country_start = $form->get('start_point')->get('country')->getData();
             $address_end = $form->get('end_point')->get('address')->getData();
             $city_end = $form->get('end_point')->get('city')->getData();
             $zip_code_end = $form->get('end_point')->get('zip_code')->getData();
             $country_end = $form->get('end_point')->get('country')->getData();
             $start_address = new Address();
             $end_address = new Address();
             $start_address->setAddress($address_start);
             $end_address->setAddress($address_end);
             $start_address->setCity($city_start);
             $end_address->setCity($city_end);
             $start_address->setZipCode($zip_code_start);
             $end_address->setZipCode($zip_code_end);
             $start_address->setCountry($country_start);
             $end_address->setCountry($country_end);
             $em->persist($start_address);
             $em->persist($end_address);
             $map_start = new Map();
             $map_end = new Map();
             $map_start->setAddress($start_address);
             $map_start->setPriority(0);
             $map_start->setCourse($course);
             $map_end->setAddress($end_address);
             $map_end->setPriority(1);
             $map_end->setCourse($course);
             $em->persist($map_start);
             $em->persist($map_end);
             $subscription = new Subscription();
             $user = $this->container->get('security.context')->getToken()->getUser();
             $subscription->setUser($user);
             $subscription->setCourse($course);
             $em->persist($subscription);
             $em->flush();
             $this->get('session')->setFlash('notice', 'Your Course is created! & Subscription OK !');
             return $this->redirect($this->generateUrl('R4F_site_course_list'));
         }
         $this->get('session')->setFlash('error', 'Error');
     }
     return array('form' => $form->createView());
 }