function editVenueNew($slug, Request $request, Application $app)
 {
     //var_dump($_POST); die();
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Event does not exist.");
     }
     if ($this->parameters['event']->getIsDeleted()) {
         die("No");
         // TODO
     }
     $areaRepository = new AreaRepository();
     $this->parameters['shouldWeAskForArea'] = $app['currentSite']->getIsFeaturePhysicalEvents() && $areaRepository->doesCountryHaveAnyNotDeletedAreas($app['currentSite'], $this->parameters['country']);
     $this->parameters['newVenueFieldsSubmitted'] = (bool) ('POST' == $request->getMethod() && $request->request->get('newVenueFieldsSubmitted'));
     //=====================================  Set Venue Object as Much as possible from what user passed!
     $this->parameters['venue'] = new VenueModel();
     $this->parameters['venue']->setTitle('POST' == $request->getMethod() ? $request->request->get('fieldTitle') : $request->query->get('fieldTitle'));
     $this->parameters['venue']->setDescription('POST' == $request->getMethod() ? $request->request->get('fieldDescription') : $request->query->get('fieldDescription'));
     $this->parameters['venue']->setAddress('POST' == $request->getMethod() ? $request->request->get('fieldAddress') : $request->query->get('fieldAddress'));
     $this->parameters['venue']->setAddressCode('POST' == $request->getMethod() ? $request->request->get('fieldAddressCode') : $request->query->get('fieldAddressCode'));
     $this->parameters['venue']->setCountryId($this->parameters['country']->getId());
     $this->parameters['venue']->setLat('POST' == $request->getMethod() ? $request->request->get('fieldLat') : $request->query->get('fieldLat'));
     $this->parameters['venue']->setLng('POST' == $request->getMethod() ? $request->request->get('fieldLng') : $request->query->get('fieldLng'));
     $this->parameters['fieldAreaObject'] = null;
     $this->parameters['noneOfAboveSelected'] = false;
     $this->parameters['areasToSelectSearch'] = false;
     $this->parameters['areasToSelectChildren'] = false;
     if ($this->parameters['shouldWeAskForArea']) {
         // has area already been passed?
         $this->parameters['fieldAreaSearchText'] = 'POST' == $request->getMethod() ? $request->request->get('fieldAreaSearchText') : $request->query->get('fieldAreaSearchText');
         $this->parameters['fieldAreaSlug'] = 'POST' == $request->getMethod() ? $request->request->get('fieldAreaSlug') : $request->query->get('fieldAreaSlug');
         $this->parameters['fieldAreaSlugSelected'] = 'POST' == $request->getMethod() ? $request->request->get('fieldAreaSlugSelected') : null;
         // Did the user select a area from a list?
         // -1 indicates skip, must check for that
         // we must check this before we check fieldAreaSlug so that this can override fieldAreaSlug
         if ($this->parameters['fieldAreaSlugSelected']) {
             $fass = intval($this->parameters['fieldAreaSlugSelected']);
             if ($fass == -1) {
                 $this->parameters['noneOfAboveSelected'] = true;
             } elseif ($fass > 0) {
                 $this->parameters['fieldAreaObject'] = $areaRepository->loadBySlug($app['currentSite'], $fass);
             }
         }
         // Slug passed?
         // -1 indicates skip, must check for that
         if (!$this->parameters['fieldAreaObject'] && $this->parameters['fieldAreaSlug']) {
             $fas = intval($this->parameters['fieldAreaSlug']);
             if ($fas == -1) {
                 $this->parameters['noneOfAboveSelected'] = true;
             } else {
                 if ($fas > 0) {
                     $this->parameters['fieldAreaObject'] = $areaRepository->loadBySlug($app['currentSite'], $fas);
                     if ($this->parameters['fieldAreaObject']) {
                         $this->parameters['fieldArea'] = $this->parameters['fieldAreaObject']->getTitle();
                     }
                 }
             }
         }
         // Free text search string passed that only has 1 result?
         if (!$this->parameters['fieldAreaObject'] && $this->parameters['fieldAreaSearchText']) {
             $arb = new AreaRepositoryBuilder();
             $arb->setSite($app['currentSite']);
             $arb->setCountry($this->parameters['country']);
             $arb->setFreeTextSearch($this->parameters['fieldAreaSearchText']);
             $arb->setIncludeParentLevels(1);
             $this->parameters['areasToSelectSearch'] = $arb->fetchAll();
             if (count($this->parameters['areasToSelectSearch']) == 1) {
                 $this->parameters['fieldAreaObject'] = $this->parameters['areasToSelectSearch'][0];
             }
         }
     }
     //=====================================  Call out to extensions to add details
     // Slightly ackward we have to set Area ID on venue object, then when extensions have done we need to reload the area object again.
     if ($this->parameters['fieldAreaObject']) {
         $this->parameters['venue']->setAreaId($this->parameters['fieldAreaObject']->getId());
     }
     foreach ($app['extensions']->getExtensionsIncludingCore() as $extension) {
         $extension->addDetailsToVenue($this->parameters['venue']);
     }
     if ($this->parameters['venue']->getAreaId() && (!$this->parameters['fieldAreaObject'] || $this->parameters['fieldAreaObject']->getId() != $this->parameters['venue']->getAreaId())) {
         $this->parameters['fieldAreaObject'] = $areaRepository->loadById($this->parameters['venue']->getAreaId());
     }
     //===================================== User gets to add details?
     // Check newVenueFieldsSubmitted because we always show the fields to user once
     // also title is a required field.
     if (!$this->parameters['newVenueFieldsSubmitted'] || !trim($this->parameters['venue']->getTitle())) {
         return $app['twig']->render('site/event/edit.venue.new.html.twig', $this->parameters);
     }
     //===================================== Do we prompt the user for more?
     if ($this->parameters['shouldWeAskForArea']) {
         // Did user type in text we had multiple options for?
         if (!$this->parameters['fieldAreaObject'] && $this->parameters['fieldAreaSearchText'] && !$this->parameters['noneOfAboveSelected'] && count($this->parameters['areasToSelectSearch']) > 1) {
             return $app['twig']->render('site/event/edit.venue.new.area.html.twig', $this->parameters);
         }
         // Child areas?
         // -1 indicates "none of the above", so don't prompt the user again.
         if (!$this->parameters['noneOfAboveSelected']) {
             $areaRepoBuilder = new AreaRepositoryBuilder();
             $areaRepoBuilder->setSite($app['currentSite']);
             $areaRepoBuilder->setCountry($this->parameters['country']);
             $areaRepoBuilder->setIncludeDeleted(false);
             $areaRepoBuilder->setIncludeParentLevels(1);
             if ($this->parameters['fieldAreaObject']) {
                 $areaRepoBuilder->setParentArea($this->parameters['fieldAreaObject']);
             } else {
                 $areaRepoBuilder->setNoParentArea(true);
             }
             $childAreas = $areaRepoBuilder->fetchAll();
             if ($childAreas) {
                 $this->parameters['areasToSelectChildren'] = $childAreas;
                 return $app['twig']->render('site/event/edit.venue.new.area.html.twig', $this->parameters);
             }
         }
     }
     //===================================== No prompt? We can  save!
     $venueRepository = new VenueRepository();
     $venueRepository->create($this->parameters['venue'], $app['currentSite'], $app['currentUser']);
     $this->parameters['event']->setVenueId($this->parameters['venue']->getId());
     $this->parameters['event']->setAreaId(null);
     $eventRepository = new EventRepository();
     $eventRepository->edit($this->parameters['event'], $app['currentUser']);
     $repo = new EventRecurSetRepository();
     if ($repo->isEventInSetWithNotDeletedFutureEvents($this->parameters['event'])) {
         return $app->redirect("/event/" . $this->parameters['event']->getSlugforURL() . '/edit/future');
     } else {
         return $app->redirect("/event/" . $this->parameters['event']->getSlugforURL());
     }
 }
 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;
 }