nouveau-theatre-de-besancon/site/models/event.php

25 lines
880 B
PHP
Raw Normal View History

<?php
class EventPage extends Page {
public function schedule() {
$sessions = $this->isMapadoEvent() != 'true' ? $this->sessions()->toStructure() : $this->remoteSessions()->toStructure();
try {
$firstSession = $sessions->first()->date();
$lastSession = $sessions->last()->date();
} catch (\Throwable $th) {
throw new Exception('Can\'t define sessions for event "' . $this->title()->value() . '".', 1);
}
$startDay = intval($firstSession->toDate('d'));
$startMonth = $firstSession->toDate('MMMM');
$endDay = intval($lastSession->toDate('d'));
$endMonth = $lastSession->toDate('MMMM');
if ($firstSession->toDate('y-M') === $lastSession->toDate('y-M')) {
return $startDay . ' - ' . $endDay . ' ' . $endMonth;
} else {
return $startDay . ' ' . $startMonth . ' - ' . $endDay . ' ' . $endMonth;
}
}
}