function test1()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userOther = new UserAccountModel();
     $userOther->setEmail("*****@*****.**");
     $userOther->setUsername("test2");
     $userOther->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $userRepo->create($userOther);
     $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);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $curatedList = new CuratedListModel();
     $curatedList->setTitle("test");
     $curatedList->setDescription("test this!");
     $clRepo = new CuratedListRepository();
     $clRepo->create($curatedList, $site, $user);
     $clRepo->addEditorToCuratedList($userOther, $curatedList, $user);
     $clRepo->addEventtoCuratedList($event, $curatedList, $user);
     $clRepo->addGroupToCuratedList($group, $curatedList, $user);
     ## Test
     $this->assertNotNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
     ## Purge!
     $clRepo->purge($curatedList);
     ## Test
     $this->assertNull($clRepo->loadBySlug($site, $curatedList->getSlug()));
 }
 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() == 'delete' && !$this->parameters['curatedlist']->getIsDeleted()) {
                 $clr = new CuratedListRepository();
                 $clr->delete($this->parameters['curatedlist'], $app['currentUser']);
                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
             } else {
                 if ($action->getCommand() == 'undelete' && $this->parameters['curatedlist']->getIsDeleted()) {
                     $clr = new CuratedListRepository();
                     $clr->undelete($this->parameters['curatedlist'], $app['currentUser']);
                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                 } else {
                     if ($action->getCommand() == 'addeditor') {
                         $userRepo = new UserAccountRepository();
                         $user = $userRepo->loadByID($action->getParam(0));
                         if ($user) {
                             $clr = new CuratedListRepository();
                             $clr->addEditorToCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                         }
                     } else {
                         if ($action->getCommand() == 'removeeditor') {
                             $userRepo = new UserAccountRepository();
                             $user = $userRepo->loadByID($action->getParam(0));
                             if ($user) {
                                 $clr = new CuratedListRepository();
                                 $clr->removeEditorFromCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']);
                                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug());
                             }
                         } else {
                             if ($action->getCommand() == 'addevent') {
                                 $eventRepository = new EventRepository();
                                 $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0));
                                 if ($event) {
                                     $clr = new CuratedListRepository();
                                     $clr->addEventtoCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']);
                                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug());
                                 }
                             } else {
                                 if ($action->getCommand() == 'removeevent') {
                                     $eventRepository = new EventRepository();
                                     $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0));
                                     if ($event) {
                                         $clr = new CuratedListRepository();
                                         $clr->removeEventFromCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']);
                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug());
                                     }
                                 } else {
                                     if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeCuratedListPassword && $CONFIG->sysAdminExtraPurgeCuratedListPassword == $action->getParam(0)) {
                                         $clr = new CuratedListRepository();
                                         $clr->purge($this->parameters['curatedlist']);
                                         return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/');
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/curatedlist/index.html.twig', $this->parameters);
 }