function test1()
 {
     $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);
     $this->checkGroupInTest1($groupRepo->loadById($group->getId()));
     $this->checkGroupInTest1($groupRepo->loadBySlug($site, $group->getSlug()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('test');
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new GroupRepositoryBuilder();
     $grb->setFreeTextsearch('cats');
     $this->assertEquals(0, count($grb->fetchAll()));
 }
 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 index($siteid, Request $request, Application $app)
 {
     $sr = new SiteRepository();
     $site = $sr->loadById($siteid);
     if (!$site) {
         die("404");
     }
     $grb = new GroupRepositoryBuilder();
     $grb->setSite($site);
     $groups = $grb->fetchAll();
     return $app['twig']->render('sysadmin/grouplist/index.html.twig', array('site' => $site, 'groups' => $groups));
 }
 public function listJson(Request $request, Application $app)
 {
     $grb = new GroupRepositoryBuilder();
     $grb->setSite($app['currentSite']);
     $ourRequest = new \Request($request);
     $grb->setIncludeDeleted($ourRequest->getGetOrPostBoolean('include_deleted', false));
     $out = array('groups' => array());
     foreach ($grb->fetchAll() as $group) {
         $out['groups'][] = array('slug' => $group->getSlug(), 'slugForURL' => $group->getSlugForUrl(), 'title' => $group->getTitle());
     }
     return json_encode($out);
 }
 function onThisStepSetUpPageView()
 {
     $out = array('groupSearchText' => $this->request->request->get('groupsearch'));
     if ($this->request->request->get('action') == 'groupsearch') {
         $grb = new GroupRepositoryBuilder();
         $grb->setSite($this->site);
         $grb->setIncludeDeleted(false);
         $grb->setFreeTextsearch($this->request->request->get('groupsearch'));
         $grb->setLimit(100);
         $out['groups'] = $grb->fetchAll();
     }
     return $out;
 }
 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 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 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 json(Request $request, Application $app)
 {
     $groupRepoBuilder = new GroupRepositoryBuilder();
     $groupRepoBuilder->setSite($app['currentSite']);
     if (isset($_GET['search']) && trim($_GET['search'])) {
         $groupRepoBuilder->setFreeTextsearch($_GET['search']);
     }
     if (isset($_GET['includeDeleted'])) {
         if (in_array(strtolower($_GET['includeDeleted']), array('yes', 'on', '1'))) {
             $groupRepoBuilder->setIncludeDeleted(true);
         } else {
             if (in_array(strtolower($_GET['includeDeleted']), array('no', 'off', '0'))) {
                 $groupRepoBuilder->setIncludeDeleted(false);
             }
         }
     }
     $out = array();
     foreach ($groupRepoBuilder->fetchAll() as $group) {
         $out[] = array('slug' => $group->getSlug(), 'title' => $group->getTitle());
     }
     $response = new Response(json_encode(array('data' => $out)));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 protected function run()
 {
     global $CONFIG;
     $userRepo = new UserAccountRepository();
     $siteRepo = new SiteRepository();
     $eventRepo = new EventRepository();
     $userWatchesSiteRepository = new UserWatchesSiteRepository();
     $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository();
     $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository();
     $userNotificationRepo = new UserNotificationRepository();
     /** @var usernotifications/UserWatchesSiteGroupPromptNotificationType **/
     $userNotificationType = $this->app['extensions']->getCoreExtension()->getUserNotificationType('UserWatchesSiteGroupPrompt');
     $b = new UserWatchesSiteRepositoryBuilder();
     foreach ($b->fetchAll() as $userWatchesSite) {
         $user = $userRepo->loadByID($userWatchesSite->getUserAccountId());
         $site = $siteRepo->loadById($userWatchesSite->getSiteId());
         $siteRepo->loadLegacyFeaturesOnSite($site);
         // to avoid flooding user we only send one group email per run
         $anyGroupNotificationsSent = false;
         $this->logVerbose(" User " . $user->getEmail() . " Site " . $site->getTitle());
         if ($site->getIsClosedBySysAdmin()) {
             $this->logVerbose(" ... site is closed");
             // Technically UserWatchesSiteRepositoryBuilder() should only return getIsWatching() == true but lets double check
         } else {
             if ($userWatchesSite->getIsWatching()) {
                 $groupRepoBuilder = new GroupRepositoryBuilder();
                 $groupRepoBuilder->setSite($site);
                 $groupRepoBuilder->setIncludeDeleted(false);
                 foreach ($groupRepoBuilder->fetchAll() as $group) {
                     if (!$anyGroupNotificationsSent) {
                         $this->logVerbose(" ... searching group " . $group->getSlug() . " for data");
                         $lastEvent = $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId());
                         $data = $userWatchesSite->getGroupPromptEmailData($site, $group, $lastEvent);
                         if ($data['moreEventsNeeded']) {
                             $this->logVerbose(" ... found data ");
                             ///// Notification Class
                             $userNotification = $userNotificationType->getNewNotification($user, $site);
                             $userNotification->setGroup($group);
                             ////// Save Notification Class
                             $userNotificationRepo->create($userNotification);
                             ////// Send Email
                             if ($userNotification->getIsEmail()) {
                                 $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($user, $site);
                                 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->userWatchesSiteGroupPromptEmailShowEvents);
                                 $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 = $this->app['twig']->render('email/userWatchesSiteGroupPromptEmail.txt.twig', array('user' => $user, 'group' => $group, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL));
                                 if ($CONFIG->isDebug) {
                                     file_put_contents('/tmp/userWatchesSiteGroupPromptEmail.txt', $messageText);
                                 }
                                 $message->setBody($messageText);
                                 $messageHTML = $this->app['twig']->render('email/userWatchesSiteGroupPromptEmail.html.twig', array('user' => $user, 'group' => $group, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL));
                                 if ($CONFIG->isDebug) {
                                     file_put_contents('/tmp/userWatchesSiteGroupPromptEmail.html', $messageHTML);
                                 }
                                 $message->addPart($messageHTML, 'text/html');
                                 $headers = $message->getHeaders();
                                 $headers->addTextHeader('List-Unsubscribe', $unsubscribeURL);
                                 $this->logVerbose(" ... sending");
                                 if (!$CONFIG->isDebug) {
                                     $this->app['mailer']->send($message);
                                 }
                                 $userNotificationRepo->markEmailed($userNotification);
                             }
                             $userWatchesSiteRepository->markGroupPromptEmailSent($userWatchesSite, $group, $data['checkTime']);
                             $anyGroupNotificationsSent = true;
                         }
                     }
                 }
             }
         }
     }
     return array('result' => 'ok');
 }
 protected function build($slug, Request $request, Application $app)
 {
     global $CONFIG;
     $this->parameters = array('group' => null, 'venue' => null, 'country' => null, 'area' => null, 'parentAreas' => array(), 'childAreas' => array(), 'importurl' => null, 'eventIsDuplicateOf' => null);
     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;
     }
     if ($this->parameters['event']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID());
     }
     $areaID = null;
     if ($this->parameters['event']->getVenueID()) {
         $cr = new VenueRepository();
         $this->parameters['venue'] = $cr->loadById($this->parameters['event']->getVenueID());
         $areaID = $this->parameters['venue']->getAreaId();
     } else {
         if ($this->parameters['event']->getAreaId()) {
             $areaID = $this->parameters['event']->getAreaId();
         }
     }
     if ($areaID) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadById($areaID);
         if (!$this->parameters['area']) {
             return false;
         }
         $checkArea = $this->parameters['area']->getParentAreaId() ? $ar->loadById($this->parameters['area']->getParentAreaId()) : null;
         while ($checkArea) {
             array_unshift($this->parameters['parentAreas'], $checkArea);
             $checkArea = $checkArea->getParentAreaId() ? $ar->loadById($checkArea->getParentAreaId()) : null;
         }
     }
     if ($this->parameters['event']->getImportUrlId()) {
         $iur = new ImportURLRepository();
         $this->parameters['importurl'] = $iur->loadById($this->parameters['event']->getImportUrlId());
     }
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($this->parameters['event']);
     $this->parameters['groups'] = $groupRB->fetchAll();
     if ($this->parameters['event']->getGroupId()) {
         foreach ($this->parameters['groups'] as $group) {
             if ($group->getId() == $this->parameters['event']->getGroupId()) {
                 $this->parameters['group'] = $group;
             }
         }
     }
     if ($this->parameters['event']->getIsDuplicateOfId()) {
         $this->parameters['eventIsDuplicateOf'] = $eventRepository->loadByID($this->parameters['event']->getIsDuplicateOfId());
     }
     $app['currentUserActions']->set("org.openacalendar", "eventHistory", true);
     $app['currentUserActions']->set("org.openacalendar", "eventEditDetails", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled());
     $app['currentUserActions']->set("org.openacalendar", "eventEditDetailsRollback", $app['currentUserActions']->has("org.openacalendar", "eventEditDetails"));
     $app['currentUserActions']->set("org.openacalendar", "eventEditVenue", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled() && $app['currentSite']->getIsFeaturePhysicalEvents());
     $app['currentUserActions']->set("org.openacalendar", "eventEditTags", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled() && $app['currentSite']->getIsFeatureTag());
     $app['currentUserActions']->set("org.openacalendar", "eventEditGroups", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled() && $app['currentSite']->getIsFeatureGroup());
     $app['currentUserActions']->set("org.openacalendar", "eventEditMedia", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled() && $CONFIG->isFileStore());
     $app['currentUserActions']->set("org.openacalendar", "eventRecur", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsImported() && !$this->parameters['event']->getIsDeleted() && !$this->parameters['event']->getIsCancelled());
     $app['currentUserActions']->set("org.openacalendar", "eventDelete", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsImported() && !$this->parameters['event']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "eventCancel", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsImported() && !$this->parameters['event']->getIsCancelled() && !$this->parameters['event']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "eventUndelete", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsImported() && $this->parameters['event']->getIsDeleted());
     $app['currentUserActions']->set("org.openacalendar", "eventUncancel", $app['currentUserPermissions']->hasPermission("org.openacalendar", "EVENTS_CHANGE") && !$this->parameters['event']->getIsImported() && $this->parameters['event']->getIsCancelled());
     return true;
 }
 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() == 'addgroup') {
                 $gr = new GroupRepository();
                 $group = $gr->loadBySlug($this->parameters['site'], $action->getParam(0));
                 if ($group) {
                     $gr->addEventToGroup($this->parameters['event'], $group, $app['currentUser']);
                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                 }
             } else {
                 if ($action->getCommand() == 'removegroup') {
                     $gr = new GroupRepository();
                     $group = $gr->loadBySlug($this->parameters['site'], $action->getParam(0));
                     if ($group) {
                         $gr->removeEventFromGroup($this->parameters['event'], $group, $app['currentUser']);
                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                     }
                 } else {
                     if ($action->getCommand() == 'maingroup') {
                         $gr = new GroupRepository();
                         $group = $gr->loadBySlug($this->parameters['site'], $action->getParam(0));
                         if ($group) {
                             $gr->setMainGroupForEvent($group, $this->parameters['event'], $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                         }
                     } else {
                         if ($action->getCommand() == 'delete' && !$this->parameters['event']->getIsDeleted()) {
                             $er = new EventRepository();
                             $er->delete($this->parameters['event'], $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                         } else {
                             if ($action->getCommand() == 'undelete' && $this->parameters['event']->getIsDeleted()) {
                                 $this->parameters['event']->setIsDeleted(false);
                                 $er = new EventRepository();
                                 $er->undelete($this->parameters['event'], $app['currentUser']);
                                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                             } else {
                                 if ($action->getCommand() == 'cancel' && !$this->parameters['event']->getIsDeleted()) {
                                     $er = new EventRepository();
                                     $er->cancel($this->parameters['event'], $app['currentUser']);
                                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                                 } else {
                                     if ($action->getCommand() == 'uncancel' && $this->parameters['event']->getIsCancelled()) {
                                         $er = new EventRepository();
                                         $er->uncancel($this->parameters['event'], $app['currentUser']);
                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                                     } else {
                                         if ($action->getCommand() == 'addcuratedlist') {
                                             $clr = new CuratedListRepository();
                                             $curatedList = $clr->loadBySlug($this->parameters['site'], $action->getParam(0));
                                             if ($curatedList) {
                                                 $clr->addEventtoCuratedList($this->parameters['event'], $curatedList, $app['currentUser']);
                                                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $curatedList->getSlug());
                                             }
                                         } else {
                                             if ($action->getCommand() == 'removecuratedlist') {
                                                 $clr = new CuratedListRepository();
                                                 $curatedList = $clr->loadBySlug($this->parameters['site'], $action->getParam(0));
                                                 if ($curatedList) {
                                                     $clr->removeEventFromCuratedList($this->parameters['event'], $curatedList, $app['currentUser']);
                                                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $curatedList->getSlug());
                                                 }
                                             } else {
                                                 if ($action->getCommand() == 'isduplicateof') {
                                                     $er = new EventRepository();
                                                     $originalEvent = $er->loadBySlug($this->parameters['site'], $action->getParam(0));
                                                     if ($originalEvent && $originalEvent->getId() != $this->parameters['event']->getId()) {
                                                         $er->markDuplicate($this->parameters['event'], $originalEvent, $app['currentUser']);
                                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                                                     }
                                                 } else {
                                                     if ($action->getCommand() == 'isnotduplicate') {
                                                         $er = new EventRepository();
                                                         $eventEditMetaData = new EventEditMetaDataModel();
                                                         $eventEditMetaData->setUserAccount($app['currentUser']);
                                                         $eventEditMetaData->setFromRequest($request);
                                                         $er->markNotDuplicateWithMetaData($this->parameters['event'], $eventEditMetaData);
                                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $this->parameters['event']->getSlug());
                                                     } else {
                                                         if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeEventPassword && $CONFIG->sysAdminExtraPurgeEventPassword == $action->getParam(0)) {
                                                             $er = new EventRepository();
                                                             $er->purge($this->parameters['event']);
                                                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/');
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $groupRB = new GroupRepositoryBuilder();
     $groupRB->setEvent($this->parameters['event']);
     $this->parameters['groups'] = $groupRB->fetchAll();
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/event/index.html.twig', $this->parameters);
 }
 function groupEdited($id, Request $request, Application $app)
 {
     $this->build($id, $request, $app);
     $grb = new GroupRepositoryBuilder();
     $grb->setEditedByUser($this->parameters['user']);
     $this->parameters['groups'] = $grb->fetchAll();
     return $app['twig']->render('/sysadmin/user/group.edited.html.twig', $this->parameters);
 }
 /**
  * @return array
  */
 public function getUserNotifyContentForSiteAndUser(\models\SiteModel $siteModel, UserAccountModel $userAccountModel)
 {
     global $CONFIG;
     if (!$siteModel->getIsFeatureGroup()) {
         return array();
     }
     $out = array();
     $grb = new GroupRepositoryBuilder();
     $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 group? but then so far most group deletetions are by admins.
     $grb->setIncludeDeleted(false);
     foreach ($grb->fetchAll() as $group) {
         $uwg = $this->loadByUserAndGroup($userAccountModel, $group);
         if ($uwg && $uwg->getIsWatching()) {
             $dateSince = $uwg->getSinceDateForNotifyChecking();
             $historyRepositoryBuilder = new HistoryRepositoryBuilder();
             $historyRepositoryBuilder->setGroup($group);
             $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 UserWatchesGroupNotifyContent();
                 $content->setHistories($histories);
                 $userWatchesGroupStopRepository = new UserWatchesGroupStopRepository();
                 $userWatchesGroupStop = $userWatchesGroupStopRepository->getForUserAndGroup($userAccountModel, $group);
                 $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/group/' . $group->getSlugForURL() . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesGroupStop->getAccessKey());
                 $content->setUserAccount($userAccountModel);
                 $content->setSite($siteModel);
                 $content->setGroup($group);
                 $content->setWatchedThingTitle($group->getTitle());
                 $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/group/' . $group->getSlugForURL() . '/history');
                 $out[] = $content;
             }
         }
     }
     return $out;
 }