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()));
 }
 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()));
 }
 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());
 }
 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 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 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 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());
     }
 }