Events as $group) { foreach ($previousDay->Events as $pGroup) { if ($group && $pGroup) { if ($group->Calendar == $pGroup->Calendar) { $group->GridPosition = $pGroup->GridPosition; $eventPositions[] = $group->GridPosition; } } } } } return $eventPositions; } private function _alignEvents(array $eventPositions, array $events) { $previousCount = count($eventPositions); foreach ($events as $event) { if ($event->GridPosition === NULL) { $event->GridPosition = min( array_diff( range(0, count($events) + $previousCount), $eventPositions ) ); $eventPositions[] = $event->GridPosition; } } usort($events, ['GridEventGroupDTO', '__compare']); return $events; } private function _fillEventGrid(array $events) { $previousEvent = -1; foreach ($events as $event) { $eventStep = $event->GridPosition - $previousEvent; if ($eventStep > 1) { array_splice( $events, $previousEvent + 1, 0, array_fill(0, $eventStep - 1, NULL) ); } $previousEvent = $event->GridPosition; } return $events; } protected function _getGridDay(DateTimeImmutable $date, array $events, CalendarGridDayDTO $previousDay = NULL) { $day = new GroupedCalendarGridDayDTO($date, $events); $eventPositions = $this->_getContinuedEventGridPositions($day, $previousDay); $day->Events = $this->_alignEvents($eventPositions, $day->Events); $day->Events = $this->_fillEventGrid($day->Events); return $day; } } ?>