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;
 }
 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();
 }
 function testFilterAreaAndIncludeAreaAndIncludeVenue()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $areaRepo = new AreaRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $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);
     $areaRepo->buildCacheAreaHasParent($area);
     ######################## For now just test it doesn't crash, I commited a bug that did crash here
     $erb = new EventRepositoryBuilder();
     $erb->setArea($area);
     $erb->setIncludeVenueInformation(true);
     $erb->setIncludeAreaInformation(true);
     $erb->fetchAll();
 }
 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());
 }
 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 run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->updateBoundsCache($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 protected function run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $arb->setLimit(0);
     // all of them
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->updateFutureEventsCache($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 protected function 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;
 }
 protected function run()
 {
     $areaRepository = new AreaRepository();
     $arb = new AreaRepositoryBuilder();
     $arb->setLimit(0);
     // all of them
     $arb->setCacheNeedsBuildingOnly(true);
     $count = 0;
     foreach ($arb->fetchAll() as $area) {
         $areaRepository->buildCacheAreaHasParent($area);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 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($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];
     }
     $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;
 }
 public function postInfoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Does not exist.");
     }
     $ourRequest = new \Request($request);
     $edits = false;
     if ($ourRequest->hasGetOrPost('title') && $this->area->setTitleIfDifferent($ourRequest->getGetOrPostString('title', ''))) {
         $edits = true;
     }
     if ($edits) {
         $repo = new AreaRepository();
         $repo->edit($this->area, $app['apiUser']);
         $out = array('edited' => true);
     } else {
         $out = array('edited' => false);
     }
     return json_encode($out);
 }
 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 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;
 }
 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());
 }
 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 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 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() . '/');
     }
 }
 function testMoveAllFutureEventsAtVenueToNoSetVenue()
 {
     $this->addCountriesToTestDB();
     TimeSource::mock(2013, 7, 1, 7, 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());
     $area = new AreaModel();
     $area->setTitle("scotland");
     $areaRepo = new AreaRepository();
     $countryRepo = new CountryRepository();
     $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $venue = new VenueModel();
     $venue->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId());
     $venue->setTitle("edinburgh hall");
     $venue->setAreaId($area->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     #### Event To Change
     $event = new EventModel();
     $event->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId());
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0));
     $event->setVenueId($venue->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     #### Load Event, Check in Venue
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals(false, $event->getIsDeleted());
     $this->assertNull($event->getAreaId());
     $this->assertEquals($venue->getId(), $event->getVenueId());
     #### In preperation for deleting event, call moveAllFutureEventsAtVenueToNoSetVenue()
     TimeSource::mock(2013, 7, 1, 8, 0, 0);
     $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($venue, $user);
     #### Load event, check in area
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals(false, $event->getIsDeleted());
     $this->assertNull($event->getVenueId());
     $this->assertEquals($area->getId(), $event->getAreaId());
 }
 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);
 }
}
// ######################################################### 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) {
        $areaRepoBuilder->setParentArea($area);
    } else {
        $areaRepoBuilder->setNoParentArea(true);
    }
    $childAreas = array();
    $areaRepository = new AreaRepository();
    foreach ($areaRepoBuilder->fetchAll() as $area) {
        $areaRepository->updateFutureEventsCache($area);
        if ($thisconfig->getBoolean('ListChildAreasWithNoEvents', false) || $area->getCachedFutureEvents() > 0) {
            $childAreas[] = $area;
        }
    }
}
// ######################################################### Build Email Content, show user.
configureAppForSite($site);
$messageText = $app['twig']->render('email/sendSpecifiedEventsEmail.cli.txt.twig', array('data' => $calData, 'currentSite' => $site, 'currentTimeZone' => $thisconfig->get('TimeZone'), 'intro' => file_get_contents($configDataDir . '/' . $thisconfig->get('IntroTXTFile')), 'listChildAreas' => $thisconfig->getBoolean('ListChildAreas'), 'listChildAreasIntro' => $thisconfig->get('ListChildAreasIntro'), 'childAreas' => $childAreas));
$messageHTML = $app['twig']->render('email/sendSpecifiedEventsEmail.cli.html.twig', array('data' => $calData, 'currentSite' => $site, 'currentTimeZone' => $thisconfig->get('TimeZone'), 'intro' => file_get_contents($configDataDir . '/' . $thisconfig->get('IntroHTMLFile')), 'listChildAreas' => $thisconfig->getBoolean('ListChildAreas'), 'listChildAreasIntro' => $thisconfig->get('ListChildAreasIntro'), 'childAreas' => $childAreas));
if ($CONFIG->isDebug) {
    file_put_contents('/tmp/sendEventsEmail.txt', $messageText);
}
if ($CONFIG->isDebug) {
 function testUserWatchingParentAreaWithVenue()
 {
     TimeSource::mock(2014, 01, 01, 9, 0, 0);
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $areaRepo = new AreaRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $venueRepo = new \repositories\VenueRepository();
     $eventRepository = new EventRepository();
     $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository();
     $GB = $countryRepo->loadByTwoCharCode("GB");
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo->create($user);
     $userWatchesMain = new UserAccountModel();
     $userWatchesMain->setEmail("*****@*****.**");
     $userWatchesMain->setUsername("test1");
     $userWatchesMain->setPassword("password1");
     $userRepo->create($userWatchesMain);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $area = new AreaModel();
     $area->setTitle("Scotland");
     $areaRepo->create($area, null, $site, $GB);
     $areaChild = new AreaModel();
     $areaChild->setTitle("Edinburgh");
     $areaRepo->create($areaChild, $area, $site, $GB);
     $venue = new \models\VenueModel();
     $venue->setTitle("Castle");
     $venue->setAreaId($areaChild->getId());
     $venueRepo->create($venue, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 11, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 11, 10, 21, 0, 0));
     $eventRepository->create($event, $site, $user);
     $event->setVenueId($venue->getId());
     TimeSource::mock(2014, 01, 01, 9, 1, 0);
     $eventRepository->edit($event);
     // have to update child cache
     $areaRepo->buildCacheAreaHasParent($area);
     $areaRepo->buildCacheAreaHasParent($areaChild);
     // test before
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesMain, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesMain, false, true, true, false);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     // test watching main group gets event
     $userWatchesAreaRepo->startUserWatchingArea($userWatchesMain, $area);
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesMain, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesMain, false, true, true, false);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
 }
 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);
 }
 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 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());
 }
 function testInChildArea()
 {
     $this->addCountriesToTestDB();
     TimeSource::mock(2013, 7, 1, 7, 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());
     $area1 = new AreaModel();
     $area1->setTitle("scotland");
     $area1child = new AreaModel();
     $area1child->setTitle("edinburgh");
     $area2 = new AreaModel();
     $area2->setTitle("england");
     $areaRepo = new AreaRepository();
     $countryRepo = new CountryRepository();
     $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1);
     $areaRepo->create($area1child, $area1, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1child);
     $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area2);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt($this->mktime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 8, 1, 21, 0, 0));
     $event->setAreaId($area1child->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1child);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - don't find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area2);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
 }
 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 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() . '/');
 }
 function testBasicThenDeletedByVanishing()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $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());
     $areaRepo = new AreaRepository();
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->getId());
     $importURL->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId());
     $importURL->setAreaId($area->getId());
     $importURL->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // Import
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/BasicICAL.ical');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $event = $events[0];
     $this->assertEquals("Test 3 SpecFic Writing Group", $event->getSummary());
     $this->assertEquals('2013-11-12 18:00:00', $event->getStartAtInUTC()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-11-12 20:30:00', $event->getEndAtInUTC()->format('Y-m-d H:i:s'));
     $this->assertEquals('http://opentechcalendar.co.uk/index.php/event/166', $event->getDescription());
     $this->assertEquals('http://opentechcalendar.co.uk/index.php/event/166', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
     $this->assertEquals($countryRepo->loadByTwoCharCode('GB')->getId(), $event->getCountryId());
     $this->assertEquals($area->getId(), $event->getAreaId());
     $this->assertEquals("Europe/London", $event->getTimezone());
     // Import again
     \TimeSource::mock(2013, 10, 1, 1, 1, 2);
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/BasicICALNoEvents.ical');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $event = $events[0];
     $this->assertTrue($event->getIsDeleted());
 }