protected function editVenueGetDataIntoParameters(Application $app)
 {
     $this->parameters['areas'] = array();
     $this->parameters['venues'] = array();
     $this->parameters['venueSearchDone'] = false;
     if ($this->parameters['doesCountryHaveAnyNotDeletedAreas']) {
         // Area search
         if ($this->parameters['searchArea']) {
             $arb = new AreaRepositoryBuilder();
             $arb->setIncludeDeleted(false);
             $arb->setIncludeParentLevels(1);
             $arb->setSite($app['currentSite']);
             $arb->setCountry($this->parameters['country']);
             $arb->setFreeTextSearch($this->parameters['searchArea']);
             $this->parameters['areas'] = $arb->fetchAll();
             if (count($this->parameters['areas']) == 1 && !$this->parameters['searchAreaSlug']) {
                 $this->parameters['searchAreaSlug'] = $this->parameters['areas'][0]->getSlug();
                 $this->parameters['searchAreaObject'] = $this->parameters['areas'][0];
             }
             // has user selected a area and is it still in search results? If so select it.
             if (!$this->parameters['searchAreaObject'] && $this->parameters['searchAreaSlug'] && intval($this->parameters['searchAreaSlug'])) {
                 foreach ($this->parameters['areas'] as $area) {
                     if ($area->getSlug() == $this->parameters['searchAreaSlug']) {
                         $this->parameters['searchAreaObject'] = $area;
                     }
                 }
             }
         }
     }
     // If user has not added any search fields. and the event is in a area. let's search by area by default.
     if (!$this->parameters['searchFieldsSubmitted'] && !$this->parameters['searchAreaObject'] && $this->parameters['area']) {
         $this->parameters['searchAreaObject'] = $this->parameters['area'];
         $this->parameters['searchArea'] = $this->parameters['area']->getTitle();
         $this->parameters['searchAreaSlug'] = $this->parameters['area']->getSlug();
     }
     // venue search
     if ($this->parameters['searchAddressCode'] || $this->parameters['searchAddress'] || $this->parameters['searchTitle'] || $this->parameters['searchAreaObject']) {
         $vrb = new VenueRepositoryBuilder();
         $vrb->setSite($app['currentSite']);
         $vrb->setCountry($this->parameters['country']);
         $vrb->setIncludeDeleted(false);
         if ($this->parameters['searchTitle']) {
             $vrb->setFreeTextSearchTitle($this->parameters['searchTitle']);
         }
         if ($this->parameters['searchAddress']) {
             $vrb->setFreeTextSearchAddress($this->parameters['searchAddress']);
         }
         if ($this->parameters['searchAddressCode']) {
             $vrb->setFreeTextSearchAddressCode($this->parameters['searchAddressCode']);
         }
         if ($this->parameters['searchAreaObject']) {
             $vrb->setArea($this->parameters['searchAreaObject']);
         }
         $this->parameters['venues'] = $vrb->fetchAll();
         $this->parameters['venueSearchDone'] = true;
     }
 }
 protected function getVenueSearchData()
 {
     $out = array('searchFieldsSubmitted' => $this->request->request->get('action') == 'searchVenues', 'searchTitle' => $this->request->request->get('searchTitle'), 'searchAddress' => $this->request->request->get('searchAddress'), 'searchArea' => $this->request->request->get('searchArea'), 'searchAreaSlug' => $this->request->request->get('searchAreaSlug'), 'searchAddressCode' => $this->request->request->get('searchAddressCode'), 'searchAreaObject' => null, 'venues' => array(), 'areas' => array(), 'venueSearchDone' => false);
     $countryRepository = new CountryRepository();
     $out['country'] = $countryRepository->loadById($this->draftEvent->getDetailsValue('event.country_id'));
     $areaRepository = new AreaRepository();
     $out['doesCountryHaveAnyNotDeletedAreas'] = $areaRepository->doesCountryHaveAnyNotDeletedAreas($this->site, $out['country']);
     if ($out['doesCountryHaveAnyNotDeletedAreas']) {
         // Area search
         if ($out['searchArea']) {
             $arb = new AreaRepositoryBuilder();
             $arb->setIncludeDeleted(false);
             $arb->setIncludeParentLevels(1);
             $arb->setSite($this->site);
             $arb->setCountry($out['country']);
             $arb->setFreeTextSearch($out['searchArea']);
             $out['areas'] = $arb->fetchAll();
             if (count($out['areas']) == 1 && !$out['searchAreaSlug']) {
                 $out['searchAreaSlug'] = $out['areas'][0]->getSlug();
                 $out['searchAreaObject'] = $out['areas'][0];
             }
             // has user selected a area and is it still in search results? If so select it.
             if (!$out['searchAreaObject'] && $out['searchAreaSlug'] && intval($out['searchAreaSlug'])) {
                 foreach ($out['areas'] as $area) {
                     if ($area->getSlug() == $out['searchAreaSlug']) {
                         $out['searchAreaObject'] = $area;
                     }
                 }
             }
         }
     }
     // If user has not added any search fields. and the event is in a area. let's search by area by default.
     if (!$out['searchFieldsSubmitted'] && !$out['searchAreaObject'] && $this->draftEvent->getDetailsValue('incoming.area.id')) {
         $areaRepository = new AreaRepository();
         $area = $areaRepository->loadById($this->draftEvent->getDetailsValue('incoming.area.id'));
         if ($area) {
             $out['searchAreaObject'] = $area;
             $out['searchArea'] = $area->getTitle();
             $out['searchAreaSlug'] = $area->getSlug();
         }
     }
     if ($out['searchAddressCode'] || $out['searchAddress'] || $out['searchTitle'] || $out['searchAreaObject']) {
         $vrb = new VenueRepositoryBuilder();
         $vrb->setSite($this->site);
         $vrb->setCountry($out['country']);
         $vrb->setIncludeDeleted(false);
         if ($out['searchTitle']) {
             $vrb->setFreeTextSearchTitle($out['searchTitle']);
         }
         if ($out['searchAddress']) {
             $vrb->setFreeTextSearchAddress($out['searchAddress']);
         }
         if ($out['searchAddressCode']) {
             $vrb->setFreeTextSearchAddressCode($out['searchAddressCode']);
         }
         if ($out['searchAreaObject']) {
             $vrb->setArea($out['searchAreaObject']);
         }
         $vrb->setLimit(500);
         $out['venues'] = $vrb->fetchAll();
         $out['venueSearchDone'] = true;
     }
     return $out;
 }