public function setFromAppAndEventAndEmail(Application $app, EventModel $eventModel, $email) { $this->event_id = $eventModel->getId(); $this->email = $email; $this->subject = "Can we check the details of your event?"; $venueRepo = new VenueRepository(); $venue = null; if ($eventModel->getVenueId()) { $venue = $venueRepo->loadById($eventModel->getVenueId()); } $area = null; $areaRepo = new AreaRepository(); if ($eventModel->getAreaId()) { $area = $areaRepo->loadById($eventModel->getAreaId()); } else { if ($venue && $venue->getAreaId()) { $area = $areaRepo->loadById($venue->getAreaId()); } } $hrb = new HumanRepositoryBuilder(); $hrb->setHumansForEvent($eventModel); $hrb->setIncludeDeleted(false); $humans = $hrb->fetchAll(); $this->body_html = $app['twig']->render('email/organiserEmail.html.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans)); if ($app['config']->isDebug) { file_put_contents('/tmp/organiserEmail.html', $this->body_html); } $this->body_text = $app['twig']->render('email/organiserEmail.txt.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans)); if ($app['config']->isDebug) { file_put_contents('/tmp/organiserEmail.txt', $this->body_text); } $this->created_at = $app['timesource']->getDateTime(); }
protected function build($slug, Request $request, Application $app) { $this->parameters = array('country' => null, 'area' => null, 'parentAreas' => array()); $iurlRepository = new ImportURLRepository(); $this->parameters['importurl'] = $iurlRepository->loadBySlug($app['currentSite'], $slug); if (!$this->parameters['importurl']) { return false; } if ($this->parameters['importurl']->getCountryID()) { $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadById($this->parameters['importurl']->getCountryID()); } if ($this->parameters['importurl']->getGroupId()) { $gr = new GroupRepository(); $this->parameters['group'] = $gr->loadById($this->parameters['importurl']->getGroupId()); } if ($this->parameters['importurl']->getAreaId()) { $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadById($this->parameters['importurl']->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; } } $app['currentUserActions']->set("org.openacalendar", "importURLLog", true); $app['currentUserActions']->set("org.openacalendar", "importURLEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter()); $app['currentUserActions']->set("org.openacalendar", "importURLDisable", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter() && $this->parameters['importurl']->getIsEnabled()); $app['currentUserActions']->set("org.openacalendar", "importURLEnable", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter() && (!$this->parameters['importurl']->getIsEnabled() || $this->parameters['importurl']->getIsExpired())); return true; }
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; }
function test1() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $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($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); ### No areas $this->assertFalse($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area 1 $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area); $this->checkAreaInTest1($areaRepo->loadById($area->getId())); $this->checkAreaInTest1($areaRepo->loadBySlug($site, $area->getSlug())); // no parents. Cache should be empty. $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent"); $stat->execute(); $this->assertEquals(0, $stat->rowCount()); $this->assertTrue($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area child $areaChild = new AreaModel(); $areaChild->setTitle("test child"); $areaChild->setDescription("test test child"); $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($areaChild); // calling this multiple times should not crash $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $this->checkChildAreaInTest1($areaRepo->loadById($areaChild->getId())); $this->checkChildAreaInTest1($areaRepo->loadBySlug($site, $areaChild->getSlug())); // Check Cache $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent WHERE area_id=" . $areaChild->getId() . " AND has_parent_area_id=" . $area->getId()); $stat->execute(); $this->assertEquals(1, $stat->rowCount()); }
function testIntegration1() { $this->addCountriesToTestDB(); \TimeSource::mock(2014, 1, 1, 12, 0, 0); $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'); ## Create area \TimeSource::mock(2014, 1, 1, 13, 0, 0); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $area->setCountryId($gb->getId()); $areaRepo = new AreaRepository(); $areaRepo->create($area, null, $site, $gb, $user); ## Edit area \TimeSource::mock(2014, 1, 1, 14, 0, 0); $area = $areaRepo->loadById($area->getId()); $area->setDescription("testy"); $areaRepo->edit($area, $user); ## Now save changed flags on these ..... $areaHistoryRepo = new AreaHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM area_history"); $stat->execute(); while ($data = $stat->fetch()) { $areaHistory = new AreaHistoryModel(); $areaHistory->setFromDataBaseRow($data); $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory); } ## Now load and check $historyRepo = new HistoryRepositoryBuilder(); $historyRepo->setIncludeEventHistory(false); $historyRepo->setIncludeVenueHistory(false); $historyRepo->setIncludeGroupHistory(false); $historyRepo->setIncludeAreaHistory(true); $histories = $historyRepo->fetchAll(); $this->assertEquals(2, count($histories)); #the edit $this->assertEquals(FALSE, $histories[0]->getTitleChanged()); $this->assertEquals(true, $histories[0]->getDescriptionChanged()); $this->assertEquals(false, $histories[0]->getCountryIdChanged()); $this->assertEquals(false, $histories[0]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[0]->getIsDeletedChanged()); #the create $this->assertEquals(true, $histories[1]->getTitleChanged()); $this->assertEquals(true, $histories[1]->getDescriptionChanged()); $this->assertEquals(true, $histories[1]->getCountryIdChanged()); $this->assertEquals(false, $histories[1]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[1]->getIsDeletedChanged()); }
protected function build($slug, Request $request, Application $app) { $this->parameters = array('groups' => array(), 'country' => null, 'venue' => null, 'area' => null); if (strpos($slug, "-") > 0) { $slugBits = explode("-", $slug, 2); $slug = $slugBits[0]; } $eventRepository = new EventRepository(); $this->parameters['event'] = $eventRepository->loadBySlug($app['currentSite'], $slug); if (!$this->parameters['event']) { return false; } if ($this->parameters['event']->getGroupId()) { $grb = new GroupRepositoryBuilder(); $grb->setEvent($this->parameters['event']); $this->parameters['groups'] = $grb->fetchAll(); } if ($this->parameters['event']->getVenueID()) { $vr = new VenueRepository(); $this->parameters['venue'] = $vr->loadById($this->parameters['event']->getVenueID()); } if ($this->parameters['event']->getAreaID()) { $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadById($this->parameters['event']->getAreaID()); } elseif ($this->parameters['venue'] && $this->parameters['venue']->getAreaId()) { $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadById($this->parameters['venue']->getAreaID()); } if ($this->parameters['event']->getCountryID()) { $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID()); } return true; }
function test1() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); \TimeSource::mock(2014, 10, 1, 1, 0, 0); $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($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaDuplicate = new AreaModel(); $areaDuplicate->setTitle("test Duplicate"); $areaRepo->create($areaDuplicate, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); \TimeSource::mock(2014, 10, 1, 2, 0, 0); $areaRepo->markDuplicate($areaDuplicate, $area, $user); $areaChild = new AreaModel(); $areaChild->setTitle("test Child"); $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $event = new EventModel(); $event->setSummary("test"); $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London')); $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London')); $event->setAreaId($area->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); ## Test $this->assertNotNull($areaRepo->loadById($area->getId())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area->getId(), $event->getAreaId()); ## Now Purge! $areaRepo->purge($area); ## Test $this->assertNull($areaRepo->loadById($area->getId())); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertNull($event->getAreaId()); }
protected function build($siteid, $slug, Request $request, Application $app) { $this->parameters = array('area' => null, 'parentarea' => null); $sr = new SiteRepository(); $this->parameters['site'] = $sr->loadById($siteid); if (!$this->parameters['site']) { $app->abort(404); } $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadBySlug($this->parameters['site'], $slug); if (!$this->parameters['area']) { $app->abort(404); } $this->parameters['areaisduplicateof'] = $this->parameters['area']->getIsDuplicateOfId() ? $ar->loadById($this->parameters['area']->getIsDuplicateOfId()) : null; if ($this->parameters['area']->getParentAreaId()) { $this->parameters['parentarea'] = $ar->loadById($this->parameters['area']->getParentAreaId()); } $cr = new CountryRepository(); $this->parameters['country'] = $this->parameters['area']->getCountryId() ? $cr->loadById($this->parameters['area']->getCountryId()) : null; }
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; }
protected function build($slug, Request $request, Application $app) { $this->parameters = array(); if (strpos($slug, "-") > 0) { $slugBits = explode("-", $slug, 2); $slug = $slugBits[0]; } $ampir = new AreaMapItInfoRepository(); $this->parameters['areaMapItInfo'] = $ampir->getByMapItID($slug); if (!$this->parameters['areaMapItInfo']) { return false; } $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadById($this->parameters['areaMapItInfo']->getAreaId()); if (!$this->parameters['area']) { return false; } return true; }
function __construct(ImportURLModel $importURL, SiteModel $site = null) { $this->importURL = $importURL; $this->realurl = $importURL->getUrl(); if ($site) { $this->site = $site; } else { $siteRepo = new SiteRepository(); $this->site = $siteRepo->loadById($importURL->getSiteId()); } if ($importURL->getCountryId()) { $countryRepo = new CountryRepository(); $this->country = $countryRepo->loadById($importURL->getCountryId()); } if ($importURL->getAreaId()) { $areaRepo = new AreaRepository(); $this->area = $areaRepo->loadById($importURL->getAreaId()); } $groupRepository = new GroupRepository(); $this->group = $groupRepository->loadById($importURL->getGroupId()); }
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; }
$end->sub(new \DateInterval('PT1S')); } else { if ($thisconfig->hasValue("Days")) { // Options for setting end; by a number of days $end->add(new \DateInterval('P' . $thisconfig->get("Days") . 'D')); } else { // Options for setting end; default to 30 days $end->add(new \DateInterval('P30D')); } } $calendar->setStartAndEnd($start, $end); // ######################################################### Filters? $area = null; if ($thisconfig->hasValue('AreaID')) { $repo = new repositories\AreaRepository(); $area = $repo->loadById($thisconfig->get('AreaID')); if ($area) { $calendar->getEventRepositoryBuilder()->setArea($area); } else { die("Area not loaded!\n"); } } // ######################################################### Get Data $calendar->getEventRepositoryBuilder()->setIncludeAreaInformation(true); $calData = $calendar->getData(); $childAreas = array(); if ($thisconfig->getBoolean('ListChildAreas', false)) { $areaRepoBuilder = new \repositories\builders\AreaRepositoryBuilder(); $areaRepoBuilder->setSite($site); $areaRepoBuilder->setIncludeDeleted(false); if ($area) {
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()); } }
public function getAreaForPostCode(PostcodeParser $postcodeParser) { global $CONFIG; if ($postcodeParser->isValid()) { $memcachedConnection = null; $areaRepo = new AreaRepository(); if ($CONFIG->memcachedServer) { $memcachedConnection = new \Memcached(); $memcachedConnection->addServer($CONFIG->memcachedServer, $CONFIG->memcachedPort); $url = $memcachedConnection->get($postcodeParser->getCanonical()); if ($url) { $urlBits = explode("/", $url); $urlBitsBits = explode("-", $urlBits[2]); $area = $areaRepo->loadBySlug($this->app['currentSite'], $urlBitsBits[0]); if ($area) { return $area; } } } $url = "http://mapit.mysociety.org/postcode/" . urlencode($postcodeParser->getCanonical()); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Meet Your Next MP'); $data = curl_exec($ch); $response = curl_getinfo($ch); curl_close($ch); if ($response['http_code'] != 200) { return; } $dataObj = json_decode($data); $mapItId = $dataObj->shortcuts->WMC; if (!$mapItId) { return; } $repo = new AreaMapItInfoRepository(); $areaMapIdInfo = $repo->getByMapItID($mapItId); if (!$areaMapIdInfo) { return; } $area = $areaRepo->loadById($areaMapIdInfo->getAreaId()); if (!$area) { return; } if ($memcachedConnection) { $memcachedConnection->set($postcodeParser->getCanonical(), '/area/' . $area->getSlugForUrl(), 60 * 60 * 24 * 30); } return $area; } }
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 newArea($countryslug, Request $request, Application $app) { if (!$this->build($countryslug, $request, $app)) { $app->abort(404, "country does not exist."); } $areaRepository = new AreaRepository(); $parentArea = null; $parentAreas = array(); if (isset($_GET['parentAreaSlug'])) { $parentArea = $areaRepository->loadBySlugAndCountry($app['currentSite'], $_GET['parentAreaSlug'], $this->parameters['country']); // build parent tree, including this area $checkArea = $parentArea; while ($checkArea) { array_unshift($parentAreas, $checkArea); $checkArea = $checkArea->getParentAreaId() ? $areaRepository->loadById($checkArea->getParentAreaId()) : null; } } $area = new AreaModel(); $form = $parentArea ? $app['form.factory']->create(new AreaNewInAreaForm(), $area) : $app['form.factory']->create(new AreaNewInCountryForm(), $area); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $areaRepository->create($area, $parentArea, $app['currentSite'], $this->parameters['country'], $app['currentUser']); $areaRepository->buildCacheAreaHasParent($area); return $app->redirect("/admin/areas/" . $this->parameters['country']->getTwoCharCode()); } } $this->parameters['parentAreas'] = $parentAreas; $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/adminareas/newarea.html.twig', $this->parameters); }
protected function findAreaForLinkToSeat(Request $request, Application $app) { $repo = new AreaMapItInfoRepository(); $areaRepo = new AreaRepository(); if ($request->query->has("mapitid")) { $areaInfo = $repo->getByMapItID($request->query->get("mapitid")); if ($areaInfo) { $area = $areaRepo->loadById($areaInfo->getAreaId()); if ($area) { return $area; } } } if ($request->query->has("gssid")) { $areaInfo = $repo->getByCodeGSS($request->query->get("gssid")); if ($areaInfo) { $area = $areaRepo->loadById($areaInfo->getAreaId()); if ($area) { return $area; } } } if ($request->query->has("title")) { $areaInfo = $repo->getByName($request->query->get("title")); if ($areaInfo) { $area = $areaRepo->loadById($areaInfo->getAreaId()); if ($area) { return $area; } } } }
function test1() { \TimeSource::mock(2014, 1, 1, 0, 0, 0); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $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($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); $area1 = new AreaModel(); $area1->setTitle("test"); $area1->setDescription("test test"); $area2 = new AreaModel(); $area2->setTitle("test this looks similar"); $area2->setDescription("test test"); $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaChild = new AreaModel(); $areaChild->setTitle("child"); $areaChild->setDescription("child"); $areaRepo->create($areaChild, $area2, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $area1 = $areaRepo->loadById($area1->getId()); $area2 = $areaRepo->loadById($area2->getId()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); $venue->setAreaId($area2->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); $event = new EventModel(); $event->setSummary("test"); $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0)); $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0)); $event->setAreaId($area2->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); // Test before $venue = $venueRepo->loadById($venue->getId()); $this->assertEquals($area2->getId(), $venue->getAreaId()); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area2->getId(), $event->getAreaId()); $areaChild = $areaRepo->loadById($areaChild->getId()); $this->assertEquals($area2->getId(), $areaChild->getParentAreaId()); $area2 = $areaRepo->loadById($area2->getId()); $this->assertFalse($area2->getIsDeleted()); $this->assertNull($area2->getIsDuplicateOfId()); // Mark \TimeSource::mock(2014, 1, 1, 2, 0, 0); $areaRepo->markDuplicate($area2, $area1, $user); // Test Duplicate $venue = $venueRepo->loadById($venue->getId()); $this->assertEquals($area1->getId(), $venue->getAreaId()); $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($area1->getId(), $event->getAreaId()); $areaChild = $areaRepo->loadById($areaChild->getId()); $this->assertEquals($area1->getId(), $areaChild->getParentAreaId()); $area2 = $areaRepo->loadById($area2->getId()); $this->assertTrue($area2->getIsDeleted()); $this->assertEquals($area1->getId(), $area2->getIsDuplicateOfId()); }
protected function run() { $this->localTimeZone = new \DateTimeZone("Europe/London"); $siteRepo = new \repositories\SiteRepository(); $site = $siteRepo->loadById($this->app['config']->singleSiteID); // TODO assumes single site! $areaRepository = new AreaRepository(); $venueRepository = new VenueRepository(); $countryRepository = new CountryRepository(); $countries = array(); $humanPopItRepository = new HumanPopItInfoRepository(); $areaMapItRepo = new AreaMapItInfoRepository(); $out = array('data' => array(), 'areasPastEvents' => array()); $erb = new EventRepositoryBuilder(); $erb->setSite($site); $erb->setIncludeDeleted(true); $erb->setIncludeCancelled(true); $erb->setAfterNow(); foreach ($erb->fetchAll() as $event) { $venue = null; $country = null; $area = null; $humans = array(); if ($event->getCountryId()) { if (!isset($countries[$event->getCountryId()])) { $countries[$event->getCountryId()] = $countryRepository->loadById($event->getCountryId()); } $country = $countries[$event->getCountryId()]; } if ($event->getVenueId()) { $venue = $venueRepository->loadById($event->getVenueId()); } if ($event->getAreaId()) { $area = $areaRepository->loadById($event->getAreaId()); } else { if ($venue && $venue->getAreaId()) { $area = $areaRepository->loadById($venue->getAreaId()); } } $thisOut = $this->addEvent($event, $venue, $area, $country); $thisOut['humans'] = array(); $mapitids = array(); if ($area) { $areamapit = $areaMapItRepo->getByAreaID($area->getId()); if ($areamapit) { $mapitids[] = $areamapit->getMapitId(); } } $hrb = new HumanRepositoryBuilder(); $hrb->setHumansForEvent($event); foreach ($hrb->fetchAll() as $human) { $popit = $humanPopItRepository->getByHumanID($human->getId()); $thisOut['humans'][] = array('popit_id' => $popit->getPopitId()); $arb = new AreaRepositoryBuilder(); $arb->setIncludeDeleted(false); $arb->setHuman($human); foreach ($arb->fetchAll() as $areaForHuman) { if (!$area || $area->getId() != $areaForHuman->getId()) { $areamapit = $areaMapItRepo->getByAreaID($areaForHuman->getId()); if ($areamapit) { $mapitids[] = $areamapit->getMapitId(); } } } } $thisOut['mapitids'] = array_values(array_unique($mapitids)); $out['data'][] = $thisOut; } $arb = new \com\meetyournextmp\repositories\builders\AreaRepositoryBuilder(); $arb->setLimit(1000); $arb->setIncludeDeleted(false); $arb->setIsMapItAreaOnly(true); foreach ($arb->fetchAll() as $area) { $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setArea($area); $erb->setBeforeNow(); $areamapit = $areaMapItRepo->getByAreaID($area->getId()); $out['areasPastEvents'][$areamapit->getMapitId()] = $erb->fetchCount(); } file_put_contents(APP_ROOT_DIR . DIRECTORY_SEPARATOR . 'webSingleSite' . DIRECTORY_SEPARATOR . 'datadump' . DIRECTORY_SEPARATOR . 'ynmpread.json', json_encode($out)); return array('result' => 'ok'); }