function testUserWatchesSite()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userTest = new UserAccountModel();
     $userTest->setEmail("*****@*****.**");
     $userTest->setUsername("testtest");
     $userTest->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userTest);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     // Test user doesn't have it
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(0, count($sites));
     // watch site
     $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository();
     $userWatchesSiteRepo->startUserWatchingSite($userTest, $site);
     // has it!
     $srb = new \repositories\builders\SiteRepositoryBuilder();
     $srb->setUserInterestedIn($userTest);
     $sites = $srb->fetchAll();
     $this->assertEquals(1, count($sites));
 }
 /**
  * @return array BaseUserWatchesNotifyContent
  */
 public function getUserNotifyContents(SiteModel $site, UserAccountModel $userAccountModel)
 {
     $out = array();
     $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository();
     $data = $userWatchesSiteRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
     if ($data) {
         // no point carrying on; someone watching a site overrides any data contained within
         return array($data);
     }
     $siteFeatureRepo = new \repositories\SiteFeatureRepository($this->app);
     if ($siteFeatureRepo->doesSiteHaveFeatureByExtensionAndId($site, 'org.openacalendar', 'Group')) {
         $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
         $data = $userWatchesGroupRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
         if ($data) {
             $out = array_merge($out, $data);
         }
     }
     $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository();
     $data = $userWatchesAreaRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
     if ($data) {
         $out = array_merge($out, $data);
     }
     return $out;
 }
 function testUserWatchingSite()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $groupRepo = new GroupRepository();
     $eventRepository = new EventRepository();
     $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository();
     $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());
     $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);
     // 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
     $userWatchesSiteRepo->startUserWatchingSite($userWatchesMain, $site);
     $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));
 }
 /**
  * @return array BaseUserWatchesNotifyContent
  */
 public function getUserNotifyContents(SiteModel $site, UserAccountModel $userAccountModel)
 {
     $out = array();
     $userWatchesSiteRepo = new \repositories\UserWatchesSiteRepository();
     $data = $userWatchesSiteRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
     if ($data) {
         // no point carrying on; someone watching a site overrides any data contained within
         return array($data);
     }
     if ($site->getIsFeatureGroup()) {
         $userWatchesGroupRepo = new \repositories\UserWatchesGroupRepository();
         $data = $userWatchesGroupRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
         if ($data) {
             $out = array_merge($out, $data);
         }
     }
     $userWatchesAreaRepo = new \repositories\UserWatchesAreaRepository();
     $data = $userWatchesAreaRepo->getUserNotifyContentForSiteAndUser($site, $userAccountModel);
     if ($data) {
         $out = array_merge($out, $data);
     }
     return $out;
 }