protected function build($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('group' => null, 'venue' => null, 'country' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $er = new EventRepository();
     $this->parameters['event'] = $er->loadBySlug($this->parameters['site'], $slug);
     $this->parameters['eventisduplicateof'] = $this->parameters['event']->getIsDuplicateOfId() ? $er->loadById($this->parameters['event']->getIsDuplicateOfId()) : null;
     if (!$this->parameters['event']) {
         $app->abort(404);
     }
     if ($this->parameters['event']->getGroupId()) {
         $gr = new GroupRepository();
         $this->parameters['group'] = $gr->loadById($this->parameters['event']->getGroupId());
     }
     if ($this->parameters['event']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID());
     }
     if ($this->parameters['event']->getVenueID()) {
         $cr = new VenueRepository();
         $this->parameters['venue'] = $cr->loadById($this->parameters['event']->getVenueID());
     }
 }
 function test1()
 {
     $this->addCountriesToTestDB();
     $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');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $grb = new VenueRepositoryBuilder();
     $grb->setFreeTextsearch('test');
     $this->assertEquals(1, count($grb->fetchAll()));
     $grb = new VenueRepositoryBuilder();
     $grb->setFreeTextsearch('cats');
     $this->assertEquals(0, count($grb->fetchAll()));
 }
 public function setFromAppAndEventAndEmail(Application $app, EventModel $eventModel, $email)
 {
     $this->event_id = $eventModel->getId();
     $this->email = $email;
     $this->subject = "Can we check the details of your event?";
     $venueRepo = new VenueRepository();
     $venue = null;
     if ($eventModel->getVenueId()) {
         $venue = $venueRepo->loadById($eventModel->getVenueId());
     }
     $area = null;
     $areaRepo = new AreaRepository();
     if ($eventModel->getAreaId()) {
         $area = $areaRepo->loadById($eventModel->getAreaId());
     } else {
         if ($venue && $venue->getAreaId()) {
             $area = $areaRepo->loadById($venue->getAreaId());
         }
     }
     $hrb = new HumanRepositoryBuilder();
     $hrb->setHumansForEvent($eventModel);
     $hrb->setIncludeDeleted(false);
     $humans = $hrb->fetchAll();
     $this->body_html = $app['twig']->render('email/organiserEmail.html.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans));
     if ($app['config']->isDebug) {
         file_put_contents('/tmp/organiserEmail.html', $this->body_html);
     }
     $this->body_text = $app['twig']->render('email/organiserEmail.txt.twig', array('event' => $eventModel, 'email' => $this->email, 'venue' => $venue, 'area' => $area, 'humans' => $humans));
     if ($app['config']->isDebug) {
         file_put_contents('/tmp/organiserEmail.txt', $this->body_text);
     }
     $this->created_at = $app['timesource']->getDateTime();
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $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');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     \TimeSource::mock(2014, 1, 1, 1, 0, 0);
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->delete($venue, $user);
     $this->checkVenueInTest1($venueRepo->loadById($venue->getId()));
     $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(true);
     $this->assertEquals(1, count($vrb->fetchAll()));
     $vrb = new VenueRepositoryBuilder();
     $vrb->setIncludeDeleted(false);
     $this->assertEquals(0, count($vrb->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;
 }
 protected function run()
 {
     $venueRepository = new VenueRepository();
     $vrb = new VenueRepositoryBuilder();
     $count = 0;
     foreach ($vrb->fetchAll() as $venue) {
         $venueRepository->updateFutureEventsCache($venue);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 protected function build($slug, Request $request, Application $app)
 {
     $this->parameters = array();
     if (strpos($slug, "-") > 0) {
         $slugBits = explode("-", $slug, 2);
         $slug = $slugBits[0];
     }
     $vr = new VenueRepository();
     $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $slug);
     if (!$this->parameters['venue']) {
         return false;
     }
     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() == 'delete' && !$this->parameters['venue']->getIsDeleted()) {
                 $vr = new VenueRepository();
                 $vr->delete($this->parameters['venue'], $app['currentUser']);
                 return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug());
             } else {
                 if ($action->getCommand() == 'undelete' && $this->parameters['venue']->getIsDeleted()) {
                     $this->parameters['venue']->setIsDeleted(false);
                     $vr = new VenueRepository();
                     $vr->undelete($this->parameters['venue'], $app['currentUser']);
                     return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug());
                 } else {
                     if ($action->getCommand() == 'isduplicateof') {
                         $vr = new VenueRepository();
                         $originalVenue = $vr->loadBySlug($this->parameters['site'], $action->getParam(0));
                         if ($originalVenue && $originalVenue->getId() != $this->parameters['venue']->getId()) {
                             $vr->markDuplicate($this->parameters['venue'], $originalVenue, $app['currentUser']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug());
                         }
                     } else {
                         if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeVenuePassword && $CONFIG->sysAdminExtraPurgeVenuePassword == $action->getParam(0)) {
                             $vr = new VenueRepository();
                             $vr->purge($this->parameters['venue']);
                             return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/');
                         }
                     }
                 }
             }
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('sysadmin/venue/index.html.twig', $this->parameters);
 }
 protected function build($countryCode, $areaSlug, $venueSlug, Request $request, Application $app)
 {
     $this->parameters = array('country' => null, 'area' => null, 'venue' => null);
     if ($areaSlug) {
         $ar = new AreaRepository();
         $this->parameters['area'] = $ar->loadBySlug($app['currentSite'], $areaSlug);
     }
     if ($this->parameters['area']) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['area']->getCountryID());
     } else {
         if ($countryCode) {
             $cr = new CountryRepository();
             $this->parameters['country'] = $cr->loadByTwoCharCode($countryCode);
         }
     }
     if ($venueSlug) {
         $vr = new VenueRepository();
         $this->parameters['venue'] = $vr->loadBySlug($app['currentSite'], $venueSlug);
     }
     return true;
 }
 function test1()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 10, 1, 1, 1, 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');
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $areaRepo = new \repositories\AreaRepository();
     $areaRepo->create($area, null, $site, $gb, $user);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venue->setAreaId($area->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $venueDuplicate = new VenueModel();
     $venueDuplicate->setTitle("test Duplicate");
     $venueRepo->create($venueDuplicate, $site, $user);
     \TimeSource::mock(2014, 10, 1, 1, 2, 0);
     $venueRepo->markDuplicate($venueDuplicate, $venue, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0, 'Europe/London'));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0, 'Europe/London'));
     $event->setVenueId($venue->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ## Test
     $this->assertNotNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue->getId(), $event->getVenueId());
     ## Now Purge!
     $venueRepo->purge($venue);
     ## Test
     $this->assertNull($venueRepo->loadBySlug($site, $venue->getSlug()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertNull($event->getVenueId());
 }
 public function postInfoJson($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Does not exist.");
     }
     $ourRequest = new \Request($request);
     $edits = false;
     if ($ourRequest->hasGetOrPost('title') && $this->venue->setTitleIfDifferent($ourRequest->getGetOrPostString('title', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('description') && $this->venue->setDescriptionIfDifferent($ourRequest->getGetOrPostString('description', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('address') && $this->venue->setAddressIfDifferent($ourRequest->getGetOrPostString('address', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('address_code') && $this->venue->setAddressCodeIfdifferent($ourRequest->getGetOrPostString('address_code', ''))) {
         $edits = true;
     }
     if ($ourRequest->hasGetOrPost('lat') && $ourRequest->hasGetOrPost('lng')) {
         if ($this->venue->setLatIfDifferent($ourRequest->getGetOrPostString('lat', ''))) {
             $edits = true;
         }
         if ($this->venue->setLngIfDifferent($ourRequest->getGetOrPostString('lng', ''))) {
             $edits = true;
         }
     }
     if ($edits) {
         $repo = new VenueRepository();
         $repo->edit($this->venue, $app['apiUser']);
         $out = array('edited' => true);
     } else {
         $out = array('edited' => false);
     }
     return json_encode($out);
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $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');
     $venue1 = new VenueModel();
     $venue1->setTitle("test");
     $venue1->setDescription("test test");
     $venue1->setCountryId($gb->getId());
     $venue2 = new VenueModel();
     $venue2->setTitle("test this looks similar");
     $venue2->setDescription("test test");
     $venue2->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue1, $site, $user);
     $venueRepo->create($venue2, $site, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setVenueId($venue2->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     // Test before
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue2->getId(), $event->getVenueId());
     $venue2 = $venueRepo->loadById($venue2->getId());
     $this->assertFalse($venue2->getIsDeleted());
     $this->assertNull($venue2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $venueRepo->markDuplicate($venue2, $venue1, $user);
     // Test Duplicate
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($venue1->getId(), $event->getVenueId());
     $venue2 = $venueRepo->loadById($venue2->getId());
     $this->assertTrue($venue2->getIsDeleted());
     $this->assertEquals($venue1->getId(), $venue2->getIsDuplicateOfId());
 }
 function testMoveAllFutureEventsAtVenueToNoSetVenueWithNoArea()
 {
     $this->addCountriesToTestDB();
     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());
     $countryRepo = new CountryRepository();
     $venue = new VenueModel();
     $venue->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId());
     $venue->setTitle("edinburgh hall");
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     #### Event To Change
     $event = new EventModel();
     $event->setCountryId($countryRepo->loadByTwoCharCode('GB')->getId());
     $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));
     $event->setVenueId($venue->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     #### Load Event, Check in Venue
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals(false, $event->getIsDeleted());
     $this->assertNull($event->getAreaId());
     $this->assertEquals($venue->getId(), $event->getVenueId());
     #### In preperation for deleting event, call moveAllFutureEventsAtVenueToNoSetVenue()
     TimeSource::mock(2013, 7, 1, 8, 0, 0);
     $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($venue, $user);
     #### Load event, check in area
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals(false, $event->getIsDeleted());
     $this->assertNull($event->getVenueId());
     $this->assertNull($event->getAreaId());
 }
 function delete($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Venue does not exist.");
     }
     if ($this->parameters['venue']->getIsDeleted()) {
         die("No");
         // TODO
     }
     $form = $app['form.factory']->create(new VenueDeleteForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $eventRepository = new EventRepository();
             $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($this->parameters['venue'], $app['currentUser']);
             $venueRepository = new VenueRepository();
             $venueRepository->delete($this->parameters['venue'], $app['currentUser']);
             return $app->redirect("/venue/" . $this->parameters['venue']->getSlugForURL());
         }
     }
     $rb = new EventRepositoryBuilder();
     $rb->setVenue($this->parameters['venue']);
     $rb->setAfterNow(true);
     $rb->setIncludeDeleted(false);
     $this->parameters['events'] = $rb->fetchAll();
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('site/venue/delete.html.twig', $this->parameters);
 }
 function addDataToEventBeforeSave(EventModel $eventModel)
 {
     $this->addDataToEventBeforeCheck($eventModel);
     if ($this->draftEvent->getDetailsValue('event.newvenue')) {
         $venueModel = new VenueModel();
         $venueModel->setSiteId($this->site->getId());
         $venueModel->setCountryId($this->draftEvent->getDetailsValue('event.country_id'));
         $venueModel->setTitle($this->draftEvent->getDetailsValue('venue.title'));
         $venueModel->setAddress($this->draftEvent->getDetailsValue('venue.address'));
         $venueModel->setAddressCode($this->draftEvent->getDetailsValue('venue.address_code'));
         $venueModel->setDescription($this->draftEvent->getDetailsValue('venue.description'));
         if ($this->draftEvent->getDetailsValue('venue.lat')) {
             $venueModel->setLat($this->draftEvent->getDetailsValue('venue.lat'));
             $venueModel->setLng($this->draftEvent->getDetailsValue('venue.lng'));
         }
         if ($this->draftEvent->getDetailsValue('area.id')) {
             $venueModel->setAreaId($this->draftEvent->getDetailsValue('area.id'));
         }
         foreach ($this->application['extensions']->getExtensionsIncludingCore() as $extension) {
             $extension->addDetailsToVenue($venueModel);
         }
         $vee = new VenueEditMetaDataModel();
         $vee->setUserAccount($this->application['currentUser']);
         // TODO $vee->setFromRequest();
         $venueRepository = new VenueRepository();
         $venueRepository->createWithMetaData($venueModel, $this->site, $vee);
         $eventModel->setVenueId($venueModel->getId());
     }
 }
 function newVenueJSON(Request $request, Application $app)
 {
     $venue = new VenueModel();
     $data = array();
     if ('POST' == $request->getMethod()) {
         if ($request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
             $venue->setTitle($request->request->get('title'));
             $venue->setDescription($request->request->get('description'));
             if (intval($request->request->get('country'))) {
                 $venue->setCountryId(intval($request->request->get('country')));
             }
             $venueRepository = new VenueRepository();
             $venueRepository->create($venue, $app['currentSite'], $app['currentUser']);
             $data['venue'] = array('id' => $venue->getId(), 'slug' => $venue->getSlug(), 'title' => $venue->getTitle());
         }
     }
     $response = new Response(json_encode($data));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 function testVenue()
 {
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     TimeSource::mock(2013, 7, 1, 7, 0, 0);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     $this->assertTrue($userRepo->hasMadeAnyEdits($user));
 }
 function testIntegration2()
 {
     $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 venue
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     ## Edit venue
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $venue = $venueRepo->loadById($venue->getId());
     $venue->setDescription("testy");
     $venue->setLat(3.6);
     $venue->setLng(3.7);
     $venueRepo->edit($venue, $user);
     ## Delete venue
     \TimeSource::mock(2014, 1, 1, 15, 0, 0);
     $venueRepo->delete($venue, $user);
     ## Now save changed flags on these .....
     $venueHistoryRepo = new VenueHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM venue_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $venueHistory = new VenueHistoryModel();
         $venueHistory->setFromDataBaseRow($data);
         $venueHistoryRepo->ensureChangedFlagsAreSet($venueHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setVenue($venue);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeVenueHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(3, count($histories));
     #the delete
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[0]->getLatChanged());
     $this->assertEquals(false, $histories[0]->getLngChanged());
     #the edit
     $this->assertEquals(FALSE, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
     $this->assertEquals(true, $histories[1]->getLatChanged());
     $this->assertEquals(true, $histories[1]->getLngChanged());
     #the create
     $this->assertEquals(true, $histories[2]->getTitleChanged());
     $this->assertEquals(true, $histories[2]->getDescriptionChanged());
     $this->assertEquals(true, $histories[2]->getCountryIdChanged());
     $this->assertEquals(false, $histories[2]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[2]->getLatChanged());
     $this->assertEquals(false, $histories[2]->getLngChanged());
 }
 function build(Application $app)
 {
     $this->paramaters = array('daysAheadInNextBox' => 3, 'showCharsOfDescription' => 0, 'refreshInMinutes' => 0, 'MAX_EVENT_QUERIES_ON_EVENT_BOARD' => self::$MAX_EVENT_QUERIES_ON_EVENT_BOARD, 'configParameters' => array());
     if (isset($_GET['daysAheadInNextBox']) && intval($_GET['daysAheadInNextBox']) >= 0) {
         $this->paramaters['daysAheadInNextBox'] = intval($_GET['daysAheadInNextBox']);
         $this->paramaters['configParameters']['daysAheadInNextBox'] = $_GET['daysAheadInNextBox'];
     }
     if (isset($_GET['showCharsOfDescription']) && intval($_GET['showCharsOfDescription']) >= 0) {
         $this->paramaters['showCharsOfDescription'] = intval($_GET['showCharsOfDescription']);
         $this->paramaters['configParameters']['showCharsOfDescription'] = $_GET['showCharsOfDescription'];
     }
     if (isset($_GET['refreshInMinutes']) && intval($_GET['refreshInMinutes']) >= 0) {
         $this->paramaters['refreshInMinutes'] = intval($_GET['refreshInMinutes']);
         $this->paramaters['configParameters']['refreshInMinutes'] = $_GET['refreshInMinutes'];
     }
     $areaRepository = new AreaRepository();
     $groupRepository = new GroupRepository();
     $venueRepository = new VenueRepository();
     $this->paramaters['data'] = array();
     for ($i = 0; $i <= self::$MAX_EVENT_QUERIES_ON_EVENT_BOARD; $i++) {
         $area = null;
         if (isset($_GET['eventArea' . $i])) {
             $area = $this->getIdFromPassedVariable($_GET['eventArea' . $i]);
             $this->paramaters['configParameters']['eventArea' . $i] = $_GET['eventArea' . $i];
         }
         $group = null;
         if (isset($_GET['eventGroup' . $i])) {
             $group = $this->getIdFromPassedVariable($_GET['eventGroup' . $i]);
             $this->paramaters['configParameters']['eventGroup' . $i] = $_GET['eventGroup' . $i];
         }
         $venue = null;
         if (isset($_GET['eventVenue' . $i])) {
             $venue = $this->getIdFromPassedVariable($_GET['eventVenue' . $i]);
             $this->paramaters['configParameters']['eventVenue' . $i] = $_GET['eventVenue' . $i];
         }
         if ($area || $group || $venue) {
             $queryData = array('area' => null, 'group' => null, 'venue' => null, 'minorImportance' => false, 'query' => new EventRepositoryBuilder());
             $queryData['query']->setSite($app['currentSite']);
             $queryData['query']->setAfterNow();
             $queryData['query']->setIncludeDeleted(false);
             if ($area) {
                 $areaObj = $areaRepository->loadBySlug($app['currentSite'], $area);
                 if ($areaObj) {
                     $queryData['area'] = $areaObj;
                     $queryData['query']->setArea($areaObj);
                 }
             }
             if ($group) {
                 $groupObj = $groupRepository->loadBySlug($app['currentSite'], $group);
                 if ($groupObj) {
                     $queryData['group'] = $groupObj;
                     $queryData['query']->setGroup($groupObj);
                 }
             }
             if ($venue) {
                 $venueObj = $venueRepository->loadBySlug($app['currentSite'], $venue);
                 if ($venueObj) {
                     $queryData['venue'] = $venueObj;
                     $queryData['query']->setVenue($venueObj);
                 }
             }
             if (isset($_GET['eventMinorImportance' . $i]) && $_GET['eventMinorImportance' . $i] == 'yes') {
                 $queryData['minorImportance'] = true;
                 $this->paramaters['configParameters']['eventMinorImportance' . $i] = 'yes';
             }
             $this->paramaters['data'][] = $queryData;
         }
     }
     if (count($this->paramaters['data']) == 0) {
         $queryData = array('area' => null, 'group' => null, 'venue' => null, 'minorImportance' => false, 'query' => new EventRepositoryBuilder());
         $queryData['query']->setSite($app['currentSite']);
         $queryData['query']->setAfterNow();
         $queryData['query']->setIncludeDeleted(false);
         $this->paramaters['data'][] = $queryData;
     }
 }
 protected function run()
 {
     $this->localTimeZone = new \DateTimeZone("Europe/London");
     $siteRepo = new \repositories\SiteRepository();
     $site = $siteRepo->loadById($this->app['config']->singleSiteID);
     // TODO assumes single site!
     $areaRepository = new AreaRepository();
     $venueRepository = new VenueRepository();
     $countryRepository = new CountryRepository();
     $countries = array();
     $humanPopItRepository = new HumanPopItInfoRepository();
     $areaMapItRepo = new AreaMapItInfoRepository();
     $out = array('data' => array(), 'areasPastEvents' => array());
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setIncludeDeleted(true);
     $erb->setIncludeCancelled(true);
     $erb->setAfterNow();
     foreach ($erb->fetchAll() as $event) {
         $venue = null;
         $country = null;
         $area = null;
         $humans = array();
         if ($event->getCountryId()) {
             if (!isset($countries[$event->getCountryId()])) {
                 $countries[$event->getCountryId()] = $countryRepository->loadById($event->getCountryId());
             }
             $country = $countries[$event->getCountryId()];
         }
         if ($event->getVenueId()) {
             $venue = $venueRepository->loadById($event->getVenueId());
         }
         if ($event->getAreaId()) {
             $area = $areaRepository->loadById($event->getAreaId());
         } else {
             if ($venue && $venue->getAreaId()) {
                 $area = $areaRepository->loadById($venue->getAreaId());
             }
         }
         $thisOut = $this->addEvent($event, $venue, $area, $country);
         $thisOut['humans'] = array();
         $mapitids = array();
         if ($area) {
             $areamapit = $areaMapItRepo->getByAreaID($area->getId());
             if ($areamapit) {
                 $mapitids[] = $areamapit->getMapitId();
             }
         }
         $hrb = new HumanRepositoryBuilder();
         $hrb->setHumansForEvent($event);
         foreach ($hrb->fetchAll() as $human) {
             $popit = $humanPopItRepository->getByHumanID($human->getId());
             $thisOut['humans'][] = array('popit_id' => $popit->getPopitId());
             $arb = new AreaRepositoryBuilder();
             $arb->setIncludeDeleted(false);
             $arb->setHuman($human);
             foreach ($arb->fetchAll() as $areaForHuman) {
                 if (!$area || $area->getId() != $areaForHuman->getId()) {
                     $areamapit = $areaMapItRepo->getByAreaID($areaForHuman->getId());
                     if ($areamapit) {
                         $mapitids[] = $areamapit->getMapitId();
                     }
                 }
             }
         }
         $thisOut['mapitids'] = array_values(array_unique($mapitids));
         $out['data'][] = $thisOut;
     }
     $arb = new \com\meetyournextmp\repositories\builders\AreaRepositoryBuilder();
     $arb->setLimit(1000);
     $arb->setIncludeDeleted(false);
     $arb->setIsMapItAreaOnly(true);
     foreach ($arb->fetchAll() as $area) {
         $erb = new EventRepositoryBuilder();
         $erb->setIncludeDeleted(false);
         $erb->setIncludeCancelled(false);
         $erb->setArea($area);
         $erb->setBeforeNow();
         $areamapit = $areaMapItRepo->getByAreaID($area->getId());
         $out['areasPastEvents'][$areamapit->getMapitId()] = $erb->fetchCount();
     }
     file_put_contents(APP_ROOT_DIR . DIRECTORY_SEPARATOR . 'webSingleSite' . DIRECTORY_SEPARATOR . 'datadump' . DIRECTORY_SEPARATOR . 'ynmpread.json', json_encode($out));
     return array('result' => 'ok');
 }
 function moveToArea($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Event does not exist.");
     }
     $gotResultEditedVenue = false;
     $gotResultEditedEvent = false;
     if ($request->request->get('area') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         if (intval($request->request->get('area'))) {
             $areaRepository = new AreaRepository();
             $area = $areaRepository->loadBySlug($app['currentSite'], $request->request->get('area'));
             if ($area && (!$this->parameters['area'] || $area->getId() != $this->parameters['area']->getId())) {
                 if ($this->parameters['venue']) {
                     $this->parameters['venue']->setAreaId($area->getId());
                     $venueRepository = new VenueRepository();
                     $venueRepository->edit($this->parameters['venue'], $app['currentUser']);
                     $gotResultEditedVenue = true;
                 } else {
                     $this->parameters['event']->setAreaId($area->getId());
                     $eventRepository = new EventRepository();
                     $eventRepository->edit($this->parameters['event'], $app['currentUser']);
                     $gotResultEditedEvent = true;
                 }
                 $app['flashmessages']->addMessage('Thank you; event updated!');
             }
         }
     }
     if ($gotResultEditedEvent) {
         $repo = new EventRecurSetRepository();
         if ($repo->isEventInSetWithNotDeletedFutureEvents($this->parameters['event'])) {
             return $app->redirect("/event/" . $this->parameters['event']->getSlugForUrl() . '/edit/future');
         } else {
             return $app->redirect("/event/" . $this->parameters['event']->getSlugForUrl());
         }
     } else {
         return $app->redirect("/event/" . $this->parameters['event']->getSlugForUrl() . '/');
     }
 }