protected function run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->updateBoundsCache($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 function index($siteid, Request $request, Application $app)
 {
     $sr = new SiteRepository();
     $site = $sr->loadById($siteid);
     if (!$site) {
         die("404");
     }
     $arb = new AreaRepositoryBuilder();
     $arb->setSite($site);
     $areas = $arb->fetchAll();
     return $app['twig']->render('sysadmin/arealist/index.html.twig', array('site' => $site, 'areas' => $areas));
 }
 public function listJson(Request $request, Application $app)
 {
     $arb = new AreaRepositoryBuilder();
     $arb->setSite($app['currentSite']);
     $ourRequest = new \Request($request);
     $arb->setIncludeDeleted($ourRequest->getGetOrPostBoolean('include_deleted', false));
     $out = array('areas' => array());
     foreach ($arb->fetchAll() as $area) {
         $out['areas'][] = array('slug' => $area->getSlug(), 'slugForURL' => $area->getSlugForUrl(), 'title' => $area->getTitle());
     }
     return json_encode($out);
 }
 protected function run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $arb->setLimit(0);
     // all of them
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->updateFutureEventsCache($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 protected function run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $arb->setLimit(0);
     // all of them
     $arb->setCacheNeedsBuildingOnly(true);
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->buildCacheAreaHasParent($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 protected function build()
 {
     parent::build();
     if ($this->isMapItAreaOnly) {
         $this->joins[] = " JOIN area_mapit_information ON area_mapit_information.area_id = area_information.id ";
     }
     if ($this->human) {
         $this->joins[] = "  JOIN human_in_area ON human_in_area.area_id = area_information.id AND  human_in_area.human_id = :human_id AND human_in_area.removed_at IS NULL";
         $this->params['human_id'] = $this->human->getId();
     }
     if ($this->includeAreasWithNoEventsOnly) {
         $this->joins[] = " LEFT JOIN meetyournextmp_event_in_area  ON meetyournextmp_event_in_area.area_id = area_information.id ";
         $this->joins[] = " LEFT JOIN event_information ON event_information.id = meetyournextmp_event_in_area.event_id " . "AND event_information.is_deleted = '0' AND event_information.is_cancelled ='0'";
         $this->where[] = "  event_information.id IS NULL  ";
     }
 }
 protected function build($slug, Request $request, Application $app)
 {
     global $CONFIG;
     $this->parameters = array('country' => null, 'area' => null, 'parentAreas' => array(), 'childAreas' => array(), 'venueIsDuplicateOf' => null);
     if (strpos($slug, "-")) {
         $slug = array_shift(explode("-", $slug, 2));
     }
     $vr = new VenueRepository();
     $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['venue']) {
         return false;
     }
     if ($this->parameters['venue']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['venue']->getCountryID());
     }
     if ($this->parameters['venue']->getAreaId()) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($this->parameters['venue']->getAreaId());
         if (!$this->parameters['area']) {
             return false;
         }
         $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
         while ($checkArea) {
             array_unshift($this->parameters['parentAreas'], $checkArea);
             $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
         }
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setSite($app['currentSite']);
         $areaRepoBuilder->setCountry($this->parameters['country']);
         $areaRepoBuilder->setParentArea($this->parameters['area']);
         $areaRepoBuilder->setIncludeDeleted(false);
         $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     } else {
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setSite($app['currentSite']);
         $areaRepoBuilder->setCountry($this->parameters['country']);
         $areaRepoBuilder->setNoParentArea(true);
         $areaRepoBuilder->setIncludeDeleted(false);
         $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     }
     if ($this->parameters['venue']->getIsDuplicateOfId()) {
         $this->parameters['venueIsDuplicateOf'] = $vr->loadByID($this->parameters['venue']->getIsDuplicateOfId());
     }
     $app['currentUserActions']->set("org.openacalendar", "venueHistory", true);
     $app['currentUserActions']->set("org.openacalendar", "venueEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "venueDelete", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "venueEditMedia", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted() && $CONFIG->isFileStore());
     $app['currentUserActions']->set("org.openacalendar", "venueEditPushToChildAreas", $this->parameters['childAreas'] && $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     return true;
 }
 protected function buildTree(SiteModel $site, AreaModel $parentArea = null)
 {
     $data = array('area' => $parentArea, 'children' => array());
     $areaRepoBuilder = new AreaRepositoryBuilder();
     $areaRepoBuilder->setSite($site);
     $areaRepoBuilder->setCountry($this->parameters['country']);
     if ($parentArea) {
         $areaRepoBuilder->setParentArea($parentArea);
     } else {
         $areaRepoBuilder->setNoParentArea(true);
     }
     foreach ($areaRepoBuilder->fetchAll() as $area) {
         $data['children'][] = $this->buildTree($site, $area);
     }
     return $data;
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array();
     $gr = new CountryRepository();
     // we must accept both ID and Slug. Slug is proper one to use, but some JS needs to load by ID.
     $this->parameters['country'] = intval($slug) ? $gr->loadById($slug) : $gr->loadByTwoCharCode($slug);
     if (!$this->parameters['country']) {
         return false;
     }
     // check this country is or was valid for this site
     $countryInSiteRepo = new CountryInSiteRepository();
     if (!$countryInSiteRepo->isCountryInSite($this->parameters['country'], $app['currentSite'])) {
         return false;
     }
     $areaRepoBuilder = new AreaRepositoryBuilder();
     $areaRepoBuilder->setSite($app['currentSite']);
     $areaRepoBuilder->setCountry($this->parameters['country']);
     $areaRepoBuilder->setNoParentArea(true);
     $areaRepoBuilder->setIncludeDeleted(false);
     $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     return true;
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array('country' => null, 'parentAreas' => array(), 'areaIsDuplicateOf' => null);
     if (strpos($slug, "-")) {
         $slug = array_shift(explode("-", $slug, 2));
     }
     $ar = new AreaRepository();
     $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['area']) {
         return false;
     }
     $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
     while ($checkArea) {
         array_unshift($this->parameters['parentAreas'], $checkArea);
         $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
     }
     if ($app['currentUser']) {
         $uwgr = new UserWatchesAreaRepository();
         $uwg = $uwgr->loadByUserAndArea($app['currentUser'], $this->parameters['area']);
         $this->parameters['currentUserWatchesArea'] = $uwg && $uwg->getIsWatching();
     }
     $cr = new CountryRepository();
     $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID());
     $areaRepoBuilder = new AreaRepositoryBuilder();
     $areaRepoBuilder->setSite($app['currentSite']);
     $areaRepoBuilder->setCountry($this->parameters['country']);
     $areaRepoBuilder->setParentArea($this->parameters['area']);
     $areaRepoBuilder->setIncludeDeleted(false);
     $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     if ($this->parameters['area']->getIsDuplicateOfId()) {
         $this->parameters['areaIsDuplicateOf'] = $ar->loadByID($this->parameters['area']->getIsDuplicateOfId());
     }
     $app['currentUserActions']->set("org.openacalendar", "areaHistory", true);
     $app['currentUserActions']->set("org.openacalendar", "actionAreaEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "AREAS_CHANGE") && !$this->parameters['area']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "actionAreaNew", $app['currentUserPermissions']->hasPermission("org.openacalendar", "AREAS_CHANGE") && !$this->parameters['area']->getIsDeleted());
     return true;
 }
 public function markDuplicateWithMetaData(AreaModel $duplicateArea, AreaModel $originalArea, AreaEditMetaDataModel $areaEditMetaDataModel)
 {
     global $DB;
     if ($duplicateArea->getId() == $originalArea->getId()) {
         return;
     }
     try {
         $DB->beginTransaction();
         $duplicateArea->setIsDuplicateOfId($originalArea->getId());
         $duplicateArea->setIsDeleted(true);
         $this->areaDBAccess->update($duplicateArea, array('is_duplicate_of_id', 'is_deleted'), $areaEditMetaDataModel);
         // Move Venues
         $venueDBAccess = new VenueDBAccess($DB, new \TimeSource());
         $vrb = new VenueRepositoryBuilder();
         $vrb->setArea($duplicateArea);
         $venueEditMetaData = new VenueEditMetaDataModel();
         $venueEditMetaData->setUserAccount($areaEditMetaDataModel->getUserAccount());
         foreach ($vrb->fetchAll() as $venue) {
             $venue->setAreaId($originalArea->getId());
             $venueDBAccess->update($venue, array('area_id'), $venueEditMetaData);
         }
         // Move Events
         $eventRepoBuilder = new EventRepositoryBuilder();
         $eventRepoBuilder->setArea($duplicateArea);
         $eventDBAccess = new EventDBAccess($DB, new \TimeSource());
         $eventEditMetaData = new EventEditMetaDataModel();
         $eventEditMetaData->setUserAccount($areaEditMetaDataModel->getUserAccount());
         foreach ($eventRepoBuilder->fetchAll() as $event) {
             // Check Area actually matches here because we may get events at a venue.
             // Based on the order we do things in (ie Move Venue, Move Event) we shouldn't but let's be safe.
             if ($event->getAreaId() == $duplicateArea->getId() && $event->getVenueId() == null) {
                 $event->setAreaId($originalArea->getId());
                 $eventDBAccess->update($event, array('area_id'), $eventEditMetaData);
             }
         }
         // Move Child Areas
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setParentArea($duplicateArea);
         $areaRepoBuilder->setIncludeParentLevels(0);
         $flag = false;
         foreach ($areaRepoBuilder->fetchAll() as $area) {
             // lets just double check we haven't got any child areas.
             if ($area->getParentAreaId() == $duplicateArea->getId()) {
                 $area->setParentAreaId($originalArea->getId());
                 $this->areaDBAccess->update($area, array('parent_area_id'), $areaEditMetaDataModel);
                 $flag = true;
             }
         }
         if ($flag) {
             // now must clear caches
             $this->deleteParentCacheForArea($originalArea);
             $this->deleteParentCacheForArea($duplicateArea);
         }
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 function edit($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Import does not exist.");
     }
     $form = $app['form.factory']->create(new ImportURLEditForm($app['currentSite']), $this->parameters['importurl']);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $area = null;
             $areaRepository = new AreaRepository();
             $postAreas = $request->request->get('areas');
             if (is_array($postAreas)) {
                 foreach ($postAreas as $areaCode) {
                     if (substr($areaCode, 0, 9) == 'EXISTING:') {
                         $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9));
                     }
                 }
             }
             $this->parameters['importurl']->setAreaId($area ? $area->getId() : null);
             $iRepository = new ImportURLRepository();
             $iRepository->edit($this->parameters['importurl'], $app['currentUser']);
             return $app->redirect("/importurl/" . $this->parameters['importurl']->getSlug());
         }
     }
     if ($this->parameters['country']) {
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setSite($app['currentSite']);
         $areaRepoBuilder->setCountry($this->parameters['country']);
         $areaRepoBuilder->setIncludeDeleted(false);
         if ($this->parameters['area']) {
             $areaRepoBuilder->setParentArea($this->parameters['area']);
         } else {
             $areaRepoBuilder->setNoParentArea(true);
         }
         $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('site/importurl/edit.html.twig', $this->parameters);
 }
 /**
  * @return array
  */
 public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel)
 {
     global $CONFIG;
     $out = array();
     $grb = new AreaRepositoryBuilder();
     $grb->setSite($siteModel);
     $grb->setLimit(0);
     // all! No limit
     // TODO  don't we still want to do this? How will user A get a notification if user B deletes area? but then so far most area deletetions are by admins.
     $grb->setIncludeDeleted(false);
     foreach ($grb->fetchAll() as $area) {
         $uwg = $this->loadByUserAndArea($userAccountModel, $area);
         if ($uwg && $uwg->getIsWatching()) {
             $dateSince = $uwg->getSinceDateForNotifyChecking();
             $historyRepositoryBuilder = new HistoryRepositoryBuilder();
             $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setArea($area);
             $historyRepositoryBuilder->setSince($dateSince);
             $historyRepositoryBuilder->setNotUser($userAccountModel);
             // Only admins can change tags at the moment so don't include
             $historyRepositoryBuilder->setIncludeTagHistory(false);
             $histories = $historyRepositoryBuilder->fetchAll();
             if ($histories) {
                 $content = new UserWatchesAreaNotifyContent();
                 $content->setHistories($histories);
                 $userWatchesAreaStopRepository = new UserWatchesAreaStopRepository();
                 $userWatchesAreaStop = $userWatchesAreaStopRepository->getForUserAndArea($userAccountModel, $area);
                 $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesAreaStop->getAccessKey());
                 $content->setUserAccount($userAccountModel);
                 $content->setSite($siteModel);
                 $content->setArea($area);
                 $content->setWatchedThingTitle($area->getTitle());
                 $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/history');
                 $out[] = $content;
             }
         }
     }
     return $out;
 }
 function areaEdited($id, Request $request, Application $app)
 {
     $this->build($id, $request, $app);
     $arb = new AreaRepositoryBuilder();
     $arb->setEditedByUser($this->parameters['user']);
     $this->parameters['areas'] = $arb->fetchAll();
     return $app['twig']->render('/sysadmin/user/area.edited.html.twig', $this->parameters);
 }
 function newVenue(Request $request, Application $app)
 {
     $areaRepository = new AreaRepository();
     $countryRepository = new CountryRepository();
     $venue = new VenueModel();
     $this->parameters = array('country' => null, 'parentAreas' => array(), 'area' => null, 'childAreas' => array(), 'startAreaBrowserFromScratch' => true);
     if (isset($_GET['area_id'])) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $_GET['area_id']);
         if ($this->parameters['area']) {
             $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
             while ($checkArea) {
                 array_unshift($this->parameters['parentAreas'], $checkArea);
                 $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
             }
             $cr = new CountryRepository();
             $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID());
             $venue->setCountryId($this->parameters['country']->getId());
             $areaRepoBuilder = new AreaRepositoryBuilder();
             $areaRepoBuilder->setSite($app['currentSite']);
             $areaRepoBuilder->setCountry($this->parameters['country']);
             $areaRepoBuilder->setParentArea($this->parameters['area']);
             $areaRepoBuilder->setIncludeDeleted(false);
             $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
             $this->parameters['startAreaBrowserFromScratch'] = false;
         }
     }
     $form = $app['form.factory']->create(new VenueNewForm($app['currentTimeZone'], $app), $venue);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $postAreas = $request->request->get('areas');
             if (is_array($postAreas)) {
                 $area = null;
                 foreach ($postAreas as $areaCode) {
                     if (substr($areaCode, 0, 9) == 'EXISTING:') {
                         $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9));
                     } else {
                         if (substr($areaCode, 0, 4) == 'NEW:' && $app['currentUserPermissions']->hasPermission('org.openacalendar', 'AREAS_CHANGE')) {
                             $newArea = new AreaModel();
                             $newArea->setTitle(substr($areaCode, 4));
                             $areaRepository->create($newArea, $area, $app['currentSite'], $countryRepository->loadById($venue->getCountryId()), $app['currentUser']);
                             $areaRepository->buildCacheAreaHasParent($newArea);
                             $area = $newArea;
                         }
                     }
                 }
                 if ($area) {
                     $venue->setAreaId($area->getId());
                 }
             }
             foreach ($app['extensions']->getExtensionsIncludingCore() as $extension) {
                 $extension->addDetailsToVenue($venue);
             }
             $venueEditMetaData = new VenueEditMetaDataModel();
             $venueEditMetaData->setUserAccount($app['currentUser']);
             if ($form->has('edit_comment')) {
                 $venueEditMetaData->setEditComment($form->get('edit_comment')->getData());
             }
             $venueRepository = new VenueRepository();
             $venueRepository->createWithMetaData($venue, $app['currentSite'], $venueEditMetaData);
             return $app->redirect("/venue/" . $venue->getSlug());
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('site/venuenew/new.html.twig', $this->parameters);
 }
 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 getChildAreasForArea(AreaModel $areaModel = null, $limit = 500)
 {
     $arb = new AreaRepositoryBuilder();
     $arb->setSite($this->site);
     $arb->setIncludeDeleted(false);
     if ($areaModel) {
         $arb->setParentArea($areaModel);
     } else {
         $arb->setNoParentArea(true);
     }
     $arb->setLimit($limit);
     return $arb->fetchAll();
 }