public function go() { $event = new EventModel(); $event->setSummary($this->summary); $event->setDescription($this->description); $event->setUrl($this->url); $event->setTimezone($this->timezone); $event->setStartAt($this->start_at); $event->setEndAt($this->end_at); $event->setCountryId($this->country->getId()); $eventRepo = new EventRepository(); $eventRepo->create($event, $this->site, $this->user, $this->group); }
public function getNewEventOnArbitraryDate(EventModel $event, \DateTime $newDate) { $timeZoneUTC = new \DateTimeZone("UTC"); $timeZone = new \DateTimeZone($this->timeZoneName); $start = clone $newDate; $start->setTimezone($timeZone); $start->setTime($event->getStartAtInTimezone()->format('G'), $event->getStartAtInTimezone()->format('i'), $event->getStartAtInTimezone()->format('s')); $start->setTimezone($timeZoneUTC); $end = clone $start; $end->add($event->getStartAtInUTC()->diff($event->getEndAtInUTC(), true)); $newEvent = new EventModel(); $newEvent->setGroupId($event->getGroupId()); $newEvent->setVenueId($event->getVenueId()); $newEvent->setCountryId($event->getCountryId()); $newEvent->setEventRecurSetId($this->id); $newEvent->setSummary($event->getSummary()); $newEvent->setDescription($event->getDescription()); $newEvent->setStartAt($start); $newEvent->setEndAt($end); foreach ($this->customFields as $customField) { if ($event->hasCustomField($customField)) { $newEvent->setCustomField($customField, $event->getCustomField($customField)); } } return $newEvent; }
function addDataToEventBeforeCheck(EventModel $eventModel) { if ($this->draftEvent->hasDetailsValue('event.country_id')) { $eventModel->setCountryId($this->draftEvent->getDetailsValue('event.country_id')); } if ($this->draftEvent->hasDetailsValue('event.timezone')) { $eventModel->setTimezone($this->draftEvent->getDetailsValue('event.timezone')); } if ($this->draftEvent->hasDetailsValue('event.start_at')) { $eventModel->setStartAt($this->draftEvent->getDetailsValueAsDateTime('event.start_at')); } if ($this->draftEvent->hasDetailsValue('event.end_at')) { $eventModel->setEndAt($this->draftEvent->getDetailsValueAsDateTime('event.end_at')); } }
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()); }
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; }
/** * * Gets new monthly events on the basis that the event is on the something day in the week. * eg. 2nd tuesday of month * eg. 4th saturday in month * * @param \models\EventModel $event * @param type $monthsInAdvance * @return \models\EventModel */ public function getNewMonthlyEventsOnSetDayInWeek(EventModel $event, $daysInAdvance = 186) { // constants $interval = new \DateInterval('P1D'); $timeZone = new \DateTimeZone($this->timeZoneName); $timeZoneUTC = new \DateTimeZone("UTC"); // calculate which day of month it should be $dayOfWeek = $event->getStartAt()->format("N"); $thisStart = new \DateTime($event->getStartAt()->format('Y-m-d H:i:s'), $timeZoneUTC); $thisEnd = new \DateTime($event->getEndAt()->format('Y-m-d H:i:s'), $timeZoneUTC); $thisStart->setTimeZone($timeZone); $thisEnd->setTimeZone($timeZone); $weekInMonth = 1; while ($thisStart->format('d') > 1) { $thisStart->sub($interval); $thisEnd->sub($interval); if ($thisStart->format("N") == $dayOfWeek) { ++$weekInMonth; } } // vars $out = array(); $currentMonthLong = $thisStart->format('F'); $currentMonthShort = $thisStart->format('M'); $currentMonth = $thisStart->format('m'); $currentWeekInMonth = 1; $loopStop = \TimeSource::time() + $daysInAdvance * 24 * 60 * 60; while ($thisStart->getTimestamp() < $loopStop) { $thisStart->add($interval); $thisEnd->add($interval); //print $thisStart->format("r")." current month: ".$currentMonth." current week: ".$currentWeekInMonth."\n"; if ($currentMonth != $thisStart->format('m')) { $currentMonth = $thisStart->format('m'); $currentWeekInMonth = 1; } if ($thisStart->format("N") == $dayOfWeek) { if ($currentWeekInMonth == $weekInMonth && $thisStart->getTimestamp() > \TimeSource::time()) { $start = clone $thisStart; $end = clone $thisEnd; $start->setTimeZone($timeZoneUTC); $end->setTimeZone($timeZoneUTC); $include = true; if ($include) { $newEvent = new EventModel(); $newEvent->setGroupId($event->getGroupId()); $newEvent->setVenueId($event->getVenueId()); $newEvent->setCountryId($event->getCountryId()); $newEvent->setEventRecurSetId($this->id); $newEvent->setSummary($event->getSummary()); $newEvent->setDescription($event->getDescription()); $newEvent->setStartAt($start); $newEvent->setEndAt($end); foreach ($this->customFields as $customField) { if ($event->hasCustomField($customField)) { $newEvent->setCustomField($customField, $event->getCustomField($customField)); } } if (stripos($newEvent->getSummary(), $currentMonthLong) !== false) { $newEvent->setSummary(str_ireplace($currentMonthLong, $newEvent->getStartAt()->format('F'), $newEvent->getSummary())); } else { if (stripos($newEvent->getSummary(), $currentMonthShort) !== false) { $newEvent->setSummary(str_ireplace($currentMonthShort, $newEvent->getStartAt()->format('M'), $newEvent->getSummary())); } } $out[] = $newEvent; } } ++$currentWeekInMonth; } } return $out; }