/**
  * @return BaseUserWatchesNotifyContent|null
  */
 public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel)
 {
     global $CONFIG;
     $userWatchesSite = $this->loadByUserAndSite($userAccountModel, $siteModel);
     if ($userWatchesSite && $userWatchesSite->getIsWatching()) {
         $dateSince = $userWatchesSite->getSinceDateForNotifyChecking();
         $checkTime = \TimeSource::getDateTime();
         $historyRepositoryBuilder = new HistoryRepositoryBuilder();
         $historyRepositoryBuilder->setSite($siteModel);
         $historyRepositoryBuilder->setSince($dateSince);
         $historyRepositoryBuilder->setNotUser($userAccountModel);
         // Only admins can change tags at the moment so don't include
         $historyRepositoryBuilder->setIncludeTagHistory(false);
         $histories = $historyRepositoryBuilder->fetchAll();
         if ($histories) {
             $content = new UserWatchesSiteNotifyContent();
             $content->setHistories($histories);
             $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository();
             $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($userAccountModel, $siteModel);
             $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesSiteStop->getAccessKey());
             $content->setUserAccount($userAccountModel);
             $content->setSite($siteModel);
             $content->setWatchedThingTitle($siteModel->getTitle());
             $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/history');
             return $content;
         }
     }
 }
 /**
  * @return array
  */
 public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel)
 {
     global $CONFIG;
     $out = array();
     $grb = new AreaRepositoryBuilder();
     $grb->setSite($siteModel);
     $grb->setLimit(0);
     // all! No limit
     // TODO  don't we still want to do this? How will user A get a notification if user B deletes area? but then so far most area deletetions are by admins.
     $grb->setIncludeDeleted(false);
     foreach ($grb->fetchAll() as $area) {
         $uwg = $this->loadByUserAndArea($userAccountModel, $area);
         if ($uwg && $uwg->getIsWatching()) {
             $dateSince = $uwg->getSinceDateForNotifyChecking();
             $historyRepositoryBuilder = new HistoryRepositoryBuilder();
             $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setArea($area);
             $historyRepositoryBuilder->setSince($dateSince);
             $historyRepositoryBuilder->setNotUser($userAccountModel);
             // Only admins can change tags at the moment so don't include
             $historyRepositoryBuilder->setIncludeTagHistory(false);
             $histories = $historyRepositoryBuilder->fetchAll();
             if ($histories) {
                 $content = new UserWatchesAreaNotifyContent();
                 $content->setHistories($histories);
                 $userWatchesAreaStopRepository = new UserWatchesAreaStopRepository();
                 $userWatchesAreaStop = $userWatchesAreaStopRepository->getForUserAndArea($userAccountModel, $area);
                 $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesAreaStop->getAccessKey());
                 $content->setUserAccount($userAccountModel);
                 $content->setSite($siteModel);
                 $content->setArea($area);
                 $content->setWatchedThingTitle($area->getTitle());
                 $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/area/' . $area->getSlugForURL() . '/history');
                 $out[] = $content;
             }
         }
     }
     return $out;
 }
 function testIntegration2()
 {
     \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 tag
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $tag = new TagModel();
     $tag->setTitle("test");
     $tag->setDescription("test test");
     $tagRepo = new TagRepository();
     $tagRepo->create($tag, $site, $user);
     ## Delete tag
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $tag = $tagRepo->loadById($tag->getId());
     $tagRepo->delete($tag, $user);
     ## Now save changed flags on these .....
     $tagHistoryRepo = new TagHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM tag_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $tagHistory = new TagHistoryModel();
         $tagHistory->setFromDataBaseRow($data);
         $tagHistoryRepo->ensureChangedFlagsAreSet($tagHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setTag($tag);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $historyRepo->setIncludeTagHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the Delete
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }