示例#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));
 }
示例#2
0
 /**
  * Edit Accommodation
  * @param Request $request
  * @param $id
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function editAction(Request $request, Accommodation $accommodation)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $gallery = new Gallery();
     # If user isn't owner -> 403
     if ($this->getUser()->getId() != $accommodation->getUser()->getId()) {
         return $this->redirect($this->generateUrl('user_403'));
     }
     # Units of this accommodation
     $units = $em->getRepository('AppBundle:Unit')->getUnitsAccommodation($accommodation->getId());
     $countries = $em->getRepository('AppBundle:Country')->findAll();
     $regions = $em->getRepository('AppBundle:Region')->getByCountry($accommodation->getCity()->getRegion()->getCountry()->getId());
     $subregions = $em->getRepository('AppBundle:Subregion')->getByRegion($accommodation->getCity()->getRegion()->getId());
     if ($accommodation->getCity()->getSubregion()) {
         $cities = $em->getRepository('AppBundle:City')->getBySubregion($accommodation->getCity()->getSubregion()->getId());
     } else {
         $cities = $em->getRepository('AppBundle:City')->getByRegion($accommodation->getCity()->getRegion()->getId());
     }
     // 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($request->getLocale()), $accommodation);
     $formGallery = $this->createForm(new GalleryType(), $gallery);
     $formVideo = $this->createForm(new VideoType());
     if (!is_null($request->request->get('accommodation')) && (!isset($request->request->get('accommodation')['city']) || $request->request->get('accommodation')['city'] == '')) {
         $session->getFlashBag()->add('msgError', $this->get('translator')->trans('city_should_not_be_blank'));
         return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodation->getId())));
     }
     $cityPost = $request->request->get('accommodation')['city'];
     $reqAccommodation = $request->request->get('accommodation');
     unset($reqAccommodation['city']);
     $request->request->set('accommodation', $reqAccommodation);
     $form->handleRequest($request);
     if ($form->isValid()) {
         # All POST data
         $postData = $request->request->all();
         //            echo'<pre>';
         //            exit(\Doctrine\Common\Util\Debug::dump(intval($postData['wifi'])));
         //            echo'</pre>';
         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();
         $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('edit_success'));
         return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodation->getId())));
     }
     //        echo'<pre>';
     //        exit(\Doctrine\Common\Util\Debug::dump($accommodation->getWifi()));
     //        echo'</pre>';
     return $this->render('AppBundle:Accommodation:edit.html.twig', array('form' => $form->createView(), 'formGallery' => $formGallery->createView(), 'formVideo' => $formVideo->createView(), 'accommodation' => $accommodation, 'units' => $units, 'countries' => $countries, 'regions' => $regions, 'subregions' => $subregions, 'cities' => $cities));
 }
示例#3
0
 /**
  * Accommodation
  * @param Request       $request
  * @param Accommodation $accommodation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function step3Action(Request $request, Accommodation $accommodation)
 {
     $em = $this->getDoctrine()->getManager();
     if ($accommodation->getUser() != $this->getUser()) {
         return $this->redirect($this->generateUrl('app_home'));
     }
     // 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($request->getLocale()), $accommodation)->remove('name')->remove('accommodationCategory')->remove('address')->remove('checkIn')->remove('checkOut')->remove('minimumStay')->remove('city')->remove('web')->remove('accommodationCategory')->remove('advertisingPackage')->remove('prepay')->remove('email')->remove('phone')->remove('fees');
     $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']));
         }
         $em->persist($accommodation);
         $em->flush();
         return $this->redirect($this->generateUrl('app_profile_step_4', array('id' => $accommodation->getId())));
     }
     return $this->render('AppBundle:Profile/Steps:step3.html.twig', array('form' => $form->createView(), 'accommodation' => $accommodation));
 }