public function RoomsEvent::transformToYearlyEvents in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Takes an event that spans several years and transforms it to yearly events
Return value
RoomsEventInterface[] The event split if is necessary, a single item array otherwise.
Overrides RoomsEventInterface::transformToYearlyEvents
File
- includes/
rooms.event.inc, line 98
Class
Code
public function transformToYearlyEvents() {
// If same year return the event
if ($this
->sameYear()) {
$sd = new DateTime();
$sd
->setDate($this
->startYear(), $this
->startMonth(), $this
->startDay());
$ed = new DateTime();
$ed
->setDate($this
->endYear(), $this
->endMonth(), $this
->endDay());
$be = $this
->createEvent($sd, $ed);
return array(
$be,
);
}
// Else split into years
$events = array();
for ($i = $this
->startYear(); $i <= $this
->endYear(); $i++) {
$sd = new DateTime();
$ed = new DateTime();
if ($i == $this
->startYear()) {
$sd
->setDate($i, $this
->startMonth(), $this
->startDay());
$ed
->setDate($i, 12, 31);
$events[$i] = $this
->createEvent($sd, $ed);
}
elseif ($i == $this
->endYear()) {
$sd
->setDate($i, 1, 1);
$ed
->setDate($i, $this
->endMonth(), $this
->endDay());
$events[$i] = $this
->createEvent($sd, $ed);
}
else {
$sd
->setDate($i, 1, 1);
$ed
->setDate($i, 12, 31);
$events[$i] = $this
->createEvent($sd, $ed);
}
}
return $events;
}