function test1()
 {
     $this->addCountriesToTestDB();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $grb = new VenueRepositoryBuilder();
     $grb->setFreeTextsearch('test');
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new VenueRepositoryBuilder();
     $grb->setFreeTextsearch('cats');
     $this->assertEquals(0, count($grb->fetchAll()));
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->delete($venue, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(true);
     $this->assertEquals(1, count($vrb->fetchAll()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(false);
     $this->assertEquals(0, count($vrb->fetchAll()));
 }
 protected function run()
 {
     $venueRepository = new VenueRepository();
     $vrb = new VenueRepositoryBuilder();
     $count = 0;
     foreach ($vrb->fetchAll() as $venue) {
         $venueRepository->updateFutureEventsCache($venue);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 function index(Application $app, Request $request)
 {
     $this->build(isset($_GET['country']) ? $_GET['country'] : null, isset($_GET['area']) ? $_GET['area'] : null, isset($_GET['venue']) ? $_GET['venue'] : null, $request, $app);
     $vrb = new VenueRepositoryBuilder();
     $vrb->setSite($app['currentSite']);
     $vrb->setIncludeDeleted(false);
     $vrb->setMustHaveLatLng(true);
     $venues = $vrb->fetchAll();
     $this->parameters['venues'] = $venues;
     return $app['twig']->render('site/mapPage.html.twig', $this->parameters);
 }
 public function listJson(Request $request, Application $app)
 {
     $vrb = new VenueRepositoryBuilder();
     $vrb->setSite($app['currentSite']);
     $ourRequest = new \Request($request);
     $vrb->setIncludeDeleted($ourRequest->getGetOrPostBoolean('include_deleted', false));
     $out = array('venues' => array());
     foreach ($vrb->fetchAll() as $venue) {
         $out['venues'][] = array('slug' => $venue->getSlug(), 'slugForURL' => $venue->getSlugForUrl(), 'title' => $venue->getTitle());
     }
     return json_encode($out);
 }
 function index($siteid, Request $request, Application $app)
 {
     $sr = new SiteRepository();
     $site = $sr->loadById($siteid);
     if (!$site) {
         die("404");
     }
     $vrb = new VenueRepositoryBuilder();
     $vrb->setSite($site);
     $venues = $vrb->fetchAll();
     return $app['twig']->render('sysadmin/venuelist/index.html.twig', array('site' => $site, 'venues' => $venues));
 }
 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();
     }
 }
 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;
     }
 }
 function infoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Country does not exist.");
     }
     $data = array('area' => array('slug' => $this->parameters['area']->getSlug(), 'title' => $this->parameters['area']->getTitle(), 'max_lat' => $this->parameters['area']->getCachedMaxLat(), 'max_lng' => $this->parameters['area']->getCachedMaxLng(), 'min_lat' => $this->parameters['area']->getCachedMinLat(), 'min_lng' => $this->parameters['area']->getCachedMinLng()), 'childAreas' => array(), 'venues' => array());
     foreach ($this->parameters['childAreas'] as $childArea) {
         $data['childAreas'][] = array('slug' => $childArea->getSlug(), 'title' => $childArea->getTitle(), 'max_lat' => $childArea->getCachedMaxLat(), 'max_lng' => $childArea->getCachedMaxLng(), 'min_lat' => $childArea->getCachedMinLat(), 'min_lng' => $childArea->getCachedMinLng());
     }
     if (isset($_GET['includeVenues']) && $_GET['includeVenues']) {
         $vrb = new VenueRepositoryBuilder();
         $vrb->setIncludeDeleted(false);
         $vrb->setSite($app['currentSite']);
         $vrb->setArea($this->parameters['area']);
         foreach ($vrb->fetchAll() as $venue) {
             $data['venues'][$venue->getId()] = array('slug' => $venue->getSlug(), 'title' => $venue->getTitle(), 'lat' => $venue->getLat(), 'lng' => $venue->getLng());
         }
     }
     $response = new Response(json_encode($data));
     $response->headers->set('Content-Type', 'application/json');
     $response->setPublic();
     $response->setMaxAge($app['config']->cacheFeedsInSeconds);
     return $response;
 }
 function venueEdited($id, Request $request, Application $app)
 {
     $this->build($id, $request, $app);
     $vrb = new VenueRepositoryBuilder();
     $vrb->setEditedByUser($this->parameters['user']);
     $this->parameters['venues'] = $vrb->fetchAll();
     return $app['twig']->render('/sysadmin/user/venue.edited.html.twig', $this->parameters);
 }
 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;
 }