function testIntegration1()
 {
     $this->addCountriesToTestDB();
     \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());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     ## Create area
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $area->setCountryId($gb->getId());
     $areaRepo = new AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     ## Edit area
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $area = $areaRepo->loadById($area->getId());
     $area->setDescription("testy");
     $areaRepo->edit($area, $user);
     ## Now save changed flags on these .....
     $areaHistoryRepo = new AreaHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM area_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $areaHistory = new AreaHistoryModel();
         $areaHistory->setFromDataBaseRow($data);
         $areaHistoryRepo->ensureChangedFlagsAreSet($areaHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeAreaHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(true, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(false, $histories[0]->getParentAreaIdChanged());
     $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]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getParentAreaIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 function history(Request $request, Application $app)
 {
     $historyRepositoryBuilder = new HistoryRepositoryBuilder();
     $historyRepositoryBuilder->setVenueVirtualOnly(true);
     $this->parameters['historyItems'] = $historyRepositoryBuilder->fetchAll();
     return $app['twig']->render('site/venuevirtual/history.html.twig', $this->parameters);
 }
 function index(Request $request, Application $app)
 {
     $historyRepositoryBuilder = new HistoryRepositoryBuilder();
     $historyRepositoryBuilder->setSite($app['currentSite']);
     $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setLimit(200);
     return $app['twig']->render('site/history/index.html.twig', array('historyItems' => $historyRepositoryBuilder->fetchAll()));
 }
 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 history($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Venue does not exist.");
     }
     $historyRepositoryBuilder = new HistoryRepositoryBuilder();
     $historyRepositoryBuilder->setVenue($this->parameters['venue']);
     $this->parameters['historyItems'] = $historyRepositoryBuilder->fetchAll();
     return $app['twig']->render('site/venue/history.html.twig', $this->parameters);
 }
 function index(Request $request, Application $app)
 {
     $hrb = new HistoryRepositoryBuilder();
     return $app['twig']->render('sysadmin/history/index.html.twig', array('historyItems' => $hrb->fetchAll()));
 }
 function history($id, Request $request, Application $app)
 {
     $this->build($id, $request, $app);
     $hrb = new HistoryRepositoryBuilder();
     $hrb->setAPI2Application($this->parameters['api2Application']);
     $this->parameters['historyItems'] = $hrb->fetchAll();
     return $app['twig']->render('sysadmin/api2app/history.html.twig', $this->parameters);
 }
 public function build()
 {
     foreach ($this->historyRepositoryBuilder->fetchAll() as $event) {
         $this->addHistory($event);
     }
 }
 /**
  * @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 history($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Area does not exist.");
     }
     $historyRepositoryBuilder = new HistoryRepositoryBuilder();
     $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setArea($this->parameters['area']);
     $this->parameters['historyItems'] = $historyRepositoryBuilder->fetchAll();
     return $app['twig']->render('site/area/history.html.twig', $this->parameters);
 }
 /**
  * @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;
         }
     }
 }
 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 Event
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 9, 1, 1, 1, 1));
     $event->setEndAt(getUTCDateTime(2014, 9, 1, 1, 1, 1));
     $eventRepo = new EventRepository();
     $eventRepo->create($event, $site, $user);
     ## Edit event
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $event = $eventRepo->loadBySlug($site, $event->getSlug());
     $event->setDescription("testy 123");
     $eventRepo->edit($event, $user);
     # delete event
     \TimeSource::mock(2014, 1, 1, 15, 0, 0);
     $eventRepo->delete($event, $user);
     ## Now save changed flags on these .....
     $eventHistoryRepo = new EventHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM event_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $eventHistory = new EventHistoryModel();
         $eventHistory->setFromDataBaseRow($data);
         $eventHistoryRepo->ensureChangedFlagsAreSet($eventHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setSite($site);
     $historyRepo->setIncludeEventHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(3, count($histories));
     #the delete
     $this->assertEquals(FALSE, $histories[0]->getSummaryChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     #the edit
     $this->assertEquals(FALSE, $histories[1]->getSummaryChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[2]->getSummaryChanged());
     $this->assertEquals(true, $histories[2]->getDescriptionChanged());
     $this->assertEquals(false, $histories[2]->getIsDeletedChanged());
     ## Now load history at a certain point; this is to test rollback!
     $history = $eventHistoryRepo->loadByEventAndtimeStamp($event, getUTCDateTime(2014, 1, 1, 15, 0, 0)->getTimestamp());
     $this->assertEquals("test", $history->getSummary());
     $this->assertEquals("testy 123", $history->getDescription());
 }