Mix and sort multiple models/blueprints

Hi Sonja.

Thank you for your answer.
Regarding the potential performance issues, I’ll try to deal with a custom cache.

Shows belong to a “season”, they’re stored in /content/seasons/2019-2020/. Rendezvous are in /content/rendezvous/. To group shows by day, I used the solution you provided here: Create a collection of pages from a structure field - #10 by texnixe.

# controllers/calendar.php

return function ($site, $page, $kirby) {

  // get future shows
  $shows = page("seasons/2019-2020")->children()->listed()->filter(function ($child) {
      # what should I use to grab only future shows ?
  });

  // get all dates
  foreach($shows as $show) {
      $dates = $show->dates()->toStructure()->pluck('date');
      sort($dates);
      foreach($dates as $date) {
          $mydates[] = strtotime($date);
      }        
  }

  // deduplicate + sort
  $mydates = array_unique($mydates, SORT_NUMERIC);
  sort($mydates);

  return [
      'shows' => $shows,
      'dates' => $mydates
  ];
};

function getShowsPerDate($shows, $day) {
    $showsPerDay = $shows->filter(function($child) use($day) {
        $dates = $child->dates()->toStructure()->pluck('date');
        foreach($dates as $date) {
            $strDates[] = strtotime($date);
        }
        // check if the current day is in dates
        if(in_array($day, $strDates)) {
            return $child;
        }
    });
    return $showsPerDay;
}

Then, in the template:

<?php foreach($dates as $date) :
    $dayShows = getShowsPerDate($shows, $date); ?>
    <?php foreach($dayShows as $show) :?>
        (…)

This logic works for shows (even if I thought I’d better have the final data prepared in the controller without calling getShowsPerDate in the loop), but I don’t know where neither how to plug the rendezvous…

Sure. Nothing fancy here (I simplified):

# show.yml
fields:
  dates:
    label: Dates
    type: structure
    fields:
      place:
        type: text
      date:
        type: date
        label: Date
        time: true
# rendezvous.yml
fields:
  place:
    type: text
  date:
    type: date
    label: Date
    time: true

Thanks a lot for your help. I hope I’ve been clear enough.