protected function build($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('group' => null, 'venue' => null, 'country' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $er = new EventRepository();
     $this->parameters['event'] = $er->loadBySlug($this->parameters['site'], $slug);
     $this->parameters['eventisduplicateof'] = $this->parameters['event']->getIsDuplicateOfId() ? $er->loadById($this->parameters['event']->getIsDuplicateOfId()) : null;
     if (!$this->parameters['event']) {
         $app->abort(404);
     }
     if ($this->parameters['event']->getGroupId()) {
         $gr = new GroupRepository();
         $this->parameters['group'] = $gr->loadById($this->parameters['event']->getGroupId());
     }
     if ($this->parameters['event']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID());
     }
     if ($this->parameters['event']->getVenueID()) {
         $cr = new VenueRepository();
         $this->parameters['venue'] = $cr->loadById($this->parameters['event']->getVenueID());
     }
 }
 function testIntegration1()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 1, 1, 12, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     ## Create area
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $area->setCountryId($gb->getId());
     $areaRepo = new AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     ## Edit area
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $area = $areaRepo->loadById($area->getId());
     $area->setDescription("testy");
     $areaRepo->edit($area, $user);
     ## Now save changed flags on these .....
     $areaHistoryRepo = new AreaHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM area_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $areaHistory = new AreaHistoryModel();
         $areaHistory->setFromDataBaseRow($data);
         $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeAreaHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(true, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(false, $histories[0]->getParentAreaIdChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(true, $histories[1]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getParentAreaIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array('groups' => array(), 'country' => null, 'venue' => null, 'area' => null);
     if (strpos($slug, "-") > 0) {
         $slugBits = explode("-", $slug, 2);
         $slug = $slugBits[0];
     }
     $eventRepository = new EventRepository();
     $this->parameters['event'] = $eventRepository->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['event']) {
         return false;
     }
     if ($this->parameters['event']->getGroupId()) {
         $grb = new GroupRepositoryBuilder();
         $grb->setEvent($this->parameters['event']);
         $this->parameters['groups'] = $grb->fetchAll();
     }
     if ($this->parameters['event']->getVenueID()) {
         $vr = new VenueRepository();
         $this->parameters['venue'] = $vr->loadById($this->parameters['event']->getVenueID());
     }
     if ($this->parameters['event']->getAreaID()) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($this->parameters['event']->getAreaID());
     } elseif ($this->parameters['venue'] && $this->parameters['venue']->getAreaId()) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($this->parameters['venue']->getAreaID());
     }
     if ($this->parameters['event']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID());
     }
     return true;
 }
 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();
     $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 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()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->delete($venue, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(true);
     $this->assertEquals(1, count($vrb->fetchAll()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(false);
     $this->assertEquals(0, count($vrb->fetchAll()));
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array('country' => null, 'area' => null, 'parentAreas' => array());
     $iurlRepository = new ImportURLRepository();
     $this->parameters['importurl'] = $iurlRepository->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['importurl']) {
         return false;
     }
     if ($this->parameters['importurl']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['importurl']->getCountryID());
     }
     if ($this->parameters['importurl']->getGroupId()) {
         $gr = new GroupRepository();
         $this->parameters['group'] = $gr->loadById($this->parameters['importurl']->getGroupId());
     }
     if ($this->parameters['importurl']->getAreaId()) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($this->parameters['importurl']->getAreaId());
         if (!$this->parameters['area']) {
             return false;
         }
         $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
         while ($checkArea) {
             array_unshift($this->parameters['parentAreas'], $checkArea);
             $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
         }
     }
     $app['currentUserActions']->set("org.openacalendar", "importURLLog", true);
     $app['currentUserActions']->set("org.openacalendar", "importURLEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter());
     $app['currentUserActions']->set("org.openacalendar", "importURLDisable", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter() && $this->parameters['importurl']->getIsEnabled());
     $app['currentUserActions']->set("org.openacalendar", "importURLEnable", $app['currentUserPermissions']->hasPermission("org.openacalendar", "IMPORTURL_CHANGE") && $app['currentSite']->getIsFeatureImporter() && (!$this->parameters['importurl']->getIsEnabled() || $this->parameters['importurl']->getIsExpired()));
     return true;
 }
 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;
 }
 function onThisStepSetUpPageView()
 {
     $out = array();
     if ($this->draftEvent->getDetailsValue('event.country_id')) {
         $countryRepository = new CountryRepository();
         $out['country'] = $countryRepository->loadById($this->draftEvent->getDetailsValue('event.country_id'));
     }
     return $out;
 }
 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 test1()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 10, 1, 1, 1, 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');
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $areaRepo = new \repositories\AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venue->setAreaId($area->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $venueDuplicate = new VenueModel();
     $venueDuplicate->setTitle("test Duplicate");
     $venueRepo->create($venueDuplicate, $site, $user);
     \TimeSource::mock(2014, 10, 1, 1, 2, 0);
     $venueRepo->markDuplicate($venueDuplicate, $venue, $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->setVenueId($venue->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ## Test
     $this->assertNotNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue->getId(), $event->getVenueId());
     ## Now Purge!
     $venueRepo->purge($venue);
     ## Test
     $this->assertNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertNull($event->getVenueId());
 }
 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()));
 }
 protected function build($slug, Request $request, Application $app)
 {
     global $CONFIG;
     $this->parameters = array('country' => null, 'area' => null, 'parentAreas' => array(), 'childAreas' => array(), 'venueIsDuplicateOf' => null);
     if (strpos($slug, "-")) {
         $slug = array_shift(explode("-", $slug, 2));
     }
     $vr = new VenueRepository();
     $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['venue']) {
         return false;
     }
     if ($this->parameters['venue']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['venue']->getCountryID());
     }
     if ($this->parameters['venue']->getAreaId()) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($this->parameters['venue']->getAreaId());
         if (!$this->parameters['area']) {
             return false;
         }
         $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
         while ($checkArea) {
             array_unshift($this->parameters['parentAreas'], $checkArea);
             $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
         }
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setSite($app['currentSite']);
         $areaRepoBuilder->setCountry($this->parameters['country']);
         $areaRepoBuilder->setParentArea($this->parameters['area']);
         $areaRepoBuilder->setIncludeDeleted(false);
         $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     } else {
         $areaRepoBuilder = new AreaRepositoryBuilder();
         $areaRepoBuilder->setSite($app['currentSite']);
         $areaRepoBuilder->setCountry($this->parameters['country']);
         $areaRepoBuilder->setNoParentArea(true);
         $areaRepoBuilder->setIncludeDeleted(false);
         $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     }
     if ($this->parameters['venue']->getIsDuplicateOfId()) {
         $this->parameters['venueIsDuplicateOf'] = $vr->loadByID($this->parameters['venue']->getIsDuplicateOfId());
     }
     $app['currentUserActions']->set("org.openacalendar", "venueHistory", true);
     $app['currentUserActions']->set("org.openacalendar", "venueEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "venueDelete", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "venueEditMedia", $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted() && $CONFIG->isFileStore());
     $app['currentUserActions']->set("org.openacalendar", "venueEditPushToChildAreas", $this->parameters['childAreas'] && $app['currentUserPermissions']->hasPermission("org.openacalendar", "VENUES_CHANGE") && $app['currentSite']->getIsFeaturePhysicalEvents() && !$this->parameters['venue']->getIsDeleted());
     return true;
 }
 function 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($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('area' => null, 'parentarea' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $ar = new AreaRepository();
     $this->parameters['area'] = $ar->loadBySlug($this->parameters['site'], $slug);
     if (!$this->parameters['area']) {
         $app->abort(404);
     }
     $this->parameters['areaisduplicateof'] = $this->parameters['area']->getIsDuplicateOfId() ? $ar->loadById($this->parameters['area']->getIsDuplicateOfId()) : null;
     if ($this->parameters['area']->getParentAreaId()) {
         $this->parameters['parentarea'] = $ar->loadById($this->parameters['area']->getParentAreaId());
     }
     $cr = new CountryRepository();
     $this->parameters['country'] = $this->parameters['area']->getCountryId() ? $cr->loadById($this->parameters['area']->getCountryId()) : null;
 }
 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($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;
 }
 protected function build($countryCode, $areaSlug, $venueSlug, Request $request, Application $app)
 {
     $this->parameters = array('country' => null, 'area' => null, 'venue' => null);
     if ($areaSlug) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $areaSlug);
     }
     if ($this->parameters['area']) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID());
     } else {
         if ($countryCode) {
             $cr = new CountryRepository();
             $this->parameters['country'] = $cr->loadByTwoCharCode($countryCode);
         }
     }
     if ($venueSlug) {
         $vr = new VenueRepository();
         $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $venueSlug);
     }
     return true;
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array('country' => null, 'parentAreas' => array(), 'areaIsDuplicateOf' => null);
     if (strpos($slug, "-")) {
         $slug = array_shift(explode("-", $slug, 2));
     }
     $ar = new AreaRepository();
     $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['area']) {
         return false;
     }
     $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
     while ($checkArea) {
         array_unshift($this->parameters['parentAreas'], $checkArea);
         $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
     }
     if ($app['currentUser']) {
         $uwgr = new UserWatchesAreaRepository();
         $uwg = $uwgr->loadByUserAndArea($app['currentUser'], $this->parameters['area']);
         $this->parameters['currentUserWatchesArea'] = $uwg && $uwg->getIsWatching();
     }
     $cr = new CountryRepository();
     $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID());
     $areaRepoBuilder = new AreaRepositoryBuilder();
     $areaRepoBuilder->setSite($app['currentSite']);
     $areaRepoBuilder->setCountry($this->parameters['country']);
     $areaRepoBuilder->setParentArea($this->parameters['area']);
     $areaRepoBuilder->setIncludeDeleted(false);
     $this->parameters['childAreas'] = $areaRepoBuilder->fetchAll();
     if ($this->parameters['area']->getIsDuplicateOfId()) {
         $this->parameters['areaIsDuplicateOf'] = $ar->loadByID($this->parameters['area']->getIsDuplicateOfId());
     }
     $app['currentUserActions']->set("org.openacalendar", "areaHistory", true);
     $app['currentUserActions']->set("org.openacalendar", "actionAreaEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "AREAS_CHANGE") && !$this->parameters['area']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "actionAreaNew", $app['currentUserPermissions']->hasPermission("org.openacalendar", "AREAS_CHANGE") && !$this->parameters['area']->getIsDeleted());
     return true;
 }
 function 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 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 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 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 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 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);
 }