Hello,
I need to generate a list of events (out of subpages), sorted by start date, end date and start time (with the date as headline for each day), wich is working so far. A subpage can actually have up to 5 events (each with start date, end date and start time). I just manage to filter and sort them with 1 event – is there a clever way to do this for all 5 events over all subpages ?
Thanks a lot in advance !
Blueprint
dateStart1:
label: Start Date
type: date
format: DD/MM/YYYY
dateEnd1:
label: End Date
type: date
format: DD/MM/YYYY
timeStart1:
label: Time Start
type: time
format: 24
timeEnd1:
label: Time End
type: time
format: 24
dateStart2:
...
Template
<?php
// Set collection of events
$events = $pages->find('projekte')->children()->visible()->sortBy('date', 'dateStart1', 'asc')->sortBy('timeStart1', 'asc');
// Set start date an duration for time span
$startDate = '01.11.2018';
$days = 18;
// Set counter for days
$i = 0;
//Count up days and date until $days is reached
while($i < $days) {
$date = date('d.m.Y', strtotime($startDate. ' + ' . $i++ . 'days'));
// Set counter for $headline, 0 = create headline
$headline = 0;
// Display and sort events by start/end date and start/end time -->
foreach($events as $event) {
// Check if event is taking place this day
if($event->date('d.m.Y', 'dateStart1') == $date || $event->date('d.m.Y', 'dateStart1') <= $date && $event->date('d.m.Y', 'dateEnd1') >= $date){
// Create headline if first event of day
if($headline == 0) {
echo "<hr />";
echo "<b>" . $date . "</b><br />";
$headline++;
}
// Set counter for $headline to 1 = don't create headline
$headline = 1;
// Display start time, end time, title
echo $event->timeStart1()->html();
if($event->timeEnd1()->isNotEmpty()){
echo "—" . $event->timeEnd1()->html();
}
echo ", ". $event->title()->html() . "<br />";
}
}
}
?>