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 newEvent(Request $request, Application $app) { /////////////////////////////////////////////////////// Set up incoming vars $newEventDraft = new NewEventDraftModel(); $newEventDraft->setSiteId($app['currentSite']->getId()); $newEventDraft->setUserAccountId($app['currentUser'] ? $app['currentUser']->getId() : null); $incomingData = array(); // check for incoming date if (isset($_GET['date']) && trim($_GET['date'])) { $bits = explode("-", $_GET['date']); if (count($bits) == 3 && intval($bits[0]) && intval($bits[1]) && intval($bits[2])) { $incomingData['event.start_at'] = \TimeSource::getDateTime(); $incomingData['event.start_at']->setTimezone(new \DateTimeZone($app['currentTimeZone'])); $incomingData['event.start_at']->setDate($bits[0], $bits[1], $bits[2]); $incomingData['event.start_at']->setTime(9, 0, 0); $incomingData['event.end_at'] = clone $incomingData['event.start_at']; $incomingData['event.end_at']->setTime(17, 0, 0); } } // check for incoming area if (isset($_GET['area']) && trim($_GET['area'])) { $ar = new AreaRepository(); $area = $ar->loadBySlug($app['currentSite'], $request->query->get('area')); if ($area) { $incomingData['area.id'] = $area->getId(); $incomingData['area.title'] = $area->getTitle(); } } // check for incoming group if (isset($_GET['group']) && trim($_GET['group'])) { $gr = new GroupRepository(); $group = $gr->loadBySlug($app['currentSite'], $request->query->get('group')); if ($group) { $newEventDraft->setDetailsValue('group.id', $group->getId()); $newEventDraft->setDetailsValue('group.title', $group->getTitle()); } } /////////////////////////////////////////////////////// Check Permissions and Prompt IF NEEDED if (!$app['currentUser'] && !$app['currentUserActions']->has("org.openacalendar", "eventNew") && $app['anyVerifiedUserActions']->has("org.openacalendar", "eventNew")) { return $app['twig']->render('site/eventnew/new.useraccountneeded.html.twig', array('incomingData' => $incomingData)); } if (!$app['currentUser']) { $app->abort(403, "Not allowed"); } /////////////////////////////////////////////////////// Set up draft and start! foreach ($incomingData as $k => $v) { $newEventDraft->setDetailsValue('incoming.' . $k, $v); } $repo = new NewEventDraftRepository(); $repo->create($newEventDraft); $steps = $this->getSteps($request, $app, $newEventDraft); $firstStepIdx = 0; // The first step is WHO but if group is already set we already know, and we want to jump straight to the next step! $steps[0]->processIsAllInformationGathered(); if ($steps[0]->getIsAllInformationGathered()) { $firstStepIdx = 1; } return $app->redirect('/event/new/' . $newEventDraft->getSlug() . "/" . $steps[$firstStepIdx]->getStepID()); }
protected function build($slug, Request $request, Application $app) { $repo = new AreaRepository(); $this->area = $repo->loadBySlug($app['currentSite'], $slug); if (!$this->area) { return false; } return true; }
function index($siteid, $slug, Request $request, Application $app) { global $CONFIG; $this->build($siteid, $slug, $request, $app); $form = $app['form.factory']->create(new ActionForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $action = new ActionParser($data['action']); if ($action->getCommand() == 'delete' && !$this->parameters['area']->getIsDeleted()) { $ar = new AreaRepository(); $ar->delete($this->parameters['area'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/area/' . $this->parameters['area']->getSlug()); } else { if ($action->getCommand() == 'undelete' && $this->parameters['area']->getIsDeleted()) { $this->parameters['area']->setIsDeleted(false); $ar = new AreaRepository(); $ar->undelete($this->parameters['area'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/area/' . $this->parameters['area']->getSlug()); } else { if ($action->getCommand() == 'parentarea') { $ar = new AreaRepository(); $newparentarea = $ar->loadBySlug($this->parameters['site'], $action->getParam(0)); if ($newparentarea) { // TODO make sure they aren't doing something dumb like moving under themselves or making a loop $this->parameters['area']->setParentAreaId($newparentarea->getId()); $ar->editParentArea($this->parameters['area'], $app['currentUser']); } return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/area/' . $this->parameters['area']->getSlug()); } else { if ($action->getCommand() == 'isduplicateof') { $ar = new AreaRepository(); $originalArea = $ar->loadBySlug($this->parameters['site'], $action->getParam(0)); if ($originalArea && $originalArea->getId() != $this->parameters['area']->getId()) { $ar->markDuplicate($this->parameters['area'], $originalArea, $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/area/' . $this->parameters['area']->getSlug()); } } else { if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeAreaPassword && $CONFIG->sysAdminExtraPurgeAreaPassword == $action->getParam(0)) { $ar = new AreaRepository(); $ar->purge($this->parameters['area']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/area/'); } } } } } } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('sysadmin/area/index.html.twig', $this->parameters); }
protected function build($slug, Request $request, Application $app) { global $CONFIG; $this->parameters = array(); if (strpos($slug, "-")) { $slug = array_shift(explode("-", $slug, 2)); } $areaRepository = new AreaRepository(); $this->parameters['area'] = $areaRepository->loadBySlug($app['currentSite'], $slug); if (!$this->parameters['area']) { return false; } return true; }
protected function build($slug, Request $request, Application $app) { $this->parameters = array(); if (strpos($slug, "-") > 0) { $slugBits = explode("-", $slug, 2); $slug = $slugBits[0]; } $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $slug); if (!$this->parameters['area']) { return false; } return true; }
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; } }
protected function build($countryCode, $areaSlug, $venueSlug, Request $request, Application $app) { $this->parameters = array('country' => null, 'area' => null, 'venue' => null); if ($areaSlug) { $ar = new AreaRepository(); $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $areaSlug); } if ($this->parameters['area']) { $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID()); } else { if ($countryCode) { $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadByTwoCharCode($countryCode); } } if ($venueSlug) { $vr = new VenueRepository(); $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $venueSlug); } 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; }
function moveToArea($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Venue does not exist."); } if ($request->request->get('area') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { if (intval($request->request->get('area'))) { $areaRepository = new AreaRepository(); $area = $areaRepository->loadBySlug($app['currentSite'], $request->request->get('area')); if ($area && (!$this->parameters['area'] || $area->getId() != $this->parameters['area']->getId())) { $this->parameters['venue']->setAreaId($area->getId()); $venueRepository = new VenueRepository(); $venueRepository->edit($this->parameters['venue'], $app['currentUser']); $app['flashmessages']->addMessage('Thank you; venue updated!'); } } } return $app->redirect("/venue/" . $this->parameters['venue']->getSlugForURL() . '/'); }
protected function run() { $siteRepo = new \repositories\SiteRepository(); $site = $siteRepo->loadById($this->app['config']->singleSiteID); // TODO assumes single site! $out = array(); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $out['countEventsTotal'] = count($erb->fetchAll()); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setBefore($this->app['timesource']->getDateTime()); $out['countEventsBeforeNow'] = count($erb->fetchAll()); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setAfterNow(); $out['countEventsAfterNow'] = count($erb->fetchAll()); $arb = new \com\meetyournextmp\repositories\builders\AreaRepositoryBuilder(); $arb->setIsMapItAreaOnly(true); $arb->setIncludeDeleted(false); $arb->setIncludeAreasWithNoEventsOnly(true); $arb->setLimit(800); $out['countSeatsWithNoEvents'] = count($arb->fetchAll()); $areaRepo = new AreaRepository(); foreach (array(3 => 'countEventsInScotland', 1 => 'countEventsInEngland', 2 => 'countEventsInWales', 4 => 'countEventsInNIreland', 712 => 'countEventsInGreaterLondon') as $areaSlug => $key) { $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setArea($areaRepo->loadBySlug($site, $areaSlug)); $out[$key] = count($erb->fetchAll()); } // =================================== Events by day $report = $this->getValueReport('com.meetyournextmp', 'NonDeletedNonCancelledEventsStartAtReport', $this->app); $startAt = \TimeSource::getDateTime(); $startAt->setTime(0, 0, 0); $endAt = new \DateTime('2015-05-07 10:00:00'); $period = "P1D"; $report->setFilterSiteId($this->app['config']->singleSiteID); $reportByTime = new SeriesOfValueByTimeReport($report, $startAt, $endAt, $period); $reportByTime->run(); $out['countEventsByDay'] = array(); foreach ($reportByTime->getData() as $data) { $out['countEventsByDay'][] = array('count' => $data->getData(), 'date' => $data->getLabelStart()->format('D d F Y')); } // =================================== Users with edits $report = $this->getSeriesReport("org.openacalendar", "UsersWithEventsEdited", $this->app); $report->run(); $out['userEventsEdited'] = array(); foreach ($report->getData() as $data) { $out['userEventsEdited'][] = array('count' => $data->getData(), 'userID' => $data->getLabelID(), 'userUserName' => $data->getLabelText()); } //var_dump($out); file_put_contents(APP_ROOT_DIR . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'numbers.json', json_encode($out)); return array('result' => 'ok'); }
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 onThisStepProcessPage() { // Firstly, do we change mode? if ($this->request->request->get('action') == 'setvenue') { $this->draftEvent->setDetailsValue('where.mode', $this->MODE_VENUE); return true; } if ($this->request->request->get('action') == 'setnewvenue') { $this->draftEvent->setDetailsValue('where.mode', $this->MODE_NEWVENUE); $venueModel = new VenueModel(); $venueModel->setSiteId($this->site->getId()); $venueModel->setCountryId($this->draftEvent->getDetailsValue('event.country_id')); $venueModel->setTitle($this->request->request->get('fieldTitle')); $venueModel->setAddress($this->request->request->get('fieldAddress')); $venueModel->setAddressCode($this->request->request->get('fieldAddressCode')); if ($this->request->request->get('fieldAreaSlug') && $this->request->request->get('fieldAreaSlug') != -1) { $areaRepo = new AreaRepository(); $area = $areaRepo->loadBySlug($this->site, $this->request->request->get('fieldAreaSlug')); if ($area) { $venueModel->setAreaId($area->getId()); } } foreach ($this->application['extensions']->getExtensionsIncludingCore() as $extension) { $extension->addDetailsToVenue($venueModel); } $this->draftEvent->setDetailsValue('venue.title', $venueModel->getTitle()); $this->draftEvent->setDetailsValue('venue.address', $venueModel->getAddress()); $this->draftEvent->setDetailsValue('venue.address_code', $venueModel->getAddressCode()); $this->draftEvent->setDetailsValue('venue.field_area_search_text', $this->request->request->get('fieldAreaSearchText')); $this->draftEvent->setDetailsValue('venue.area_id', $venueModel->getAreaId()); return true; } if ($this->request->request->get('action') == 'setarea') { // User may have been setting venue and realised they didn't know it. Clear data to make sure it's kept clean. $this->draftEvent->unsetDetailsValue('event.newvenue'); $this->draftEvent->unsetDetailsValue('venue.title'); $this->draftEvent->unsetDetailsValue('venue.address'); $this->draftEvent->unsetDetailsValue('venue.address_code'); $this->draftEvent->unsetDetailsValue('venue.description'); $this->draftEvent->unsetDetailsValue('venue.field_area_search_text'); $this->draftEvent->unsetDetailsValue('venue.area_id'); // Do we ask user for area or not? $countryRepository = new CountryRepository(); $country = $countryRepository->loadById($this->draftEvent->getDetailsValue('event.country_id')); $areaRepository = new AreaRepository(); if ($areaRepository->doesCountryHaveAnyNotDeletedAreas($this->site, $country)) { $this->draftEvent->setDetailsValue('where.mode', $this->MODE_AREA); } else { $this->draftEvent->setDetailsValue('event.noareavenue', true); $this->isAllInformationGathered = true; } return true; } // Secondly, any thing actually set? if ($this->request->request->get('action') == 'setthisarea') { $ar = new AreaRepository(); $area = $ar->loadBySlug($this->site, $this->request->request->get('area_slug')); if ($area) { $this->draftEvent->setDetailsValue('area.id', $area->getId()); $this->draftEvent->setDetailsValue('area.title', $area->getTitle()); $this->isAllInformationGathered = true; return true; } } if ($this->request->request->get('action') == 'setthisvenue') { $vr = new VenueRepository(); $venue = $vr->loadBySlug($this->site, $this->request->request->get('venue_slug')); if ($venue) { $this->draftEvent->setDetailsValue('venue.id', $venue->getId()); $this->draftEvent->setDetailsValue('venue.title', $venue->getTitle()); $this->draftEvent->setDetailsValue('venue.address', $venue->getAddress()); $this->draftEvent->setDetailsValue('venue.address_code', $venue->getAddressCode()); $this->isAllInformationGathered = true; return true; } } if ($this->request->request->get('action') == 'setthisnewvenue') { $venueModel = new VenueModel(); $venueModel->setSiteId($this->site->getId()); $venueModel->setCountryId($this->draftEvent->getDetailsValue('event.country_id')); $venueModel->setTitle($this->request->request->get('fieldTitle')); $venueModel->setAddress($this->request->request->get('fieldAddress')); $venueModel->setAddressCode($this->request->request->get('fieldAddressCode')); $venueModel->setDescription($this->request->request->get('fieldDescription')); $areaRepo = new AreaRepository(); // 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->request->request->get('fieldAreaSlug') && $this->request->request->get('fieldAreaSlug') != -1) { $area = $areaRepo->loadBySlug($this->site, $this->request->request->get('fieldAreaSlug')); if ($area) { $venueModel->setAreaId($area->getId()); } } if ($this->request->request->get('fieldChildAreaSlug') && $this->request->request->get('fieldChildAreaSlug') != -1) { $areaChild = $areaRepo->loadBySlug($this->site, $this->request->request->get('fieldChildAreaSlug')); if ($areaChild) { $area = $areaChild; $venueModel->setAreaId($areaChild->getId()); } } foreach ($this->application['extensions']->getExtensionsIncludingCore() as $extension) { $extension->addDetailsToVenue($venueModel); } $area = null; if ($venueModel->getAreaId() && (!$area || $area->getId() != $venueModel->getAreaId())) { $area = $areaRepo->loadById($venueModel->getAreaId()); } $this->draftEvent->setDetailsValue('venue.title', $venueModel->getTitle()); $this->draftEvent->setDetailsValue('venue.address', $venueModel->getAddress()); $this->draftEvent->setDetailsValue('venue.address_code', $venueModel->getAddressCode()); $this->draftEvent->setDetailsValue('venue.description', $venueModel->getDescription()); if ($venueModel->hasLatLng()) { $this->draftEvent->setDetailsValue('venue.lat', $venueModel->getLat()); $this->draftEvent->setDetailsValue('venue.lng', $venueModel->getLng()); } else { $this->draftEvent->setDetailsValue('venue.lat', null); $this->draftEvent->setDetailsValue('venue.lng', null); } $this->draftEvent->setDetailsValue('venue.field_area_search_text', $this->request->request->get('fieldAreaSearchText')); if ($area) { $this->draftEvent->setDetailsValue('area.id', $area->getId()); $this->draftEvent->setDetailsValue('area.title', $area->getTitle()); } else { $this->draftEvent->setDetailsValue('area.id', null); $this->draftEvent->setDetailsValue('area.title', null); } // are we done? if user has selected -1 for "none" or there are no child areas. oh, and title needed if ($this->request->request->get('fieldChildAreaSlug') == -1 && trim($venueModel->getTitle())) { $this->draftEvent->setDetailsValue('event.newvenue', true); $this->isAllInformationGathered = true; } else { if (count($this->getChildAreasForArea($area, 1)) == 0 && trim($venueModel->getTitle())) { $this->draftEvent->setDetailsValue('event.newvenue', true); $this->isAllInformationGathered = true; } } $this->draftEvent->setDetailsValue('where.setthisnewvenue.submitted', true); return true; } if ($this->request->request->get('action') == 'setnoareavenue') { $this->draftEvent->setDetailsValue('event.noareavenue', true); $this->isAllInformationGathered = true; return true; } }
function newImportURL($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Group does not exist."); } $importurl = new ImportURLModel(); // we must setSiteId() here so loadClashForImportUrl() works $importurl->setSiteId($app['currentSite']->getId()); $importurl->setGroupId($this->parameters['group']->getId()); $form = $app['form.factory']->create(new ImportURLNewForm($app['currentSite'], $app['currentTimeZone']), $importurl); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $importURLRepository = new ImportURLRepository(); $clash = $importURLRepository->loadClashForImportUrl($importurl); if ($clash) { $importurl->setIsEnabled(false); $app['flashmessages']->addMessage("There was a problem enabling this importer. Please try to enable it for details."); } else { $importurl->setIsEnabled(true); } $area = null; $areaRepository = new AreaRepository(); $areasPost = $request->request->get('areas'); if (is_array($areasPost)) { foreach ($areasPost as $areaCode) { if (substr($areaCode, 0, 9) == 'EXISTING:') { $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9)); } } } $importurl->setAreaId($area ? $area->getId() : null); $importURLRepository->create($importurl, $app['currentSite'], $app['currentUser']); return $app->redirect("/importurl/" . $importurl->getSlug()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/group/newimporturl.html.twig', $this->parameters); }
function build(Application $app) { $this->paramaters = array('daysAheadInNextBox' => 3, 'showCharsOfDescription' => 0, 'refreshInMinutes' => 0, 'MAX_EVENT_QUERIES_ON_EVENT_BOARD' => self::$MAX_EVENT_QUERIES_ON_EVENT_BOARD, 'configParameters' => array()); if (isset($_GET['daysAheadInNextBox']) && intval($_GET['daysAheadInNextBox']) >= 0) { $this->paramaters['daysAheadInNextBox'] = intval($_GET['daysAheadInNextBox']); $this->paramaters['configParameters']['daysAheadInNextBox'] = $_GET['daysAheadInNextBox']; } if (isset($_GET['showCharsOfDescription']) && intval($_GET['showCharsOfDescription']) >= 0) { $this->paramaters['showCharsOfDescription'] = intval($_GET['showCharsOfDescription']); $this->paramaters['configParameters']['showCharsOfDescription'] = $_GET['showCharsOfDescription']; } if (isset($_GET['refreshInMinutes']) && intval($_GET['refreshInMinutes']) >= 0) { $this->paramaters['refreshInMinutes'] = intval($_GET['refreshInMinutes']); $this->paramaters['configParameters']['refreshInMinutes'] = $_GET['refreshInMinutes']; } $areaRepository = new AreaRepository(); $groupRepository = new GroupRepository(); $venueRepository = new VenueRepository(); $this->paramaters['data'] = array(); for ($i = 0; $i <= self::$MAX_EVENT_QUERIES_ON_EVENT_BOARD; $i++) { $area = null; if (isset($_GET['eventArea' . $i])) { $area = $this->getIdFromPassedVariable($_GET['eventArea' . $i]); $this->paramaters['configParameters']['eventArea' . $i] = $_GET['eventArea' . $i]; } $group = null; if (isset($_GET['eventGroup' . $i])) { $group = $this->getIdFromPassedVariable($_GET['eventGroup' . $i]); $this->paramaters['configParameters']['eventGroup' . $i] = $_GET['eventGroup' . $i]; } $venue = null; if (isset($_GET['eventVenue' . $i])) { $venue = $this->getIdFromPassedVariable($_GET['eventVenue' . $i]); $this->paramaters['configParameters']['eventVenue' . $i] = $_GET['eventVenue' . $i]; } if ($area || $group || $venue) { $queryData = array('area' => null, 'group' => null, 'venue' => null, 'minorImportance' => false, 'query' => new EventRepositoryBuilder()); $queryData['query']->setSite($app['currentSite']); $queryData['query']->setAfterNow(); $queryData['query']->setIncludeDeleted(false); if ($area) { $areaObj = $areaRepository->loadBySlug($app['currentSite'], $area); if ($areaObj) { $queryData['area'] = $areaObj; $queryData['query']->setArea($areaObj); } } if ($group) { $groupObj = $groupRepository->loadBySlug($app['currentSite'], $group); if ($groupObj) { $queryData['group'] = $groupObj; $queryData['query']->setGroup($groupObj); } } if ($venue) { $venueObj = $venueRepository->loadBySlug($app['currentSite'], $venue); if ($venueObj) { $queryData['venue'] = $venueObj; $queryData['query']->setVenue($venueObj); } } if (isset($_GET['eventMinorImportance' . $i]) && $_GET['eventMinorImportance' . $i] == 'yes') { $queryData['minorImportance'] = true; $this->paramaters['configParameters']['eventMinorImportance' . $i] = 'yes'; } $this->paramaters['data'][] = $queryData; } } if (count($this->paramaters['data']) == 0) { $queryData = array('area' => null, 'group' => null, 'venue' => null, 'minorImportance' => false, 'query' => new EventRepositoryBuilder()); $queryData['query']->setSite($app['currentSite']); $queryData['query']->setAfterNow(); $queryData['query']->setIncludeDeleted(false); $this->paramaters['data'][] = $queryData; } }
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); }
function moveToArea($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Event does not exist."); } $gotResultEditedVenue = false; $gotResultEditedEvent = false; if ($request->request->get('area') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { if (intval($request->request->get('area'))) { $areaRepository = new AreaRepository(); $area = $areaRepository->loadBySlug($app['currentSite'], $request->request->get('area')); if ($area && (!$this->parameters['area'] || $area->getId() != $this->parameters['area']->getId())) { if ($this->parameters['venue']) { $this->parameters['venue']->setAreaId($area->getId()); $venueRepository = new VenueRepository(); $venueRepository->edit($this->parameters['venue'], $app['currentUser']); $gotResultEditedVenue = true; } else { $this->parameters['event']->setAreaId($area->getId()); $eventRepository = new EventRepository(); $eventRepository->edit($this->parameters['event'], $app['currentUser']); $gotResultEditedEvent = true; } $app['flashmessages']->addMessage('Thank you; event updated!'); } } } if ($gotResultEditedEvent) { $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()); } } else { return $app->redirect("/event/" . $this->parameters['event']->getSlugForUrl() . '/'); } }
protected function processThingsToDoAfterGetUser(Request $request, Application $app) { global $CONFIG; $eventRepo = new EventRepository(); $areaRepo = new AreaRepository(); $event = null; $area = null; // Any events to add? if ($request->query->has("event")) { if ($CONFIG->isSingleSiteMode) { $event = $eventRepo->loadBySiteIDAndEventSlug($CONFIG->singleSiteID, $request->query->get("event")); } else { $siteRepo = new SiteRepository(); $site = $siteRepo->loadBySlug($request->query->get("eventSite")); if ($site) { $event = $eventRepo->loadBySlug($site, $request->query->get("event")); } } if ($event && $event->getIsAllowedForAfterGetUser()) { if (!$app['websession']->hasArray("afterGetUserAddEvents")) { $app['websession']->setArray("afterGetUserAddEvents", array($event->getId())); } else { if (!in_array($event->getId(), $app['websession']->getArray("afterGetUserAddEvents"))) { $app['websession']->appendArray("afterGetUserAddEvents", $event->getId()); } } } } // Any areas to add? if ($request->query->has("area")) { if ($CONFIG->isSingleSiteMode) { $area = $areaRepo->loadBySiteIDAndAreaSlug($CONFIG->singleSiteID, $request->query->get("area")); } else { $siteRepo = new SiteRepository(); $site = $siteRepo->loadBySlug($request->query->get("areaSite")); if ($site) { $area = $areaRepo->loadBySlug($site, $request->query->get("area")); } } if ($area && $area->getIsAllowedForAfterGetUser()) { if (!$app['websession']->hasArray("afterGetUserAddAreas")) { $app['websession']->setArray("afterGetUserAddAreas", array($area->getId())); } else { if (!in_array($area->getId(), $app['websession']->getArray("afterGetUserAddAreas"))) { $app['websession']->appendArray("afterGetUserAddAreas", $area->getId()); } } } } // Remove events? if ($request->query->has("removeEventId")) { $app['websession']->removeValueFromArray("afterGetUserAddEvents", $request->query->has("removeEventId")); } // Remove areas? if ($request->query->has("removeAreaId")) { $app['websession']->removeValueFromArray("afterGetUserAddAreas", $request->query->has("removeAreaId")); } // load events to show user $this->parameters['afterGetUserAddEvents'] = array(); if ($app['websession']->hasArray("afterGetUserAddEvents")) { foreach ($app['websession']->getArray("afterGetUserAddEvents") as $eventID) { if ($event != null && $eventID == $event->getId()) { if ($event->getIsAllowedForAfterGetUser()) { $this->parameters['afterGetUserAddEvents'][] = $event; } } else { $eventTmp = $eventRepo->loadByID($eventID); if ($eventTmp && $eventTmp->getIsAllowedForAfterGetUser()) { $this->parameters['afterGetUserAddEvents'][] = $eventTmp; } } } } // load areas to show user $this->parameters['afterGetUserAddAreas'] = array(); if ($app['websession']->hasArray("afterGetUserAddAreas")) { foreach ($app['websession']->getArray("afterGetUserAddAreas") as $areaID) { if ($area != null && $areaID == $area->getId()) { if ($area->getIsAllowedForAfterGetUser()) { $this->parameters['afterGetUserAddAreas'][] = $area; } } else { $areaTmp = $areaRepo->loadByID($areaID); if ($areaTmp && $areaTmp->getIsAllowedForAfterGetUser()) { $this->parameters['afterGetUserAddAreas'][] = $areaTmp; } } } } }