I need help with the combination of two filters

We are on the page of an ensemble member.
This is working code that lists all the plays of this person.

<?php 
$engagiertIn = $pages->find('spielzeiten')->children()->children()
    ->filter(function($child) use($page) {
      $people = new Pages();
      foreach ($child->menschen()->toStructure() as $item) {
        $people->add($item->mensch()->toPages(','));
      }
      return $people->has($page);
  });
?> 

<?php if($engagiertIn->isNotEmpty()): ?>
  <?php foreach ($engagiertIn as $stueck): ?>
    <a href="<?= $stueck->url() ?>"><?= $stueck->title() ?></a>
  <?php endforeach ?>
<?php endif ?> 

This is a working code for a loop through all calendar dates within two key dates - not related to this person.

<?php 
$daten = $spielzeit->children()->unlisted()->children()->listed();
$sichtbare = $daten->filter(function ($child) {
  $heute = date("Ymd"); return (
    $child->sichtbarab()->toDate("YMMdd") <= $heute &&
    $child->datum()->toDate("YMMdd") >= $heute
  );
}); ?>


<?php snippet("kalender", ['items' => $sichtbare])  ?>

Can I combine these two filters so that I only receive calendar data for this person? I’ve tried a few things, but I’m not getting anywhere. Can I ask something like that here, or is this more of a Discord situation?

But this:

and this

are supposed to be the same pages to filter, although the queried pages are different?

Sorry. The second loop looks completely like this. It is globally applicable. Wherever I need all the calendar dates of the shows.

<?php $spielzeiten = page("spielzeiten")->children()->listed() ?>

<?php foreach ($spielzeiten as $spielzeit): ?>
          
<h1><?= $spielzeit->title() ?></h1>

<?php 
  // all individual data per play
  $daten = $spielzeit->children()->unlisted()->children()->listed();

  $sichtbare = $daten->filter(function ($child) {
    $heute = date("Ymd"); return (
      $child->sichtbarab()->toDate("YMMdd") <= $heute &&
      $child->datum()->toDate("YMMdd") >= $heute
    );
  }); 
?>

<?php snippet("kalender", ['items' => $sichtbare])  ?>

<?php endforeach ?>

The first loop lists all the pieces for an actor in which he is assigned to ‘menschen’ via structure. (on his own single page).

Not easy without the structure before me (and I will never get to terms with such a mix of English code and German field and variable names), but I guess you would need some like
Assuming $page is the current actor page:

 $sichtbare = $daten->filter(function ($child) use($page) {
    $heute = date("Ymd"); 
      // if I got the structure right, the parent of $child is the play that holds the data for the actors involved:
    $people = new Pages();
    foreach ($child->parent()->menschen()->toStructure() as $item) {
        $people->add($item->mensch()->toPages(','));
     }
    return 
      $child->sichtbarab()->toDate("YMMdd") <= $heute &&
      $child->datum()->toDate("YMMdd") >= $heute &&
      $people->has($page);
  });

This definitely needs cleaning up, i.e. move stuff to separate methods

True. In addition, my English is terrible. :slight_smile:
Let’s freeze it like this. I’m convinced I can make it clear to the customer that they don’t need that.

If it had been very easy right now, I would have done it.
But the effort is out of proportion to the benefit.

That’s right.