/** * @param FullSearchData $searchData * @return FullSearchData */ public function initSearchData(FullSearchData $searchData) { $em = $this->entityManager; $request = $this->request; $roomsTransformer = new RoomsToStringTransformer(); $servicesTransformer = new ServicesToStringTransformer($em); $brandsTransformer = new BrandsToStringTransformer($em); // Re-setting all the data in the form $searchData->searchString = $request->get('searchcriteria'); $searchData->searchString = str_replace('##-##', '/', $searchData->searchString); $searchData->datePax->startingDate = new \DateTime($request->get('startdate')); $searchData->datePax->endingDate = new \DateTime($request->get('enddate')); $searchData->accentCard = ($accentCard = $request->get('accentCard')) ? $accentCard : null; $searchData->flexible_dates = (bool) $request->get('flexible'); $searchData->budget_min = $request->get('budgetmin'); $searchData->budget_max = $request->get('budgetmax'); $searchData->radius = $request->get('radius'); if ($brands = $request->get('brands')) { $searchData->brands = $brandsTransformer->reverseTransform($brands); } if (count($searchData->getBrands()) > 1) { $this->reservitUtils->setBrandExtender(true); } $searchData->services = $servicesTransformer->reverseTransform($request->get('servicesstring')); $searchData->datePax->setPartialRooms($roomsTransformer->reverseTransform($request->get('roomsstring'))); $this->searchData = $searchData; $this->setModeFromSearchString(); return $searchData; }
public function toArray(ObjectManager $om) { $data = array(); $roomsTransformer = new RoomsToStringTransformer(); $servicesTransformer = new ServicesToStringTransformer($om); $data['searchcriteria'] = $this->searchString; $data['startdate'] = $this->datePax->startingDate->format('Y-m-d'); $data['enddate'] = $this->datePax->endingDate->format('Y-m-d'); $data['roomsstring'] = $roomsTransformer->transform($this->datePax->getSelectedRooms()); $data['accentCard'] = $this->accentCard; $data['flexible'] = $this->flexible_dates ? 1 : 0; $data['servicesstring'] = $servicesTransformer->transform($this->services); $data['budgetmin'] = $this->budget_min; $data['budgetmax'] = $this->budget_max; $data['brands'] = $this->brands; $data['radius'] = $this->radius; $data['nbAdults'] = $this->getNbAdults(); $data['nbChildren'] = $this->getNbChildren(); $data['nbRooms'] = $this->datePax->getNbRooms(); $data['geolocationLat'] = $this->geolocationLat; $data['geolocationLng'] = $this->geolocationLng; return $data; }
/** * @Route("/process", name="process_advanced_search_form") * @Method("POST") */ public function processAdvancedFormAction(Request $request) { $searchData = $this->get('seh_search_fullsearch_data'); $searchForm = $this->createForm('seh_search_fullsearch', $searchData); $session = $this->get('session'); $searchForm->submit($request); if ($searchForm->isValid()) { $searchDataSession = $this->getSearchData(); $searchString = $searchData->searchString; if ($searchData->searchMapId != '' && $searchData->comeFromSearchMap) { $session->set('searchmapId', $searchData->searchMapId); $locations = array('cities' => array(), 'departments' => array(), 'regions' => array(), 'countries' => array()); foreach (explode(',', $searchData->searchMapId) as $hotelId) { /** @var Hotel $hotel */ $hotel = $this->getRepository('SehBundle:Hotel')->find($hotelId); if ($hotel) { $locations['cities'][$hotel->getCity()->getId()] = $hotel->getCity()->getName(); if ($hotel->getDepartment()) { $locations['departments'][$hotel->getDepartment()->getId()] = $hotel->getDepartment()->getName(); } $locations['regions'][$hotel->getRegion()->getId()] = $hotel->getRegion()->getName(); $locations['countries'][$hotel->getCountry()->getId()] = $hotel->getCountry()->getName(); } } if (count($locations['cities']) == 1) { $location = array_shift($locations['cities']); $searchString = $location; } elseif (count($locations['departments']) == 1) { $location = array_shift($locations['departments']); $searchString = $location; } elseif (count($locations['regions']) == 1) { $location = array_shift($locations['regions']); $searchString = $location; } elseif (count($locations['countries']) == 1) { $location = array_shift($locations['countries']); $searchString = $location; } $session->get('search.data', $searchDataSession); } if (!$searchData->comeFromSearchMap && $searchDataSession) { $searchDataSession->setSearchMapId(''); } if ('' === $searchString) { $searchString = 'no-search-string'; } $roomsTransformer = new RoomsToStringTransformer(); $roomsAsString = $roomsTransformer->transform($searchData->datePax->getSelectedRooms()); $servicesTransformer = new ServicesToStringTransformer($this->getDoctrine()->getManager()); $servicesAsString = $servicesTransformer->transform($searchData->services); $startDate = $searchData->datePax->startingDate->format('Y-m-d'); $endDate = $searchData->datePax->endingDate->format('Y-m-d'); $parameters = array('searchcriteria' => $searchString, 'startdate' => $startDate, 'enddate' => $endDate, 'roomsstring' => $roomsAsString, 'flexible' => !$searchData->flexible_dates ? '0' : '1', 'servicesstring' => $servicesAsString); if ($searchData->accentCard) { $parameters['accentCard'] = $searchData->accentCard; } $route = 'search_form_process_full'; $brandsTransformer = new BrandsToStringTransformer($this->getDoctrine()->getManager()); $brands = $brandsTransformer->transform($searchData->brands); $parameters = array_merge($parameters, array('budgetmin' => $searchData->budget_min, 'budgetmax' => $searchData->budget_max, 'brands' => '' != $brands ? $brands : 'nobrand', 'radius' => $searchData->radius)); $parameters['searchcriteria'] = str_replace('/', '##-##', $parameters['searchcriteria']); return $this->redirect($this->generateUrl($route, $parameters)); } $session->set('form.search.errors', $this->getFormErrorsAsArray($searchForm)); return $this->redirect($this->getRequest()->headers->get('referer')); }