detector = $detector; $this->event_repo = $event_repo; $this->config_repo = $config_repo; } /** * Check for conflicts for a given event and its participants. * * @param Event $event The event to check. * @param array $participants List of participant logins. * @return EventCollection Collection of conflicting events. */ public function get_conflicts( Event $event, array $participants ): EventCollection { // All-day / untimed events are informational — they should never // trigger or be considered for scheduling conflicts. if ( $event->isAllDay() ) { return new EventCollection( [] ); } $limit_val = $this->config_repo->get( 'LIMIT_APPTS' ); $limit_appts = $limit_val !== null ? (int) $limit_val : 1; if ( $limit_appts <= 0 ) { return new EventCollection( [] ); } // Buffer range slightly to be safe (e.g., check the whole day) $range = new DateRange( $event->start()->modify( '-1 day' ), $event->end()->modify( '+1 day' ) ); // Fetch all events where any of these participants are involved $existing_events = $this->event_repo->findByDateRange( $range, null, null, $participants ); // Exclude global/system events (holidays) and all-day events — // they are informational, not real scheduling commitments. $existing_events = array_values( array_filter( $existing_events, fn( Event $e ) => $e->createdBy() !== self::SYSTEM_CREATOR && ! $e->isAllDay() ) ); $overlaps = $this->detector->detectConflicts( $event, new EventCollection( $existing_events ), $limit_appts ); // A conflict only exists if total overlapping events (including this one) > limit if ( count( $overlaps ) + 1 <= $limit_appts ) { return new EventCollection( [] ); } return $overlaps; } }