Example #1
0
 /**
  * New Accommodation
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function newAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $accommodation = new Accommodation();
     $hosts = $em->getRepository('UserBundle:User')->getHosts();
     $countries = $em->getRepository('AppBundle:Country')->findAll();
     //        $cities = $em->getRepository('AppBundle:City')->findAll();
     if (!isset($request->request->get('accommodation')['city']) && isset($request->request->get('accommodation')['name'])) {
         $session->getFlashBag()->add('msgError', $this->get('translator')->trans('city_should_not_be_blank'));
         return $this->redirect($this->generateUrl('admin_accommodation_new'));
     }
     $cityPost = $request->request->get('accommodation')['city'];
     $reqAccommodation = $request->request->get('accommodation');
     unset($reqAccommodation['city']);
     unset($reqAccommodation['region']);
     unset($reqAccommodation['subregion']);
     $request->request->set('accommodation', $reqAccommodation);
     //            echo'<pre>';
     //            exit(\Doctrine\Common\Util\Debug::dump($request->request->get('accommodation')));
     //            echo'</pre>';
     // price for form
     if (!is_null($accommodation->getWifi())) {
         $newPrice = $this->get("currencyService")->fromEuro($accommodation->getWifi());
         $accommodation->setWifi(round($newPrice, 2));
     }
     $form = $this->createForm(new AccommodationType($hosts, $request->getLocale(), true), $accommodation);
     $form->handleRequest($request);
     if ($form->isValid()) {
         # All POST data
         $postData = $request->request->all();
         if (intval($postData['wifi']) == 0) {
             $accommodation->setWifi(null);
         } else {
             $accommodation->setWifi($this->get("currencyService")->toEuro($postData['accommodation']['wifi']));
         }
         $city = $em->getRepository('AppBundle:City')->find($cityPost);
         $accommodation->setCity($city);
         $em->persist($accommodation);
         $em->flush();
         //            $advertisingPackage = new AdvertisingPackage();
         //            $advertisingPackage->setAccommodation($accommodation);
         //            $advertisingPackage->setStatus(0);
         //
         //            $em->persist($advertisingPackage);
         //            $em->flush();
         $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('create_success'));
         return $this->redirect($this->generateUrl('admin_accommodation'));
     }
     return $this->render('AdminBundle:Accommodation:new.html.twig', array('form' => $form->createView(), 'countries' => $countries));
 }
Example #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'));
     }
 }
Example #3
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())));
 }
Example #4
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())));
 }