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 test1() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $areaRepo = new AreaRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting()); ### No areas $this->assertFalse($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area 1 $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($area); $this->checkAreaInTest1($areaRepo->loadById($area->getId())); $this->checkAreaInTest1($areaRepo->loadBySlug($site, $area->getSlug())); // no parents. Cache should be empty. $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent"); $stat->execute(); $this->assertEquals(0, $stat->rowCount()); $this->assertTrue($areaRepo->doesCountryHaveAnyNotDeletedAreas($site, $countryRepo->loadByTwoCharCode('GB'))); ### Area child $areaChild = new AreaModel(); $areaChild->setTitle("test child"); $areaChild->setDescription("test test child"); $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $user); $areaRepo->buildCacheAreaHasParent($areaChild); // calling this multiple times should not crash $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $areaRepo->buildCacheAreaHasParent($areaChild); $this->checkChildAreaInTest1($areaRepo->loadById($areaChild->getId())); $this->checkChildAreaInTest1($areaRepo->loadBySlug($site, $areaChild->getSlug())); // Check Cache $stat = $this->app['db']->prepare("SELECT * FROM cached_area_has_parent WHERE area_id=" . $areaChild->getId() . " AND has_parent_area_id=" . $area->getId()); $stat->execute(); $this->assertEquals(1, $stat->rowCount()); }
function testIntegration1() { $this->addCountriesToTestDB(); \TimeSource::mock(2014, 1, 1, 12, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); ## Create area \TimeSource::mock(2014, 1, 1, 13, 0, 0); $area = new AreaModel(); $area->setTitle("test"); $area->setDescription("test test"); $area->setCountryId($gb->getId()); $areaRepo = new AreaRepository(); $areaRepo->create($area, null, $site, $gb, $user); ## Edit area \TimeSource::mock(2014, 1, 1, 14, 0, 0); $area = $areaRepo->loadById($area->getId()); $area->setDescription("testy"); $areaRepo->edit($area, $user); ## Now save changed flags on these ..... $areaHistoryRepo = new AreaHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM area_history"); $stat->execute(); while ($data = $stat->fetch()) { $areaHistory = new AreaHistoryModel(); $areaHistory->setFromDataBaseRow($data); $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory); } ## Now load and check $historyRepo = new HistoryRepositoryBuilder(); $historyRepo->setIncludeEventHistory(false); $historyRepo->setIncludeVenueHistory(false); $historyRepo->setIncludeGroupHistory(false); $historyRepo->setIncludeAreaHistory(true); $histories = $historyRepo->fetchAll(); $this->assertEquals(2, count($histories)); #the edit $this->assertEquals(FALSE, $histories[0]->getTitleChanged()); $this->assertEquals(true, $histories[0]->getDescriptionChanged()); $this->assertEquals(false, $histories[0]->getCountryIdChanged()); $this->assertEquals(false, $histories[0]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[0]->getIsDeletedChanged()); #the create $this->assertEquals(true, $histories[1]->getTitleChanged()); $this->assertEquals(true, $histories[1]->getDescriptionChanged()); $this->assertEquals(true, $histories[1]->getCountryIdChanged()); $this->assertEquals(false, $histories[1]->getParentAreaIdChanged()); $this->assertEquals(false, $histories[1]->getIsDeletedChanged()); }
function test1() { $this->addCountriesToTestDB(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); $this->checkVenueInTest1($venueRepo->loadById($venue->getId())); $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug())); $grb = new VenueRepositoryBuilder(); $grb->setFreeTextsearch('test'); $this->assertEquals(1, count($grb->fetchAll())); $grb = new VenueRepositoryBuilder(); $grb->setFreeTextsearch('cats'); $this->assertEquals(0, count($grb->fetchAll())); }
function test1() { \TimeSource::mock(2014, 1, 1, 0, 0, 0); $this->addCountriesToTestDB(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); \TimeSource::mock(2014, 1, 1, 1, 0, 0); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); \TimeSource::mock(2014, 1, 1, 2, 0, 0); $venueRepo->delete($venue, $user); $this->checkVenueInTest1($venueRepo->loadById($venue->getId())); $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug())); $vrb = new VenueRepositoryBuilder(); $vrb->setIncludeDeleted(true); $this->assertEquals(1, count($vrb->fetchAll())); $vrb = new VenueRepositoryBuilder(); $vrb->setIncludeDeleted(false); $this->assertEquals(0, count($vrb->fetchAll())); }
public function setFromJSON($json) { if (isset($json->event)) { if (isset($json->event->summary)) { $this->summary = $json->event->summary; } if (isset($json->event->description)) { $this->description = $json->event->description; } if (isset($json->event->url)) { $this->url = $json->event->url; } $timezone = new \DateTimeZone($this->timezone); if (isset($json->event->start->str)) { $this->start_at = new \DateTime($json->event->start->str, $timezone); } if (isset($json->event->end->str)) { $this->end_at = new \DateTime($json->event->end->str, $timezone); } if (isset($json->event->country) && isset($json->event->country->code) && $json->event->country->code) { $countryRepo = new CountryRepository(); // Delibrately setting NULL on failure so user gets an error message. $this->country = $countryRepo->loadByTwoCharCode($json->event->country->code); // TODO check allowed in this site } if (isset($json->event->timezone)) { // Delibrately setting NULL on failure so user gets an error message. $this->timezone = $this->country && in_array($json->event->timezone, $this->country->getTimezonesAsList()) ? $json->event->timezone : null; } } if (isset($json->site)) { $siteRepo = new SiteRepository(); if (isset($json->site->id)) { $this->site = $siteRepo->loadById($json->site->id); } if (isset($json->site->slug)) { $this->site = $siteRepo->loadBySlug($json->site->slug); } } if (isset($json->user)) { $userRepo = new UserAccountRepository(); if (isset($json->user->email)) { $this->user = $userRepo->loadByEmail($json->user->email); } else { if (isset($json->user->username)) { $this->user = $userRepo->loadByUserName($json->user->username); } } } if (isset($json->group)) { $groupRepo = new GroupRepository(); if (isset($json->group->slug) && $this->site) { $this->group = $groupRepo->loadBySlug($this->site, $json->group->slug); } else { if (isset($json->group->id)) { $this->group = $groupRepo->loadById($json->group->id); } } } }
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 create(Request $request, Application $app) { $siteRepository = new SiteRepository(); $form = $app['form.factory']->create(new CreateForm()); if ('POST' == $request->getMethod()) { $form->bind($request); $data = $form->getData(); $site = $siteRepository->loadBySlug($data['slug']); if ($site) { $form->addError(new FormError('That address is already taken')); } if ($form->isValid()) { $site = new SiteModel(); $site->setSlug($data['slug']); $site->setTitle($data['title']); if ($data['read'] == 'public') { $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); } else { $site->setIsListedInIndex(false); $site->setIsWebRobotsAllowed(false); } if ($data['write'] == 'public') { $isAllUsersEditors = true; } else { $isAllUsersEditors = false; } $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $siteRepository->create($site, $app['currentUser'], array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode), $isAllUsersEditors); if ($app['config']->hasSSL) { return $app->redirect("https://" . $site->getSlug() . "." . $app['config']->webSiteDomainSSL); } else { return $app->redirect("http://" . $site->getSlug() . "." . $app['config']->webSiteDomain); } } } $sites = array(); $repo = new SiteRepository(); if (isset($_COOKIE['sitesSeen'])) { foreach (explode(",", $_COOKIE['sitesSeen']) as $siteID) { if (intval($siteID) > 0) { $site = $repo->loadById($siteID); if ($site && !$site->getIsClosedBySysAdmin() && $site->getSlug() != $app['config']->siteSlugDemoSite) { $sites[$site->getId()] = $site; } } } } $srb = new SiteRepositoryBuilder(); $srb->setIsOpenBySysAdminsOnly(true); $srb->setUserInterestedIn($app['currentUser']); foreach ($srb->fetchAll() as $site) { $sites[$site->getId()] = $site; } return $app['twig']->render('index/index/create.html.twig', array('form' => $form->createView(), 'sites' => $sites)); }
protected function build($slug, Request $request, Application $app) { $repo = new CountryRepository(); $this->country = $repo->loadByTwoCharCode($slug); if (!$this->country) { return false; } return true; }
protected function build($slug, Request $request, Application $app) { $this->parameters = array(); $gr = new CountryRepository(); $this->parameters['country'] = $gr->loadByTwoCharCode($slug); if (!$this->parameters['country']) { return false; } // TODO could check this country is or was valid for this site? return true; }
function index(Request $request, Application $app) { $form = $app['form.factory']->create(new NewSiteForm()); if ('POST' == $request->getMethod()) { $form->bind($request); $data = $form->getData(); $siteRepository = new SiteRepository(); $site = $siteRepository->loadBySlug($data['slug']); if ($site) { $form->addError(new FormError('That address is already taken')); } if ($form->isValid()) { $userRepo = new UserAccountRepository(); $user = $userRepo->loadByEmail($data['email']); if ($user) { $data = $form->getData(); $site = new SiteModel(); $site->setSlug($data['slug']); $site->setTitle($data['title']); if ($data['read'] == 'public') { $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); } else { $site->setIsListedInIndex(false); $site->setIsWebRobotsAllowed(false); } if ($data['write'] == 'public') { $site->setIsAllUsersEditors(true); $site->setIsRequestAccessAllowed(false); } else { $site->setIsAllUsersEditors(false); $site->setIsRequestAccessAllowed(true); } $site->setIsFeatureCuratedList($app['config']->newSiteHasFeatureCuratedList); $site->setIsFeatureImporter($app['config']->newSiteHasFeatureImporter); $site->setIsFeatureMap($app['config']->newSiteHasFeatureMap); $site->setIsFeatureVirtualEvents($app['config']->newSiteHasFeatureVirtualEvents); $site->setIsFeaturePhysicalEvents($app['config']->newSiteHasFeaturePhysicalEvents); $site->setIsFeatureGroup($app['config']->newSiteHasFeatureGroup); $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance); $site->setIsFeatureTag($app['config']->newSiteHasFeatureTag); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $siteRepository->create($site, $user, array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode)); return $app->redirect("/sysadmin/site/" . $site->getId()); } else { $app['flashmessages']->addError('Existing user not found!'); } } } return $app['twig']->render('sysadmin/sitenew/index.html.twig', array('form' => $form->createView())); }
function testLoadEventJustBeforeEdit() { \TimeSource::mock(2014, 1, 1, 1, 1, 1); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $eventRepo = new EventRepository(); $eventHistoryRepo = new EventHistoryRepository(); #### Setup $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()); #### Create Event \TimeSource::mock(2014, 1, 1, 1, 2, 1); $event = new EventModel(); $event->setSummary("Cats"); $event->setDescription("Go Miaow"); $event->setStartAt(getUTCDateTime(2014, 1, 10, 9, 0, 0)); $event->setEndAt(getUTCDateTime(2014, 1, 10, 17, 0, 0)); $eventRepo->create($event, $site, $user); #### Edit Event \TimeSource::mock(2014, 1, 1, 1, 3, 1); $event = $eventRepo->loadBySlug($site, $event->getSlug()); $event->setSummary("Lizards"); $event->setDescription("Go ?"); $eventRepo->edit($event, $user); #### Edit Event \TimeSource::mock(2014, 1, 1, 1, 4, 1); $event = $eventRepo->loadBySlug($site, $event->getSlug()); $event->setSummary("Dogs"); $event->setDescription("Go Woof"); $eventRepo->edit($event, $user); #### test: Load Current State \TimeSource::mock(2014, 1, 1, 1, 5, 1); $event = $eventRepo->loadBySlug($site, $event->getSlug()); $this->assertEquals("Dogs", $event->getSummary()); $this->assertEquals("Go Woof", $event->getDescription()); #### test: load state before last edit \TimeSource::mock(2014, 1, 1, 1, 6, 1); $history = $eventHistoryRepo->loadByEventAndlastEditByUser($event, $user); $event = $eventRepo->loadEventJustBeforeEdit($event, $history); $this->assertEquals("Lizards", $event->getSummary()); $this->assertEquals("Go ?", $event->getDescription()); }
function test1() { \TimeSource::mock(2014, 1, 1, 0, 0, 0); $this->addCountriesToTestDB(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $countryRepo = new CountryRepository(); $gb = $countryRepo->loadByTwoCharCode('GB'); $venue1 = new VenueModel(); $venue1->setTitle("test"); $venue1->setDescription("test test"); $venue1->setCountryId($gb->getId()); $venue2 = new VenueModel(); $venue2->setTitle("test this looks similar"); $venue2->setDescription("test test"); $venue2->setCountryId($gb->getId()); $venueRepo = new VenueRepository(); $venueRepo->create($venue1, $site, $user); $venueRepo->create($venue2, $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->setVenueId($venue2->getId()); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); // Test before $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($venue2->getId(), $event->getVenueId()); $venue2 = $venueRepo->loadById($venue2->getId()); $this->assertFalse($venue2->getIsDeleted()); $this->assertNull($venue2->getIsDuplicateOfId()); // Mark \TimeSource::mock(2014, 1, 1, 2, 0, 0); $venueRepo->markDuplicate($venue2, $venue1, $user); // Test Duplicate $event = $eventRepository->loadBySlug($site, $event->getSlug()); $this->assertEquals($venue1->getId(), $event->getVenueId()); $venue2 = $venueRepo->loadById($venue2->getId()); $this->assertTrue($venue2->getIsDeleted()); $this->assertEquals($venue1->getId(), $venue2->getIsDuplicateOfId()); }
public function addDetailsToVenue(VenueModel $venue) { if ($venue->getAddressCode() && (!$venue->getLat() || !$venue->getLng())) { $cr = new CountryRepository(); $gb = $cr->loadByTwoCharCode("GB"); if ($venue->getCountryId() == $gb->getId()) { list($lat, $lng) = AddressCodeGBOpenCodePointGet::get($venue->getAddressCode()); if ($lat && $lng) { $venue->setLat($lat); $venue->setLng($lng); } } } }
protected function build($countryslug, Request $request, Application $app) { $this->parameters = array('country' => null, 'parentAreas' => array()); $cr = new CountryRepository(); // we accept both ID and Slug. Slug is proper one to use, but some JS may need to load by ID. $this->parameters['country'] = intval($countryslug) ? $cr->loadById($countryslug) : $cr->loadByTwoCharCode($countryslug); if (!$this->parameters['country']) { return false; } // check this country is or was valid for this site $countryInSiteRepo = new CountryInSiteRepository(); if (!$countryInSiteRepo->isCountryInSite($this->parameters['country'], $app['currentSite'])) { return false; } return true; }
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(); $gr = new CountryRepository(); // we must accept both ID and Slug. Slug is proper one to use, but some JS needs to load by ID. $this->parameters['country'] = intval($slug) ? $gr->loadById($slug) : $gr->loadByTwoCharCode($slug); if (!$this->parameters['country']) { return false; } // check this country is or was valid for this site $countryInSiteRepo = new CountryInSiteRepository(); if (!$countryInSiteRepo->isCountryInSite($this->parameters['country'], $app['currentSite'])) { return false; } $areaRepoBuilder = new AreaRepositoryBuilder(); $areaRepoBuilder->setSite($app['currentSite']); $areaRepoBuilder->setCountry($this->parameters['country']); $areaRepoBuilder->setNoParentArea(true); $areaRepoBuilder->setIncludeDeleted(false); $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll(); return true; }
$slug = $argv[1]; $email = $argv[2]; if (!$slug || !$email) { die("Slug and Email?\n\n"); } if (!SiteModel::isSlugValid($slug, $CONFIG)) { die("Slug is not valid!\n\n"); } print "Slug: " . $slug . "\n"; print "Email: " . $email . "\n"; sleep(10); print "Starting ...\n"; $userRepository = new UserAccountRepository(); $user = $userRepository->loadByUserNameOrEmail($email); if (!$user) { die("Can't load user!\n\n"); } $site = new SiteModel(); $site->setSlug($slug); $site->setTitle($slug); $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); $site->setPromptEmailsDaysInAdvance($CONFIG->newSitePromptEmailsDaysInAdvance); $siteRepository = new SiteRepository(); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $gb = $countryRepository->loadByTwoCharCode("GB"); if (!$gb) { die("Can't load Country GB - have you loaded static data?\n\n"); } $siteRepository->create($site, $user, array($gb), $siteQuotaRepository->loadByCode($CONFIG->newSiteHasQuotaCode), false);
function showCountry($siteid, $countrycode, Request $request, Application $app) { $this->build($siteid, $request, $app); $cr = new CountryRepository(); $this->parameters['country'] = $cr->loadByTwoCharCode($countrycode); if (!$this->parameters['country']) { die("No Country"); } $this->parameters['areaTree'] = $this->buildTree($this->parameters['site']); return $app['twig']->render('sysadmin/site/country.html.twig', $this->parameters); }
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)); }
function testUserWatchesArea() { $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userTest = new UserAccountModel(); $userTest->setEmail("*****@*****.**"); $userTest->setUsername("testtest"); $userTest->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $userRepo->create($userTest); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $area = new \models\AreaModel(); $area->setTitle("Test"); $areaRepo = new \repositories\AreaRepository(); $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user); // Test user doesn't have it $srb = new \repositories\builders\SiteRepositoryBuilder(); $srb->setUserInterestedIn($userTest); $sites = $srb->fetchAll(); $this->assertEquals(0, count($sites)); // watch area $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository(); $userWatchesAreaRepo->startUserWatchingArea($userTest, $area); // has it! $srb = new \repositories\builders\SiteRepositoryBuilder(); $srb->setUserInterestedIn($userTest); $sites = $srb->fetchAll(); $this->assertEquals(1, count($sites)); }
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()); }
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 testSetCountryAndTimeZone() { \TimeSource::mock(2014, 06, 01, 00, 00, 00); $this->addCountriesToTestDB(); $countryRepo = new CountryRepository(); $country = $countryRepo->loadByTwoCharCode("DE"); $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()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $json = json_decode('{ "event":{ "summary":"Test", "description":"test test test", "url":"http://example.com", "start":{ "str":"2014-07-01 10:00:00" }, "end":{ "str":"2014-07-01 17:00:00" }, "country":{ "code":"DE" }, "timezone":"Europe/Berlin" }, "site":{ "slug":"test" }, "group":{ "slug":"' . $group->getSlug() . '" }, "user":{ "username":"******" } }'); $createEvent = new CreateEvent(); $createEvent->setFromJSON($json); $this->assertEquals(true, $createEvent->canGo()); $createEvent->go(); $eventRepoBuilder = new EventRepositoryBuilder(); $events = $eventRepoBuilder->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertEquals('Test', $event->getSummary()); $this->assertEquals('test test test', $event->getDescription()); $this->assertEquals('http://example.com', $event->getUrl()); // Times above are Berlin, These are UTC $this->assertEquals('2014-07-01T09:00:00+00:00', $event->getStartAtInUTC()->format('c')); $this->assertEquals('2014-07-01T16:00:00+00:00', $event->getEndAtInUTC()->format('c')); $this->assertEquals($group->getId(), $event->getGroupId()); $this->assertEquals('Europe/Berlin', $event->getTimeZone()); $this->assertEquals($country->getId(), $event->getCountryId()); }
function testMoveAllFutureEventsAtVenueToNoSetVenueWithNoArea() { $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()); $countryRepo = new CountryRepository(); $venue = new VenueModel(); $venue->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId()); $venue->setTitle("edinburgh hall"); $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->assertNull($event->getAreaId()); }