/**
  * @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;
 }
 public function testGetNewAndHistoriesForContentsToSendSame()
 {
     global $app;
     // Create 2 seperate objects in memory because that is how it might happen in the app ...
     // but they represent the same piece of data!
     $historydata = array('event_id' => 1, 'summary' => null, 'description' => null, 'start_at' => null, 'end_at' => null, 'created_at' => '2014-01-01 10:10:10', 'is_deleted' => null, 'is_cancelled' => null, 'country_id' => null, 'timezone' => null, 'venue_id' => null, 'url' => null, 'ticket_url' => null, 'is_virtual' => null, 'is_physical' => null, 'area_id' => null, 'user_account_id' => null, 'summary_changed' => '-1', 'description_changed' => '1', 'start_at_changed' => '-1', 'end_at_changed' => '-1', 'is_deleted_changed' => '-1', 'country_id_changed' => '-1', 'timezone_changed' => '-1', 'venue_id_changed' => '-1', 'url_changed' => '-1', 'is_virtual_changed' => '-1', 'is_physical_changed' => '-1', 'area_id_changed' => '-1', 'is_new' => '-1', 'custom_fields' => null, 'custom_fields_changed' => null);
     $eventHistoryModel1 = new \models\EventHistoryModel();
     $eventHistoryModel1->setFromDataBaseRow($historydata);
     $content1 = new UserWatchesAreaNotifyContent();
     $content1->setWatchedThingTitle("Edinburgh");
     $content1->setHistories(array($eventHistoryModel1));
     $eventHistoryModel2 = new \models\EventHistoryModel();
     $eventHistoryModel2->setFromDataBaseRow($historydata);
     $content2 = new UserWatchesAreaNotifyContent();
     $content2->setWatchedThingTitle("Edinburgh");
     $content2->setHistories(array($eventHistoryModel2));
     $task = new TestSendUserWatchesNotifyTask($app);
     list($newThings, $histories) = $task->testGetNewAndHistoriesForContentsToSend(array($content1, $content2));
     $this->assertEquals(1, count($histories));
     $eventHistorModel = $histories[0];
     $this->assertEquals(1, $eventHistorModel->getId());
     $this->assertEquals("2014-01-01T10:10:10+00:00", $eventHistorModel->getCreatedAt()->format("c"));
 }