Hello @distantnative and thank you for your interest.
For your understanding, the page is creating a programme for a congress / symposium that is called the IMPS. It grabs all information from a sibling page that is called abstracts. The abstracts page has a bunch of children with the information on the talks. Each of the children represents one talk and contains information such as talk title, date (date and time), speaker details and an summary. The programme page grabs that information and displays it in an overview. The production page runs on kirby 4.6.0 and can be seen here.
These are the relevant requested files:
The ‘abstracts’ collection file:
return function ($site) {
// create a collection of all abstracts in this IMPS.
if ($site->page()->parent()->hasTemplate('imps') and $site->page()->siblings()->template('abstracts')->children()->listed()) {
$collection = $site->page()->siblings()->template('abstracts')->children()->listed()->sortBy('posno', 'asc', 'title', 'asc');
}
else {
$collection = null;
}
return $collection;
};
The page controller:
return function ($page, $kirby) {
// get the root of this year's / this particular IMPS
$imps = $page->parent();
// get the collection of abstracts to obtain the information for the talks
$abstracts = $kirby->collection('abstracts');
// Error if no abstracts found
if($abstracts->isEmpty() or $abstracts->count() == 0) {
throw new Exception("Controller Error: No abstract pages found for this IMPS.");
}
// sort talks by date
$abstracts = $abstracts->sortBy('date', 'asc');
// filter all abstracts by the date. The date parameter has to be present to group by in the next step.
$abstracts = $abstracts->filter(
fn ($page) => $page->content()->date()->isNotEmpty()
);
// function that returns the formatted date reduced to the date without the time so that the talks/abstracts can be grouped by day.
$callback = function($f) {
if($f->date() && $f->date()->isNotEmpty()) {
return $f->date()->toDate('yyyy-MM-dd'); /* appears to require ICU datetime format. */
} else {
return 'undated';
}
};
// group abstracts by the date field in the abstracts content using the callback filter above.
$days = $abstracts->group($callback);
// get the coffee breaks and other events
$breaks = $page->breaks()->toStructure()->sortBy('date', 'asc');
return [
'imps' => $imps,
'days' => $days,
'breaks' => $breaks
];
The page itself is only some HTML containers and an include statement for the relevant code snippet. For my debugging efforts I have included a single line of code at the top of the snippet that dumps the $days
variable and then exits. I therefore assume that all further code is irrelevant.
<?php echo "Days: "; dump($days); exit(); ?>
I use git to checkout the 4.6.0 tag or the 5.0.0.-beta2 tag on the kirby folder and can thus switch directly between the two without changing any other code.
$ website/kirby: git checkout tags/4.6.0
$ website/kirby: git checkout tags/5.0.0-beta.2
The resulting dump shows the information I stated in my original question shown above. The collections groups as expected in 4.6.0 but does not do so in 5.0.0
The only complicated thing I have done here is that I make use fo the intl date functions in a function of the page model which complicated the formatting strings for all date functions. However, that is called later in the code snippet, after the exit()
of my debug dump and thus never executed here. I therefore don’t think it should play a role for this problem. It is the only thing I could think of.
page model:
class ProgrammePage extends Page
{
// create a cover image
public function cover()
{
return $this->content()->cover()->toFile() ?? $this->image();
}
// use the intl date function to show the date in multiple languages
public function intlDate($d, $format = 'YYYY-MM-dd'): string
{
$language = kirby()->language();
if($language->code() == 'de')
{
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN,
$format
);
} else
{
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN,
$format
);
}
return $fmt->format($d);
}
}
I hope this helps in finding the . Many thanks in advance for your efforts.
As a side note. I also have another page that only lists the titles of the abstracts without grouping them and that page works fine on 5.0.0-beta.2. For me it all points to the group()
step.