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 testAddSet()
 {
     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($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 = new GroupModel();
     $group1->setTitle("test");
     $group1->setDescription("test test");
     $group1->setUrl("http://www.group.com");
     $group2 = new GroupModel();
     $group2->setTitle("test2");
     $group2->setDescription("test 2");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group1, $site, $user);
     $groupRepo->create($group2, $site, $user);
     ## Add event to group1, test
     $groupRepo->addEventToGroup($event, $group1, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## Add event to group2, test group1 is still main group
     $groupRepo->addEventToGroup($event, $group2, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group1->getId(), $event->getGroupId());
     $this->assertEquals("test", $event->getGroupTitle());
     ## set main group to group2, test
     $groupRepo->setMainGroupForEvent($group2, $event, $user);
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($group2->getId(), $event->getGroupId());
     $this->assertEquals("test2", $event->getGroupTitle());
 }
 function editGroups($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Event does not exist.");
     }
     $groupRepo = new GroupRepository();
     if ('POST' == $request->getMethod() && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         if ($request->request->get('addGroup')) {
             $group = $groupRepo->loadBySlug($app['currentSite'], $request->request->get('addGroup'));
             if ($group) {
                 $groupRepo->addEventToGroup($this->parameters['event'], $group, $app['currentUser']);
                 // Need to redirect here so other parts of page are correct when shown
                 return $app->redirect("/event/" . $this->parameters['event']->getSlugForURL() . '/edit/groups');
             }
         } elseif ($request->request->get('removeGroup')) {
             $group = $groupRepo->loadBySlug($app['currentSite'], $request->request->get('removeGroup'));
             if ($group) {
                 $groupRepo->removeEventFromGroup($this->parameters['event'], $group, $app['currentUser']);
                 // Need to redirect here so other parts of page are correct when shown
                 return $app->redirect("/event/" . $this->parameters['event']->getSlugForURL() . '/edit/groups');
             }
         }
     }
     $this->parameters['groupListFilterParams'] = new GroupFilterParams();
     $this->parameters['groupListFilterParams']->set($_GET);
     $this->parameters['groupListFilterParams']->getGroupRepositoryBuilder()->setSite($app['currentSite']);
     $this->parameters['groupListFilterParams']->getGroupRepositoryBuilder()->setIncludeDeleted(false);
     $this->parameters['groupListFilterParams']->getGroupRepositoryBuilder()->setLimit(30);
     $this->parameters['groupListFilterParams']->getGroupRepositoryBuilder()->setNotEvent($this->parameters['event']);
     $this->parameters['groupsToAdd'] = $this->parameters['groupListFilterParams']->getGroupRepositoryBuilder()->fetchAll();
     return $app['twig']->render('site/event/edit.groups.html.twig', $this->parameters);
 }
 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);
 }