示例#1
0
 /**
  * Add new video
  * @param Request $request
  * @param Accommodation $accommodation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function videoNewAction(Request $request, Accommodation $accommodation)
 {
     $session = $request->getSession();
     if ($accommodation->getVideos()->count() >= 5) {
         $session->getFlashBag()->add('msgError', $this->get('translator')->trans('video_limit_reached'));
         if ($request->get('_route') == 'app_video_step6_new') {
             return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodation->getId())));
         } else {
             return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodation->getId())));
         }
     }
     $em = $this->getDoctrine()->getManager();
     $video = new Video();
     $form = $this->createForm(new VideoType(), $video);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $video->setAccommodation($accommodation);
         $em->persist($video);
         $em->flush();
         $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('create_success'));
         return $this->redirect($this->generateUrl('admin_accommodation_edit', array('id' => $accommodation->getId())));
     }
     $session->getFlashBag()->add('msgError', $this->get('translator')->trans('create_error'));
     return $this->redirect($this->generateUrl('admin_accommodation_edit', array('id' => $accommodation->getId())));
 }
示例#2
0
 /**
  * Booking Action
  * @param Request $request
  * @param Accommodation $accommodation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function bookingAction(Request $request, Accommodation $accommodation)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     try {
         # User
         $role = $em->getRepository('UserBundle:Role')->findOneByName('guest');
         $unit = $em->getRepository('AppBundle:Unit')->find($request->request->get('unit'));
         $checkIn = new \DateTime($request->request->get('checkIn'));
         $checkOut = new \DateTime($request->request->get('checkOut'));
         $price = $request->request->get('price');
         $bookingForm = $this->createForm(new RegistrationType(array()));
         $bookingForm->handleRequest($request);
         # Array with form fields
         $data = $bookingForm->getData();
         if (!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
             $user = new User();
             $user->setRoles($role);
             $user->setUsername($data['username']);
             $user->setName($data['name']);
             $user->setSurename($data['surename']);
             $user->setEmail($data['email']);
             $user->setPassword($data['password']);
             $user->setIsActive(0);
             $user->encryptPassword();
             # User validation
             $validator = $this->get('validator');
             $errors = $validator->validate($user);
             $errorsString = (string) $errors;
             if (count($errors) > 0) {
                 $response = array();
                 $response['error'] = $errorsString;
                 $session->getFlashBag()->add('formErrors', (string) $errorsString);
                 return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId())));
             }
         } else {
             $user = $this->getUser();
         }
         # Booking
         $booking = new Booking();
         $booking->setUnit($unit);
         $booking->setStatus(0);
         $booking->setPrice($price);
         $booking->setUser($user);
         $booking->setFromDate($checkIn);
         $booking->setToDate($checkOut);
         # Booking validation
         $validator = $this->get('validator');
         $errorsBooking = $validator->validate($booking);
         $errorsString = (string) $errorsBooking;
         if (count($errorsBooking) > 0) {
             $response = array();
             $response['error'] = $errorsString;
             $session->getFlashBag()->add('formErrors', (string) $errorsString);
             return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId())));
         }
         # Booking not allowed
         if (!$this->get('bookingService')->bookingAllowed($booking)) {
             return $this->redirect($this->generateUrl('user_403'));
         }
         $em->persist($user);
         $em->flush();
         $em->persist($booking);
         $em->flush();
         $session->getFlashBag()->add('formSuccess', $this->get('translator')->trans('booking_success'));
         $this->bookingRequestEmail($accommodation->getUser(), $booking, 'host');
         $this->bookingRequestEmail($user, $booking, 'guest');
         if ($user->getIsActive()) {
             return $this->redirect($this->generateUrl('app_profile'));
         } else {
             return $this->redirect($this->generateUrl('app_home'));
         }
     } catch (ExportException $e) {
         $session->getFlashBag()->add('formError', $e->getMessage());
         return $this->redirect($this->generateUrl('app_home'));
     }
 }
示例#3
0
 /**
  * Add unit photo
  * @param Request       $request
  * @param Accommodation $accommodation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function step6UnitGalleryAction(Request $request, Accommodation $accommodation)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $unitGallery = new UnitGallery();
     $formUnit = $this->createForm(new UnitGalleryType($accommodation->getUnits()), $unitGallery);
     $formUnit->handleRequest($request);
     if ($formUnit->isValid()) {
         $unitGallery->setFeaturedImage(0);
         $unitGallery->upload();
         $em->persist($unitGallery);
         $em->flush();
         $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('create_success'));
     } else {
         $errors = (string) $formUnit->getErrors(true, false);
         $session->getFlashBag()->add('msgSuccess', $errors);
     }
     return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodation->getId())));
 }