function index($slug, $id, Request $request, Application $app)
 {
     if (!$this->buildEvent($slug, $id, $request, $app)) {
         $app->abort(404, "Import does not exist.");
     }
     if ($this->parameters['importedEvent']->hasReoccurence()) {
         $this->parameters['importedEventReoccurs'] = true;
         $this->parameters['eventListFilterParams'] = new EventFilterParams();
         // set some defaults that are different from normal
         $this->parameters['eventListFilterParams']->setIncludeDeleted(true);
         $this->parameters['eventListFilterParams']->setFromNow(false);
         // now carry on ...
         $this->parameters['eventListFilterParams']->set($_GET);
         $this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->setSite($app['currentSite']);
         $this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->setIncludeAreaInformation(true);
         $this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->setIncludeVenueInformation(true);
         // Technically we should be able to do this ... but to keep the UI simple, lets not.
         //if ($app['currentUser'])) {
         //	$this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->setUserAccount($app['currentUser'], true);
         //}
         $this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->setImportedEvent($this->parameters['importedEvent']);
         $this->parameters['events'] = $this->parameters['eventListFilterParams']->getEventRepositoryBuilder()->fetchAll();
         $this->parameters['event'] = null;
     } else {
         $this->parameters['importedEventReoccurs'] = false;
         $this->parameters['eventListFilterParams'] = null;
         $this->parameters['events'] = null;
         $eventRepo = new EventRepository();
         $this->parameters['event'] = $eventRepo->loadByImportedEvent($this->parameters['importedEvent']);
     }
     return $app['twig']->render('site/importurlimportedevent/index.html.twig', $this->parameters);
 }
 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('summary') && $this->event->setSummaryIfDifferent($ourRequest->getGetOrPostString('summary', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('description') && $this->event->setDescriptionIfDifferent($ourRequest->getGetOrPostString('description', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('url') && $this->event->setUrlIfDifferent($ourRequest->getGetOrPostString('url', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('ticket_url') && $this->event->setTicketUrlIfDifferent($ourRequest->getGetOrPostString('ticket_url', ''))) {
         $edits = true;
     }
     if ($edits) {
         $repo = new EventRepository();
         $repo->edit($this->event, $app['apiUser']);
         $out = array('edited' => true);
     } else {
         $out = array('edited' => false);
     }
     return json_encode($out);
 }
 protected function build($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('user' => null, 'eventCreated' => null, 'eventDupe' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $repo = new NewEventDraftRepository();
     $this->parameters['draft'] = $repo->loadBySlugForSite($slug, $this->parameters['site']);
     if (!$this->parameters['draft']) {
         $app->abort(404);
     }
     if ($this->parameters['draft']->getUserAccountId()) {
         $ur = new UserAccountRepository();
         $this->parameters['user'] = $ur->loadByID($this->parameters['draft']->getUserAccountId());
     }
     if ($this->parameters['draft']->getEventId()) {
         $er = new EventRepository();
         $this->parameters['eventCreated'] = $er->loadByID($this->parameters['draft']->getEventId());
     }
     if ($this->parameters['draft']->getWasExistingEventId()) {
         $er = new EventRepository();
         $this->parameters['eventDupe'] = $er->loadByID($this->parameters['draft']->getWasExistingEventId());
     }
 }
 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;
 }
 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 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 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()));
 }
 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());
 }
 protected function build($slug, Request $request, Application $app)
 {
     global $CONFIG;
     $this->parameters = array();
     if (strpos($slug, "-")) {
         $slug = array_shift(explode("-", $slug, 2));
     }
     $eventRepository = new EventRepository();
     $this->parameters['event'] = $eventRepository->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['event']) {
         return false;
     }
     return true;
 }
 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));
 }
 function testEventsVanish()
 {
     ## User, Site, Event
     \TimeSource::mock(2014, 1, 1, 1, 2, 3);
     $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(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);
     ## Event can be found
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(true);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(false);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     ## Close Site
     \TimeSource::mock(2014, 2, 1, 1, 2, 3);
     $site->setIsClosedBySysAdmin(true);
     $site->setClosedBySysAdminreason('Testing');
     $siteRepo->edit($site, $user);
     ## Event can not be found
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(true);
     $erb->fetchAll();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setIncludeEventsFromClosedSites(false);
     $erb->fetchAll();
     $this->assertEquals(0, count($erb->fetchAll()));
 }
 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, $eslug, Request $request, Application $app)
 {
     $this->parameters = array();
     $curatedlistRepository = new CuratedListRepository();
     $this->parameters['curatedlist'] = $curatedlistRepository->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['curatedlist']) {
         return false;
     }
     $eventRepository = new EventRepository();
     $this->parameters['event'] = $eventRepository->loadBySlug($app['currentSite'], $eslug);
     if (!$this->parameters['event']) {
         return false;
     }
     $this->parameters['currentUserCanEditCuratedList'] = $this->parameters['curatedlist']->canUserEdit($app['currentUser']);
     return true;
 }
 /**
  * @dataProvider dataForTest1
  */
 function test1($emailOption, $goingOption, $result)
 {
     TimeSource::mock(2013, 8, 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, 2, 19, 0, 0));
     $event->setEndAt($this->mktime(2013, 8, 2, 21, 0, 0));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $user->setEmailUpcomingEventsDaysNotice(1);
     $user->setEmailUpcomingEvents($emailOption);
     $userRepo->editEmailsOptions($user);
     if ($goingOption == 'a') {
         $userAtEvent = new UserAtEventModel();
         $userAtEvent->setUserAccountId($user->getId());
         $userAtEvent->setEventId($event->getId());
         $userAtEvent->setIsPlanAttending(true);
         $uaeRepo = new UserAtEventRepository();
         $uaeRepo->save($userAtEvent);
     } else {
         if ($goingOption == 'm') {
             $userAtEvent = new UserAtEventModel();
             $userAtEvent->setUserAccountId($user->getId());
             $userAtEvent->setEventId($event->getId());
             $userAtEvent->setIsPlanMaybeAttending(true);
             $uaeRepo = new UserAtEventRepository();
             $uaeRepo->save($userAtEvent);
         }
     }
     list($upcomingEvents, $allEvents, $userAtEvent, $flag) = $user->getDataForUpcomingEventsEmail();
     $this->assertEquals($result, $flag);
 }
 function testFreeTextSearch()
 {
     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());
     $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);
     ///////////// Test No Search
     $erb = new EventRepositoryBuilder();
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $this->assertEquals(1, $erb->fetchCount());
     ///////////// Test Search Pass
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("test");
     $this->assertEquals(1, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("test");
     $this->assertEquals(1, $erb->fetchCount());
     ///////////// Test Search Fail
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn");
     $this->assertEquals(0, count($erb->fetchAll()));
     $erb = new EventRepositoryBuilder();
     $erb->setFreeTextsearch("eodueoth dlhtunkn ethh5f 8l79,35dheutn");
     $this->assertEquals(0, $erb->fetchCount());
 }
 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());
     $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);
     $tag = new TagModel();
     $tag->setTitle("Test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     $tagRepo->addTagToEvent($tag, $event, $user);
     ## Test
     $this->assertNotNull($tagRepo->loadById($tag->getId()));
     $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder();
     $tagRepoBuilder->setTagsForEvent($event);
     $this->assertEquals(1, count($tagRepoBuilder->fetchAll()));
     ## Purge!
     $tagRepo->purge($tag);
     ## Test
     $this->assertNull($tagRepo->loadById($tag->getId()));
     $tagRepoBuilder = new repositories\builders\TagRepositoryBuilder();
     $tagRepoBuilder->setTagsForEvent($event);
     $this->assertEquals(0, count($tagRepoBuilder->fetchAll()));
 }
 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, 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()));
 }
 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 testEvent()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     TimeSource::mock(2013, 7, 1, 7, 0, 0);
     $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);
     $this->assertTrue($userRepo->hasMadeAnyEdits($user));
 }
 function delete($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Venue does not exist.");
     }
     if ($this->parameters['venue']->getIsDeleted()) {
         die("No");
         // TODO
     }
     $form = $app['form.factory']->create(new VenueDeleteForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $eventRepository = new EventRepository();
             $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($this->parameters['venue'], $app['currentUser']);
             $venueRepository = new VenueRepository();
             $venueRepository->delete($this->parameters['venue'], $app['currentUser']);
             return $app->redirect("/venue/" . $this->parameters['venue']->getSlugForURL());
         }
     }
     $rb = new EventRepositoryBuilder();
     $rb->setVenue($this->parameters['venue']);
     $rb->setAfterNow(true);
     $rb->setIncludeDeleted(false);
     $this->parameters['events'] = $rb->fetchAll();
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('site/venue/delete.html.twig', $this->parameters);
 }
 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 go()
 {
     $event = new EventModel();
     $event->setSummary($this->summary);
     $event->setDescription($this->description);
     $event->setUrl($this->url);
     $event->setTimezone($this->timezone);
     $event->setStartAt($this->start_at);
     $event->setEndAt($this->end_at);
     $event->setCountryId($this->country->getId());
     $eventRepo = new EventRepository();
     $eventRepo->create($event, $this->site, $this->user, $this->group);
 }
 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 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['curatedlist']->getIsDeleted()) {
                 $clr = new CuratedListRepository();
                 $clr->delete($this->parameters['curatedlist'], $app['currentUser']);
                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
             } else {
                 if ($action->getCommand() == 'undelete' && $this->parameters['curatedlist']->getIsDeleted()) {
                     $clr = new CuratedListRepository();
                     $clr->undelete($this->parameters['curatedlist'], $app['currentUser']);
                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                 } else {
                     if ($action->getCommand() == 'addeditor') {
                         $userRepo = new UserAccountRepository();
                         $user = $userRepo->loadByID($action->getParam(0));
                         if ($user) {
                             $clr = new CuratedListRepository();
                             $clr->addEditorToCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                         }
                     } else {
                         if ($action->getCommand() == 'removeeditor') {
                             $userRepo = new UserAccountRepository();
                             $user = $userRepo->loadByID($action->getParam(0));
                             if ($user) {
                                 $clr = new CuratedListRepository();
                                 $clr->removeEditorFromCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']);
                                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                             }
                         } else {
                             if ($action->getCommand() == 'addevent') {
                                 $eventRepository = new EventRepository();
                                 $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0));
                                 if ($event) {
                                     $clr = new CuratedListRepository();
                                     $clr->addEventtoCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']);
                                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug());
                                 }
                             } else {
                                 if ($action->getCommand() == 'removeevent') {
                                     $eventRepository = new EventRepository();
                                     $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0));
                                     if ($event) {
                                         $clr = new CuratedListRepository();
                                         $clr->removeEventFromCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']);
                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug());
                                     }
                                 } else {
                                     if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeCuratedListPassword && $CONFIG->sysAdminExtraPurgeCuratedListPassword == $action->getParam(0)) {
                                         $clr = new CuratedListRepository();
                                         $clr->purge($this->parameters['curatedlist']);
                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/');
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/curatedlist/index.html.twig', $this->parameters);
 }
 function testWinterTime()
 {
     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());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt($this->mktime(2014, 11, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt($this->mktime(2014, 11, 10, 21, 0, 0, 'Europe/London'));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals("test test", $event->getDescription());
     $this->assertEquals("test", $event->getSummary());
     $startAtShouldBe = $this->mktime(2014, 11, 10, 19, 0, 0, 'UTC');
     $startAtIs = clone $event->getStartAt();
     $startAtIs->setTimezone(new \DateTimeZone('UTC'));
     $this->assertEquals($startAtShouldBe->format("c"), $startAtIs->format("c"));
 }
 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 testAcrossBST1()
 {
     \TimeSource::mock(2015, 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());
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setTimezone('Europe/London');
     $start = new \DateTime("", new \DateTimeZone('Europe/London'));
     $start->setDate(2015, 5, 10);
     $start->setTime(19, 0, 0);
     $event->setStartAt($start);
     $end = new \DateTime("", new \DateTimeZone('Europe/London'));
     $end->setDate(2015, 5, 10);
     $end->setTime(21, 0, 0);
     $event->setEndAt($end);
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $eventRecurSetRepository = new EventRecurSetRepository();
     $eventRecurSet = $eventRecurSetRepository->getForEvent($event);
     $eventRecurSet->setTimeZoneName($event->getTimezone());
     $newStart = new \DateTime();
     $newStart->setDate(2015, 11, 1);
     $newEvent = $eventRecurSet->getNewEventOnArbitraryDate($event, $newStart);
     // What we are really testing here is start and end times set correctly
     $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInUTC()->format("c"));
     $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInUTC()->format("c"));
     $this->assertEquals("2015-11-01T19:00:00+00:00", $newEvent->getStartAtInTimezone()->format("c"));
     $this->assertEquals("2015-11-01T21:00:00+00:00", $newEvent->getEndAtInTimezone()->format("c"));
 }
 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 test1()
 {
     TimeSource::mock(2014, 5, 1, 7, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $user1 = new UserAccountModel();
     $user1->setEmail("*****@*****.**");
     $user1->setUsername("test1");
     $user1->setPassword("password");
     $user2 = new UserAccountModel();
     $user2->setEmail("*****@*****.**");
     $user2->setUsername("test2");
     $user2->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($user1);
     $userRepo->create($user2);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $event1 = new EventModel();
     $event1->setSummary("test");
     $event1->setDescription("test test");
     $event1->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event1->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event1->setUrl("http://www.info.com");
     $event1->setTicketUrl("http://www.tickets.com");
     $event2 = new EventModel();
     $event2->setSummary("test this looks similar");
     $event2->setDescription("test test");
     $event2->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event2->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event2->setUrl("http://www.info.com");
     $event2->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event1, $site, $user);
     $eventRepository->create($event2, $site, $user);
     $userAtEventRepo = new \repositories\UserAtEventRepository();
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user1, $event1);
     $user1AtEvent1->setIsPlanAttending(true);
     $user1AtEvent1->setIsPlanPublic(true);
     $userAtEventRepo->save($user1AtEvent1);
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user1, $event2);
     $user1AtEvent2->setIsPlanMaybeAttending(true);
     $userAtEventRepo->save($user1AtEvent2);
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEventOrInstanciate($user2, $event2);
     $user2AtEvent2->setIsPlanMaybeAttending(true);
     $userAtEventRepo->save($user2AtEvent2);
     //=============================================== Test before
     $event2 = $eventRepository->loadBySlug($site, $event2->getSlug());
     $this->assertFalse($event2->getIsDeleted());
     $this->assertNull($event2->getIsDuplicateOfId());
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user1, $event1);
     $this->assertNotNull($user1AtEvent1);
     $this->assertEquals(true, $user1AtEvent1->getIsPlanAttending());
     $this->assertEquals(false, $user1AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(true, $user1AtEvent1->getIsPlanPublic());
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user1, $event2);
     $this->assertNotNull($user1AtEvent2);
     $this->assertEquals(false, $user1AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user1AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user1AtEvent2->getIsPlanPublic());
     $user2AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user2, $event1);
     $this->assertNull($user2AtEvent1);
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user2, $event2);
     $this->assertNotNull($user2AtEvent2);
     $this->assertEquals(false, $user2AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent2->getIsPlanPublic());
     //==================================================== Mark
     TimeSource::mock(2014, 5, 1, 8, 0, 0);
     $eventRepository->markDuplicate($event2, $event1, $user);
     //==================================================== Test Duplicate
     $event2 = $eventRepository->loadBySlug($site, $event2->getSlug());
     $this->assertTrue($event2->getIsDeleted());
     $this->assertEquals($event1->getId(), $event2->getIsDuplicateOfId());
     // This should not have changed; as there already was data here we don't change it.
     $user1AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user1, $event1);
     $this->assertNotNull($user1AtEvent1);
     $this->assertEquals(true, $user1AtEvent1->getIsPlanAttending());
     $this->assertEquals(false, $user1AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(true, $user1AtEvent1->getIsPlanPublic());
     $user1AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user1, $event2);
     $this->assertNotNull($user1AtEvent2);
     $this->assertEquals(false, $user1AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user1AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user1AtEvent2->getIsPlanPublic());
     // This should now change, the mark dupe function should have copied it.
     $user2AtEvent1 = $userAtEventRepo->loadByUserAndEvent($user2, $event1);
     $this->assertNotNull($user2AtEvent1);
     $this->assertEquals(false, $user2AtEvent1->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent1->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent1->getIsPlanPublic());
     $user2AtEvent2 = $userAtEventRepo->loadByUserAndEvent($user2, $event2);
     $this->assertNotNull($user2AtEvent2);
     $this->assertEquals(false, $user2AtEvent2->getIsPlanAttending());
     $this->assertEquals(true, $user2AtEvent2->getIsPlanMaybeAttending());
     $this->assertEquals(false, $user2AtEvent2->getIsPlanPublic());
 }