function create(Request $request, Application $app)
 {
     $siteRepository = new SiteRepository();
     $form = $app['form.factory']->create(new CreateForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         $data = $form->getData();
         $site = $siteRepository->loadBySlug($data['slug']);
         if ($site) {
             $form->addError(new FormError('That address is already taken'));
         }
         if ($form->isValid()) {
             $site = new SiteModel();
             $site->setSlug($data['slug']);
             $site->setTitle($data['title']);
             if ($data['read'] == 'public') {
                 $site->setIsListedInIndex(true);
                 $site->setIsWebRobotsAllowed(true);
             } else {
                 $site->setIsListedInIndex(false);
                 $site->setIsWebRobotsAllowed(false);
             }
             if ($data['write'] == 'public') {
                 $isAllUsersEditors = true;
             } else {
                 $isAllUsersEditors = false;
             }
             $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance);
             $countryRepository = new CountryRepository();
             $siteQuotaRepository = new SiteQuotaRepository();
             $siteRepository->create($site, $app['currentUser'], array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode), $isAllUsersEditors);
             if ($app['config']->hasSSL) {
                 return $app->redirect("https://" . $site->getSlug() . "." . $app['config']->webSiteDomainSSL);
             } else {
                 return $app->redirect("http://" . $site->getSlug() . "." . $app['config']->webSiteDomain);
             }
         }
     }
     $sites = array();
     $repo = new SiteRepository();
     if (isset($_COOKIE['sitesSeen'])) {
         foreach (explode(",", $_COOKIE['sitesSeen']) as $siteID) {
             if (intval($siteID) > 0) {
                 $site = $repo->loadById($siteID);
                 if ($site && !$site->getIsClosedBySysAdmin() && $site->getSlug() != $app['config']->siteSlugDemoSite) {
                     $sites[$site->getId()] = $site;
                 }
             }
         }
     }
     $srb = new SiteRepositoryBuilder();
     $srb->setIsOpenBySysAdminsOnly(true);
     $srb->setUserInterestedIn($app['currentUser']);
     foreach ($srb->fetchAll() as $site) {
         $sites[$site->getId()] = $site;
     }
     return $app['twig']->render('index/index/create.html.twig', array('form' => $form->createView(), 'sites' => $sites));
 }
 function index(Request $request, Application $app)
 {
     $form = $app['form.factory']->create(new NewSiteForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         $data = $form->getData();
         $siteRepository = new SiteRepository();
         $site = $siteRepository->loadBySlug($data['slug']);
         if ($site) {
             $form->addError(new FormError('That address is already taken'));
         }
         if ($form->isValid()) {
             $userRepo = new UserAccountRepository();
             $user = $userRepo->loadByEmail($data['email']);
             if ($user) {
                 $data = $form->getData();
                 $site = new SiteModel();
                 $site->setSlug($data['slug']);
                 $site->setTitle($data['title']);
                 if ($data['read'] == 'public') {
                     $site->setIsListedInIndex(true);
                     $site->setIsWebRobotsAllowed(true);
                 } else {
                     $site->setIsListedInIndex(false);
                     $site->setIsWebRobotsAllowed(false);
                 }
                 if ($data['write'] == 'public') {
                     $site->setIsAllUsersEditors(true);
                     $site->setIsRequestAccessAllowed(false);
                 } else {
                     $site->setIsAllUsersEditors(false);
                     $site->setIsRequestAccessAllowed(true);
                 }
                 $site->setIsFeatureCuratedList($app['config']->newSiteHasFeatureCuratedList);
                 $site->setIsFeatureImporter($app['config']->newSiteHasFeatureImporter);
                 $site->setIsFeatureMap($app['config']->newSiteHasFeatureMap);
                 $site->setIsFeatureVirtualEvents($app['config']->newSiteHasFeatureVirtualEvents);
                 $site->setIsFeaturePhysicalEvents($app['config']->newSiteHasFeaturePhysicalEvents);
                 $site->setIsFeatureGroup($app['config']->newSiteHasFeatureGroup);
                 $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance);
                 $site->setIsFeatureTag($app['config']->newSiteHasFeatureTag);
                 $countryRepository = new CountryRepository();
                 $siteQuotaRepository = new SiteQuotaRepository();
                 $siteRepository->create($site, $user, array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode));
                 return $app->redirect("/sysadmin/site/" . $site->getId());
             } else {
                 $app['flashmessages']->addError('Existing user not found!');
             }
         }
     }
     return $app['twig']->render('sysadmin/sitenew/index.html.twig', array('form' => $form->createView()));
 }
 function testIsGroupRunningOutOfFutureEvents()
 {
     \TimeSource::mock(2014, 1, 1, 1, 1, 1);
     $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");
     $site->setPromptEmailsDaysInAdvance(28);
     $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, 4, 1, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 4, 1, 21, 0, 0, 'Europe/London'));
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user, $group);
     ### TEST
     \TimeSource::mock(2014, 2, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 2, 15, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 1, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 2, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 3, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 4, 1, 1, 1);
     $this->assertEquals(0, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 5, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 6, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 7, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 3, 20, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 1, 1, 1, 1);
     $this->assertEquals(1, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 4, 15, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
     ### TEST
     \TimeSource::mock(2014, 5, 1, 1, 1, 1);
     $this->assertEquals(2, $groupRepo->isGroupRunningOutOfFutureEvents($group, $site));
 }
 /**
  * @dataProvider providerPromptEmailsDaysInAdvance
  */
 function testPromptEmailsDaysInAdvance($in, $out)
 {
     $site = new SiteModel();
     $site->setPromptEmailsDaysInAdvance($in);
     $this->assertEquals($out, $site->getPromptEmailsDaysInAdvance());
 }
$slug = $argv[1];
$email = $argv[2];
if (!$slug || !$email) {
    die("Slug and Email?\n\n");
}
if (!SiteModel::isSlugValid($slug, $CONFIG)) {
    die("Slug is not valid!\n\n");
}
print "Slug: " . $slug . "\n";
print "Email: " . $email . "\n";
sleep(10);
print "Starting ...\n";
$userRepository = new UserAccountRepository();
$user = $userRepository->loadByUserNameOrEmail($email);
if (!$user) {
    die("Can't load user!\n\n");
}
$site = new SiteModel();
$site->setSlug($slug);
$site->setTitle($slug);
$site->setIsListedInIndex(true);
$site->setIsWebRobotsAllowed(true);
$site->setPromptEmailsDaysInAdvance($CONFIG->newSitePromptEmailsDaysInAdvance);
$siteRepository = new SiteRepository();
$countryRepository = new CountryRepository();
$siteQuotaRepository = new SiteQuotaRepository();
$gb = $countryRepository->loadByTwoCharCode("GB");
if (!$gb) {
    die("Can't load Country GB - have you loaded static data?\n\n");
}
$siteRepository->create($site, $user, array($gb), $siteQuotaRepository->loadByCode($CONFIG->newSiteHasQuotaCode), false);