all( 2 ) ) > 1 || ( new \Abientot\Repositories\ResourceBookingRepository() )->has_unassigned(); } public static function timezone( array $staff, array $location ): \DateTimeZone { foreach ( array( (string) ( $staff['timezone'] ?? '' ), (string) ( $location['timezone'] ?? '' ), wp_timezone_string() ) as $candidate ) { try { return new \DateTimeZone( $candidate ); } catch ( \Exception $error ) { } } return wp_timezone(); } public static function edit_start( array $booking ): string { if ( ( new \Abientot\Repositories\ResourceBookingRepository() )->snapshot( (int) ( $booking['id'] ?? 0 ) ) ) { return ( new \DateTimeImmutable( (string) $booking['start_utc'], new \DateTimeZone( 'UTC' ) ) )->setTimezone( new \DateTimeZone( (string) $booking['timezone'] ) )->format( 'Y-m-d\TH:i' ); } $staff = ( new StaffRepository() )->find( (int) $booking['staff_id'] ) ?? array(); $location = ( new \Abientot\Repositories\LocationsRepository() )->find( (int) $booking['location_id'] ) ?? array(); return ( new \DateTimeImmutable( (string) $booking['start_utc'], new \DateTimeZone( 'UTC' ) ) )->setTimezone( self::timezone( $staff, $location ) )->format( 'Y-m-d\TH:i' ); } public static function resolve( string $surface, ?array $booking = null, ?int $service_id = null ): array { if ( $booking && (int) $booking['staff_id'] === 0 && ( new \Abientot\Repositories\ResourceBookingRepository() )->snapshot( (int) $booking['id'] ) ) { return array( 'id' => (int) $booking['staff_id'], 'display_name' => StaffFilter::label(), 'timezone' => (string) $booking['timezone'], 'status' => 'active' ); } $repo = new StaffRepository(); $staff = $booking ? $repo->find( (int) $booking['staff_id'] ) : $repo->default_staff(); // Premium may select staff for new/public operations. Historical IDs remain canonical. $staff = apply_filters( 'abientot_booking_staff', $staff, $surface, $booking, $service_id ); return is_array( $staff ) ? $staff : array( 'id' => 0, 'display_name' => '', 'timezone' => '' ); } }