function test1()
 {
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $areaRepo = new AreaRepository();
     \TimeSource::mock(2014, 10, 1, 1, 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($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $area = new AreaModel();
     $area->setTitle("test");
     $area->setDescription("test test");
     $areaRepo->create($area, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaDuplicate = new AreaModel();
     $areaDuplicate->setTitle("test Duplicate");
     $areaRepo->create($areaDuplicate, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     \TimeSource::mock(2014, 10, 1, 2, 0, 0);
     $areaRepo->markDuplicate($areaDuplicate, $area, $user);
     $areaChild = new AreaModel();
     $areaChild->setTitle("test Child");
     $areaRepo->create($areaChild, $area, $site, $countryRepo->loadByTwoCharCode('GB'), $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->setAreaId($area->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     ## Test
     $this->assertNotNull($areaRepo->loadById($area->getId()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($area->getId(), $event->getAreaId());
     ## Now Purge!
     $areaRepo->purge($area);
     ## Test
     $this->assertNull($areaRepo->loadById($area->getId()));
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertNull($event->getAreaId());
 }
 function testInChildArea()
 {
     $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());
     $area1 = new AreaModel();
     $area1->setTitle("scotland");
     $area1child = new AreaModel();
     $area1child->setTitle("edinburgh");
     $area2 = new AreaModel();
     $area2->setTitle("england");
     $areaRepo = new AreaRepository();
     $countryRepo = new CountryRepository();
     $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1);
     $areaRepo->create($area1child, $area1, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area1child);
     $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->buildCacheAreaHasParent($area2);
     $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));
     $event->setAreaId($area1child->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area1child);
     $events = $erb->fetchAll();
     $this->assertEquals(1, count($events));
     $this->assertEquals($event->getId(), $events[0]->getId());
     #test - don't find in erb
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setArea($area2);
     $events = $erb->fetchAll();
     $this->assertEquals(0, count($events));
 }
 function testScoreAreaSameButByVenue()
 {
     $site = new SiteModel();
     $eventNew = new models\EventModel();
     $eventNew->setStartAt(new \DateTime("12th April 2012 10:00:00"));
     $eventNew->setEndAt(new \DateTime("12th April 2012 13:00:00"));
     $eventNew->setAreaId(34);
     $eventExisting = new models\EventModel();
     $eventExisting->setFromDataBaseRow(array('id' => 1, 'site_id' => 1, 'slug' => 1, 'summary' => 'Cat', 'description' => 'Cat', 'start_at' => '2014:01:01 01:01:01', 'end_at' => '2014:01:01 01:01:01', 'created_at' => '2013:01:01 01:01:01', 'is_deleted' => 0, 'is_cancelled' => 0, 'event_recur_set_id' => null, 'country_id' => 1, 'venue_id' => 12, 'area_id' => null, 'timezone' => 'Europe/London', 'import_id' => null, 'import_url_id' => null, 'url' => null, 'ticket_url' => null, 'area_information_id' => 34, 'area_title' => 'Edinburgh', 'area_slug' => '1', 'is_virtual' => 0, 'is_physical' => 0, 'is_duplicate_of_id' => null, 'custom_fields' => null, 'custom_fields_changed' => null));
     $sfde = new SearchForDuplicateEvents($eventNew, $site);
     $score = $sfde->getScoreForConsideredEvent($eventExisting);
     $this->assertEquals(1, $score);
 }
 function test1()
 {
     \TimeSource::mock(2014, 1, 1, 0, 0, 0);
     $this->addCountriesToTestDB();
     $countryRepo = new CountryRepository();
     $areaRepo = new AreaRepository();
     $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($countryRepo->loadByTwoCharCode('GB')), $this->getSiteQuotaUsedForTesting());
     $area1 = new AreaModel();
     $area1->setTitle("test");
     $area1->setDescription("test test");
     $area2 = new AreaModel();
     $area2->setTitle("test this looks similar");
     $area2->setDescription("test test");
     $areaRepo->create($area1, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaRepo->create($area2, null, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $areaChild = new AreaModel();
     $areaChild->setTitle("child");
     $areaChild->setDescription("child");
     $areaRepo->create($areaChild, $area2, $site, $countryRepo->loadByTwoCharCode('GB'), $user);
     $area1 = $areaRepo->loadById($area1->getId());
     $area2 = $areaRepo->loadById($area2->getId());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venue->setAreaId($area2->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $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->setAreaId($area2->getId());
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     // Test before
     $venue = $venueRepo->loadById($venue->getId());
     $this->assertEquals($area2->getId(), $venue->getAreaId());
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($area2->getId(), $event->getAreaId());
     $areaChild = $areaRepo->loadById($areaChild->getId());
     $this->assertEquals($area2->getId(), $areaChild->getParentAreaId());
     $area2 = $areaRepo->loadById($area2->getId());
     $this->assertFalse($area2->getIsDeleted());
     $this->assertNull($area2->getIsDuplicateOfId());
     // Mark
     \TimeSource::mock(2014, 1, 1, 2, 0, 0);
     $areaRepo->markDuplicate($area2, $area1, $user);
     // Test Duplicate
     $venue = $venueRepo->loadById($venue->getId());
     $this->assertEquals($area1->getId(), $venue->getAreaId());
     $event = $eventRepository->loadBySlug($site, $event->getSlug());
     $this->assertEquals($area1->getId(), $event->getAreaId());
     $areaChild = $areaRepo->loadById($areaChild->getId());
     $this->assertEquals($area1->getId(), $areaChild->getParentAreaId());
     $area2 = $areaRepo->loadById($area2->getId());
     $this->assertTrue($area2->getIsDeleted());
     $this->assertEquals($area1->getId(), $area2->getIsDuplicateOfId());
 }
 protected function newEventFromImportedEventModel(ImportedEventModel $importedEvent)
 {
     $event = new EventModel();
     $event->setFromImportedEventModel($importedEvent);
     if ($this->site->getIsFeaturePhysicalEvents() && !$this->site->getIsFeatureVirtualEvents()) {
         $event->setIsPhysical(true);
         $event->setIsVirtual(false);
     } else {
         if (!$this->site->getIsFeaturePhysicalEvents() && $this->site->getIsFeatureVirtualEvents()) {
             $event->setIsPhysical(false);
             $event->setIsVirtual(true);
         }
     }
     if ($this->country) {
         // country is set on importer.
         $event->setCountryId($this->country->getId());
         $timezones = $this->country->getTimezonesAsList();
         if ($importedEvent->getTimezone() && in_array($importedEvent->getTimezone(), $timezones)) {
             $event->setTimezone($importedEvent->getTimezone());
         } else {
             if ($timezones) {
                 // take first timezone in that country at random :-/
                 $event->setTimezone($timezones[0]);
             }
         }
         if ($this->area) {
             $event->setAreaId($this->area->getId());
         }
     } else {
         // if no country set on importer, we just pick first one at random :-/
         $crb = new \repositories\builders\CountryRepositoryBuilder();
         $crb->setSiteIn($this->site);
         $crb->setLimit(1);
         $countries = $crb->fetchAll();
         if (count($countries) > 0) {
             $country = $countries[0];
             $event->setCountryId($country->getId());
             $timezones = $country->getTimezonesAsList();
             if ($importedEvent->getTimezone() && in_array($importedEvent->getTimezone(), $timezones)) {
                 $event->setTimezone($importedEvent->getTimezone());
             } else {
                 if ($timezones) {
                     // take first timezone in that country at random :-/
                     $event->setTimezone($timezones[0]);
                 }
             }
         }
     }
     return $event;
 }
 public function moveAllFutureEventsAtVenueToNoSetVenueWithMetaData(VenueModel $venue, EventEditMetaDataModel $eventEditMetaDataModel)
 {
     global $DB;
     $statFetch = $DB->prepare("SELECT event_information.* FROM event_information WHERE venue_id = :venue_id AND start_at > :start_at AND is_deleted='0'");
     $statFetch->execute(array('venue_id' => $venue->getId(), 'start_at' => \TimeSource::getFormattedForDataBase()));
     while ($data = $statFetch->fetch()) {
         $event = new EventModel();
         $event->setFromDataBaseRow($data);
         $event->setVenueId(null);
         $event->setAreaId($venue->getAreaId());
         $this->eventDBAccess->update($event, array('venue_id', 'area_id'), $eventEditMetaDataModel);
     }
 }
 function addDataToEventBeforeCheck(EventModel $eventModel)
 {
     if ($this->draftEvent->getDetailsValue('area.id')) {
         $eventModel->setAreaId($this->draftEvent->getDetailsValue('area.id'));
     }
     if ($this->draftEvent->getDetailsValue('venue.id')) {
         $eventModel->setVenueId($this->draftEvent->getDetailsValue('venue.id'));
     }
 }