private function loadGroupIfNeeded()
 {
     if (!$this->group && property_exists($this->data, 'group') && $this->data->group) {
         $repo = new GroupRepository();
         $this->group = $repo->loadById($this->data->group);
     }
 }
 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->group->setTitleIfDifferent($ourRequest->getGetOrPostString('title', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('description') && $this->group->setDescriptionIfDifferent($ourRequest->getGetOrPostString('description', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('url') && $this->group->setUrlIfDifferent($ourRequest->getGetOrPostString('url', ''))) {
         $edits = true;
     }
     if ($edits) {
         $repo = new GroupRepository();
         $repo->edit($this->group, $app['apiUser']);
         $out = array('edited' => true);
     } else {
         $out = array('edited' => false);
     }
     return json_encode($out);
 }
 function test1()
 {
     $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);
     $this->checkGroupInTest1($groupRepo->loadById($group->getId()));
     $this->checkGroupInTest1($groupRepo->loadBySlug($site, $group->getSlug()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('test');
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('cats');
     $this->assertEquals(0, count($grb->fetchAll()));
 }
 function test1()
 {
     TimeSource::mock(2014, 5, 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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventDupe = new EventModel();
     $eventDupe->setSummary("test");
     $eventDupe->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $eventDupe->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     $eventRepository->create($eventDupe, $site, $user, $group);
     TimeSource::mock(2014, 5, 1, 7, 1, 0);
     $eventRepository->markDuplicate($eventDupe, $event);
     $userAtEvent = new \models\UserAtEventModel();
     $userAtEvent->setEventId($event->getId());
     $userAtEvent->setUserAccountId($user->getId());
     $userAtEvent->setIsPlanAttending(true);
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $userAtEventRepo->create($userAtEvent);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $tag = new TagModel();
     $tag->setTitle("Test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $tagRepo->addTagToEvent($tag, $event, $user);
     ## TEST
     $this->assertNotNull($eventRepository->loadBySlug($site, $event->getSlug()));
     ## PURGE!
     $eventRepository->purge($event);
     ## TEST
     $this->assertNull($eventRepository->loadBySlug($site, $event->getSlug()));
 }
 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 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());
 }
 function testIntegration1()
 {
     \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());
     ## Create group
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Edit group
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $group = $groupRepo->loadById($group->getId());
     $group->setTwitterUsername("testy");
     $groupRepo->edit($group, $user);
     ## Now save changed flags on these .....
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setGroup($group);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getUrlChanged());
     $this->assertEquals(true, $histories[0]->getTwitterUsernameChanged());
     $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]->getUrlChanged());
     $this->assertEquals(false, $histories[1]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->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/Lanyrd1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $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("State of the Map Scotland 2013", $event->getSummary());
     $this->assertEquals('2013-10-11 00:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-14 23:59:59', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("http://sotms.eventbrite.com/\n\nhttp://lanyrd.com/crkmt", $event->getDescription());
     $this->assertEquals('http://lanyrd.com/2013/sotmscot2013/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
     // Look for event
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setImportURL($importURL);
     $this->assertEquals(1, count($erb->fetchAll()));
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->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/Eventbrite1.ical');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $importURLRun->setFlag(ImportURLRun::$FLAG_SET_TICKET_URL_AS_URL);
     $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("Computing At School Scotland Conference 2013", $event->getSummary());
     $this->assertEquals('2013-10-26 07:30:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-26 16:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('For details, click here: https://casscot13.eventbrite.co.uk', $event->getDescription());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getURL());
     $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getTicketURL());
     $this->assertFalse($event->getIsDeleted());
 }
 function testBasic()
 {
     global $CONFIG;
     \TimeSource::mock(2013, 10, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000;
     // 90 days
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->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/Meetup1.ics');
     $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS);
     $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("Talk & Build AngularJS", $event->getSummary());
     $this->assertEquals('2013-10-17 18:00:00', $event->getStartAt()->format('Y-m-d H:i:s'));
     $this->assertEquals('2013-10-17 21:00:00', $event->getEndAt()->format('Y-m-d H:i:s'));
     $this->assertEquals("AngularJS - Edinburgh\nThursday, October 17 at 7:00 PM\n\nDetails: http://www.meetup.com/AngularJS-Edinburgh/events/141654792/", $event->getDescription());
     $this->assertEquals('http://www.meetup.com/AngularJS-Edinburgh/events/141654792/', $event->getURL());
     $this->assertFalse($event->getIsDeleted());
 }
 function testEventAndNotEvent1()
 {
     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());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $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);
     ## Test event not in group
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     ## Add event to group, test
     $groupRepo->addEventToGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     ## remove event from group
     $groupRepo->removeEventFromGroup($event, $group, $user);
     $grb = new GroupRepositoryBuilder();
     $grb->setEvent($event);
     $this->assertEquals(0, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setNotEvent($event);
     $this->assertEquals(1, count($grb->fetchAll()));
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array();
     if (strpos($slug, "-") > 0) {
         $slugBits = explode("-", $slug, 2);
         $slug = $slugBits[0];
     }
     $gr = new GroupRepository();
     $this->parameters['group'] = $gr->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['group']) {
         return false;
     }
     return true;
 }
 function newGroup(Request $request, Application $app)
 {
     $group = new GroupModel();
     $form = $app['form.factory']->create(new GroupNewForm($request->query->get('title')), $group);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $groupRepository = new GroupRepository();
             $groupRepository->create($group, $app['currentSite'], $app['currentUser']);
             return $app->redirect("/group/" . $group->getSlugForUrl());
         }
     }
     return $app['twig']->render('site/groupnew/new.html.twig', array('form' => $form->createView()));
 }
 function test1()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOther = new UserAccountModel();
     $userOther->setEmail("*****@*****.**");
     $userOther->setUsername("test2");
     $userOther->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userOther);
     $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);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEditorToCuratedList($userOther, $curatedList, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group, $curatedList, $user);
     ## Test
     $this->assertNotNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
     ## Purge!
     $clRepo->purge($curatedList);
     ## Test
     $this->assertNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
 }
 protected function build($slug, $gslug, Request $request, Application $app)
 {
     $this->parameters = array();
     $curatedlistRepository = new CuratedListRepository();
     $this->parameters['curatedlist'] = $curatedlistRepository->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['curatedlist']) {
         return false;
     }
     $groupRepository = new GroupRepository();
     $this->parameters['group'] = $groupRepository->loadBySlug($app['currentSite'], $gslug);
     if (!$this->parameters['group']) {
         return false;
     }
     $this->parameters['currentUserCanEditCuratedList'] = $this->parameters['curatedlist']->canUserEdit($app['currentUser']);
     return true;
 }
 function onThisStepProcessPage()
 {
     if ($this->request->request->get('action') == 'nogroup') {
         $this->draftEvent->setDetailsValue('group.none', true);
         $this->isAllInformationGathered = true;
         return true;
     }
     if ($this->request->request->get('action') == 'selectgroup') {
         $gr = new GroupRepository();
         $group = $gr->loadBySlug($this->site, $this->request->request->get('group'));
         if ($group) {
             $this->draftEvent->setDetailsValue('group.id', $group->getId());
             $this->draftEvent->setDetailsValue('group.title', $group->getTitle());
             $this->isAllInformationGathered = true;
             return true;
         }
     }
 }
 function newGroup(Request $request, Application $app)
 {
     /////////////////////////////////////////////////////// Check Permissions and Prompt IF NEEDED
     if (!$app['currentUser'] && !$app['currentUserActions']->has("org.openacalendar", "groupNew") && $app['anyVerifiedUserActions']->has("org.openacalendar", "groupNew")) {
         return $app['twig']->render('site/groupnew/new.useraccountneeded.html.twig', array());
     }
     /////////////////////////////////////////////////////// Carry On
     $group = new GroupModel();
     $form = $app['form.factory']->create(new GroupNewForm($request->query->get('title')), $group);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $groupRepository = new GroupRepository();
             $groupRepository->create($group, $app['currentSite'], $app['currentUser']);
             return $app->redirect("/group/" . $group->getSlugForUrl());
         }
     }
     return $app['twig']->render('site/groupnew/new.html.twig', array('form' => $form->createView()));
 }
 function index($siteid, $slug, Request $request, Application $app)
 {
     global $CONFIG;
     $this->build($siteid, $slug, $request, $app);
     $form = $app['form.factory']->create(new ActionForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $action = new ActionParser($data['action']);
             if ($action->getCommand() == 'delete' && !$this->parameters['group']->getIsDeleted()) {
                 $gr = new GroupRepository();
                 $gr->delete($this->parameters['group'], $app['currentUser']);
                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/group/' . $this->parameters['group']->getSlug());
             } else {
                 if ($action->getCommand() == 'undelete' && $this->parameters['group']->getIsDeleted()) {
                     $this->parameters['group']->setIsDeleted(false);
                     $gr = new GroupRepository();
                     $gr->undelete($this->parameters['group'], $app['currentUser']);
                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/group/' . $this->parameters['group']->getSlug());
                 } else {
                     if ($action->getCommand() == 'isduplicateof') {
                         $gr = new GroupRepository();
                         $originalGroup = $gr->loadBySlug($this->parameters['site'], $action->getParam(0));
                         if ($originalGroup && $originalGroup->getId() != $this->parameters['group']->getId()) {
                             $gr->markDuplicate($this->parameters['group'], $originalGroup, $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/group/' . $this->parameters['group']->getSlug());
                         }
                     } else {
                         if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeGroupPassword && $CONFIG->sysAdminExtraPurgeGroupPassword == $action->getParam(0)) {
                             $gr = new GroupRepository();
                             $gr->purge($this->parameters['group']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/group/');
                         }
                     }
                 }
             }
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/group/index.html.twig', $this->parameters);
 }
 function test1()
 {
     $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);
     $importURLRepository = new ImportURLRepository();
     $newImportURL = new ImportURLModel();
     $newImportURL->setIsEnabled(true);
     $newImportURL->setSiteId($site->getId());
     $newImportURL->setGroupId($group->getId());
     $newImportURL->setTitle("Test");
     $newImportURL->setUrl("http://test.com");
     # no clash
     $clash = $importURLRepository->loadClashForImportUrl($newImportURL);
     $this->assertNull($clash);
     # save import, now clash!
     $importURLRepository->create($newImportURL, $site, $user);
     $newImportURL2 = new ImportURLModel();
     $newImportURL2->setIsEnabled(true);
     $newImportURL2->setSiteId($site->getId());
     $newImportURL2->setGroupId($group->getId());
     $newImportURL2->setTitle("Test.com site");
     $newImportURL2->setUrl("http://TEST.com");
     # no clash
     $clash = $importURLRepository->loadClashForImportUrl($newImportURL2);
     $this->assertTrue($clash != 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());
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $user1 = new UserAccountModel();
     $user1->setEmail("*****@*****.**");
     $user1->setUsername("test");
     $user1->setPassword("password");
     $user2 = new UserAccountModel();
     $user2->setEmail("*****@*****.**");
     $user2->setUsername("test2");
     $user2->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user1);
     $userRepo->create($user2);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user1, array(), $this->getSiteQuotaUsedForTesting());
     $group1 = new GroupModel();
     $group1->setTitle("test1");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test this looks similar");
     $group2->setDescription("test test");
     $group2->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $groupRepo->create($group1, $site, $user1);
     $groupRepo->create($group2, $site, $user2);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user1, $group2);
     $uwgr = new UserWatchesGroupRepository();
     // Test before
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(0, count($erb->fetchAll()));
     $this->assertNull($uwgr->loadByUserAndGroup($user2, $group1));
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertFalse($group2->getIsDeleted());
     $this->assertNull($group2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $groupRepo->markDuplicate($group2, $group1, $user1);
     // Test Duplicate
     $erb = new \repositories\builders\EventRepositoryBuilder();
     $erb->setGroup($group1);
     $this->assertEquals(1, count($erb->fetchAll()));
     $uwg = $uwgr->loadByUserAndGroup($user2, $group1);
     $this->assertNotNull($uwg);
     $group2 = $groupRepo->loadById($group2->getId());
     $this->assertTrue($group2->getIsDeleted());
     $this->assertEquals($group1->getId(), $group2->getIsDuplicateOfId());
 }
 function testMultiple()
 {
     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());
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("cat");
     $group2->setDescription("cat cat");
     $group2->setUrl("http://www.cat.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group1, array($group1, $group2));
     // Check groups
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(2, count($groups));
 }
 function testMultiple()
 {
     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());
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupDupe = new GroupModel();
     $groupDupe->setTitle("test DUPE");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     $groupRepo->create($groupDupe, $site, $user);
     TimeSource::mock(2013, 7, 1, 7, 1, 0);
     $groupRepo->markDuplicate($groupDupe, $group);
     $ufgr = new UserWatchesGroupRepository();
     $ufgr->startUserWatchingGroupIdIfNotWatchedBefore($user, $group->getId());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2013, 8, 1, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2013, 8, 1, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     ## TEST
     $this->assertNotNull($groupRepo->loadById($group->getId()));
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(1, count($groups));
     ## PURGE!
     $groupRepo->purge($group);
     ## TEST
     $this->assertNull($groupRepo->loadById($group->getId()));
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($event);
     $groups = $groupRB->fetchAll();
     $this->assertEquals(0, count($groups));
 }
 public static function run(Application $app, $verbose = false)
 {
     global $CONFIG;
     if ($verbose) {
         print "Starting " . date("c") . "\n";
     }
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $groupRepo = new GroupRepository();
     $eventRepo = new EventRepository();
     $userWatchesGroupRepository = new UserWatchesGroupRepository();
     $userWatchesGroupStopRepository = new UserWatchesGroupStopRepository();
     $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository();
     $userNotificationRepo = new UserNotificationRepository();
     $userHasNoEditorPermissionsInSiteRepo = new UserHasNoEditorPermissionsInSiteRepository();
     $userPermissionsRepo = new UserPermissionsRepository($app['extensions']);
     /** @var usernotifications/UserWatchesGroupPromptNotificationType **/
     $userNotificationType = $app['extensions']->getCoreExtension()->getUserNotificationType('UserWatchesGroupPrompt');
     $b = new UserWatchesGroupRepositoryBuilder();
     foreach ($b->fetchAll() as $userWatchesGroup) {
         $user = $userRepo->loadByID($userWatchesGroup->getUserAccountId());
         $group = $groupRepo->loadById($userWatchesGroup->getGroupId());
         $site = $siteRepo->loadById($group->getSiteID());
         // This is not the most efficient as it involves DB access and the results might not be used. But it'll do for now.
         $userPermissions = $userPermissionsRepo->getPermissionsForUserInSite($user, $site, false, true);
         if ($verbose) {
             print date("c") . " User " . $user->getEmail() . " Site " . $site->getTitle() . " Group " . $group->getTitle() . "\n";
         }
         // UserWatchesGroupRepositoryBuilder() should only return instances where site is not also watched
         if ($site->getIsClosedBySysAdmin()) {
             if ($verbose) {
                 print " ... site is closed\n";
             }
         } else {
             if ($group->getIsDeleted()) {
                 if ($verbose) {
                     print " ... group is deleted\n";
                 }
             } else {
                 if ($userHasNoEditorPermissionsInSiteRepo->isUserInSite($user, $site)) {
                     if ($verbose) {
                         print " ... user does not have edit permissions allowed in site\n";
                     }
                 } else {
                     if (!$userPermissions->hasPermission("org.openacalendar", "CALENDAR_CHANGE")) {
                         if ($verbose) {
                             print " ... user does not have org.openacalendar/CALENDAR_CHANGE permission in site\n";
                         }
                         // Technically UserWatchesSiteRepositoryBuilder() should only return getIsWatching() == true but lets double check
                     } else {
                         if ($userWatchesGroup->getIsWatching()) {
                             if ($verbose) {
                                 print " ... searching for data\n";
                             }
                             $lastEvent = $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId());
                             $data = $userWatchesGroup->getPromptEmailData($site, $lastEvent);
                             if ($data['moreEventsNeeded']) {
                                 if ($verbose) {
                                     print " ... found data\n";
                                 }
                                 ///// Notification Class
                                 $userNotification = $userNotificationType->getNewNotification($user, $site);
                                 $userNotification->setGroup($group);
                                 ////// Save Notification Class
                                 $userNotificationRepo->create($userNotification);
                                 ////// Send Email
                                 if ($userNotification->getIsEmail()) {
                                     $userWatchesGroupStop = $userWatchesGroupStopRepository->getForUserAndGroup($user, $group);
                                     configureAppForSite($site);
                                     configureAppForUser($user);
                                     $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user);
                                     $unsubscribeURL = $CONFIG->getWebIndexDomainSecure() . '/you/emails/' . $user->getId() . '/' . $userAccountGeneralSecurityKey->getAccessKey();
                                     $lastEventsBuilder = new EventRepositoryBuilder();
                                     $lastEventsBuilder->setSite($site);
                                     $lastEventsBuilder->setGroup($group);
                                     $lastEventsBuilder->setOrderByStartAt(true);
                                     $lastEventsBuilder->setIncludeDeleted(false);
                                     $lastEventsBuilder->setIncludeImported(false);
                                     $lastEventsBuilder->setLimit($CONFIG->userWatchesGroupPromptEmailShowEvents);
                                     $lastEvents = $lastEventsBuilder->fetchAll();
                                     $message = \Swift_Message::newInstance();
                                     $message->setSubject("Any news about " . $group->getTitle() . "?");
                                     $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName));
                                     $message->setTo($user->getEmail());
                                     $messageText = $app['twig']->render('email/userWatchesGroupPromptEmail.txt.twig', array('group' => $group, 'user' => $user, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL));
                                     if ($CONFIG->isDebug) {
                                         file_put_contents('/tmp/userWatchesGroupPromptEmail.txt', $messageText);
                                     }
                                     $message->setBody($messageText);
                                     $messageHTML = $app['twig']->render('email/userWatchesGroupPromptEmail.html.twig', array('group' => $group, 'user' => $user, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL));
                                     if ($CONFIG->isDebug) {
                                         file_put_contents('/tmp/userWatchesGroupPromptEmail.html', $messageHTML);
                                     }
                                     $message->addPart($messageHTML, 'text/html');
                                     $headers = $message->getHeaders();
                                     $headers->addTextHeader('List-Unsubscribe', $unsubscribeURL);
                                     if ($verbose) {
                                         print " ... sending\n";
                                     }
                                     if (!$CONFIG->isDebug) {
                                         $app['mailer']->send($message);
                                     }
                                     $userNotificationRepo->markEmailed($userNotification);
                                 }
                                 $userWatchesGroupRepository->markPromptEmailSent($userWatchesGroup, $data['checkTime']);
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($verbose) {
         print "Finished " . date("c") . "\n";
     }
 }
 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 testAddSet()
 {
     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());
     $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));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $group1 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test2");
     $group2->setDescription("test 2");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     ## Add event to group1, test
     $groupRepo->addEventToGroup($event, $group1, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## Add event to group2, test group1 is still main group
     $groupRepo->addEventToGroup($event, $group2, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## set main group to group2, test
     $groupRepo->setMainGroupForEvent($group2, $event, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group2->getId(), $event->getGroupId());
     $this->assertEquals("test2", $event->getGroupTitle());
 }
 function testRRuleDeleteByExDate1()
 {
     global $CONFIG;
     \TimeSource::mock(2015, 1, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000;
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->getId());
     $importURL->setTitle("Test");
     $importURL->setUrl("http://test.com");
     $importURLRepository->create($importURL, $site, $user);
     // ============================================= Import CREATE
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     \TimeSource::mock(2015, 1, 2, 1, 1, 1);
     // ============================================= Import With no changes
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     \TimeSource::mock(2015, 1, 3, 1, 1, 1);
     // ============================================= Import WITH ONE DELETED!
     $importURLRun = new ImportURLRun($importURL, $site);
     $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part2.ics');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(7);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Is it loaded on Imported Events?
     $ierb = new \repositories\builders\ImportedEventRepositoryBuilder();
     $importedEvents = $ierb->fetchAll();
     $this->assertEquals(1, count($importedEvents));
     $importedEvent = $importedEvents[0];
     $reoccur = $importedEvent->getReoccur();
     $this->assertEquals(true, is_array($reoccur));
     $this->assertEquals(true, isset($reoccur['ical_rrule']));
     $this->assertEquals(true, is_array($reoccur['ical_rrule']));
     $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]);
     $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]);
     // now test real events
     $erb = new EventRepositoryBuilder();
     $erb->setImportedEvent($importedEvent);
     $erb->setAfterNow();
     $erb->setIncludeDeleted(true);
     $events = $erb->fetchAll();
     $this->assertTrue(count($events) > 5);
     $event = $events[0];
     $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
     $event = $events[1];
     $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertTrue($event->getIsDeleted());
     $event = $events[2];
     $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c"));
     $this->assertFalse($event->getIsDeleted());
 }
 function testUserWatchingGroupsWithAnEventInTwoGroups()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $groupRepo = new GroupRepository();
     $eventRepository = new EventRepository();
     $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
     $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);
     $userWatchesOther = new UserAccountModel();
     $userWatchesOther->setEmail("*****@*****.**");
     $userWatchesOther->setUsername("test2");
     $userWatchesOther->setPassword("password1");
     $userRepo->create($userWatchesOther);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo->create($site, $user, array($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $groupMain = new GroupModel();
     $groupMain->setTitle("test");
     $groupRepo->create($groupMain, $site, $user);
     $groupOther = new GroupModel();
     $groupOther->setTitle("test");
     $groupRepo->create($groupOther, $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, $groupMain, array($groupOther));
     // 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));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, false);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
     // test watching main group gets event
     $userWatchesGroupRepo->startUserWatchingGroup($userWatchesMain, $groupMain);
     $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));
     // test watching other group gets event
     $userWatchesGroupRepo->startUserWatchingGroup($userWatchesOther, $groupOther);
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, true);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $erb = new EventRepositoryBuilder();
     $erb->setUserAccount($userWatchesOther, false, true, true, false);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
 }
 function testIsGroupRunningOutOfFutureEvents()
 {
     \TimeSource::mock(2014, 1, 1, 1, 1, 1);
     $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");
     $site->setPromptEmailsDaysInAdvance(28);
     $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);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 4, 1, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 4, 1, 21, 0, 0, 'Europe/London'));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     ### TEST
     \TimeSource::mock(2014, 2, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 2, 15, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 2, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 3, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 4, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 5, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 6, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 7, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 20, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 1, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 15, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 5, 1, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
 }
 function testLimits()
 {
     global $CONFIG;
     \TimeSource::mock(2012, 9, 1, 1, 1, 1);
     $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000;
     $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);
     $importURLRepository = new ImportURLRepository();
     $importURL = new ImportURLModel();
     $importURL->setIsEnabled(true);
     $importURL->setSiteId($site->getId());
     $importURL->setGroupId($group->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/ICALManyEvents.ical');
     $i = new ImportURLICalHandler();
     $i->setImportURLRun($importURLRun);
     $i->setLimitToSaveOnEachRun(2);
     $this->assertTrue($i->canHandle());
     $r = $i->handle();
     // Load!
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $events = $erb->fetchAll();
     $this->assertEquals(2, count($events));
 }