isMapadoEvent() == 'true'; $arraySession = $session->toArray(); $arraySession['title'] = $event->title()->value(); $arraySession['authors'] = $event->authors(); $arraySession['place'] = $event->place(); $arraySession['public'] = $event->public(); $arraySession['event-url'] = $event->url(); $arraySession['duration'] = $isMapadoEvent ? $event->remoteDuration() : $event->duration(); $arraySession['ticketingUrl'] = $isMapadoEvent ? $session->ticketingUrl() : false; $arraySession['bookableStock'] = $isMapadoEvent ? $session->bookableStock()->value() : 'free'; $arraySession['color'] = $event->color(); return $arraySession; } return function($page) { $currentSeason = $page->children()->first(); $today = date('Ymd'); $previousEvents = new Pages(); $nextEvents = new Pages(); $currentSeasonSessions = []; $previousSeasons = $page->children()->without($currentSeason); foreach ($currentSeason->children() as $event) { $sessions = $event->isMapadoEvent() == 'true' ? $event->remoteSessions() : $event->sessions(); $isStillShowing = false; foreach ($sessions->toStructure() as $session) { $arraySession = createArraySession($event, $session); $currentSeasonSessions[] = $arraySession; $sessionDate = str_replace('-', '', $session->date()->toDate('YMMdd')); if ($sessionDate >= $today) { $isStillShowing = true; } } if ($isStillShowing) { $nextEvents->add($event); } else { $previousEvents->add($event); } } return [ 'previousEvents' => $previousEvents, 'nextEvents' => $nextEvents, 'currentSeasonSessions' => sortByMonth($currentSeasonSessions), 'previousSeasons' => $previousSeasons, ]; };