>} */ public function handle( string $query, AccessScope $scope ): array { $q = strtolower( trim( $query ) ); if ( strlen( $q ) < 1 ) { return [ 'items' => [] ]; } $items = []; $customers = $this->customers->handle( 1, 20, $query ); foreach ( $customers['items'] as $row ) { $label = (string) ( $row['display_name'] ?? '' ); $id = (int) ( $row['id'] ?? 0 ); $items[] = [ 'id' => 'customer-' . $id, 'type' => 'customer', 'label' => $label . ' · customer', 'route' => '/customers/' . $id, ]; } foreach ( $this->services->handle()['items'] as $row ) { $name = (string) ( $row['name'] ?? '' ); if ( ! str_contains( strtolower( $name ), $q ) ) { continue; } $items[] = [ 'id' => 'service-' . (string) ( $row['id'] ?? '' ), 'type' => 'service', 'label' => $name . ' · service', 'route' => '/catalogue', ]; } foreach ( $this->agents->handle( $scope )['items'] as $row ) { $name = (string) ( $row['display_name'] ?? '' ); if ( ! str_contains( strtolower( $name ), $q ) ) { continue; } $items[] = [ 'id' => 'agent-' . (string) ( $row['id'] ?? '' ), 'type' => 'agent', 'label' => $name . ' · agent', 'route' => '/catalogue', ]; } $from = $this->clock->now()->modify( '-90 days' ); $to = $this->clock->now()->modify( '+90 days' ); $bookings = $this->bookings->handle( $scope, $from, $to ); foreach ( $bookings as $booking ) { $hay = strtolower( (string) $booking->id() . ' ' . $booking->uuid()->to_string() . ' ' . $booking->status()->value ); if ( ! str_contains( $hay, $q ) ) { continue; } $items[] = [ 'id' => 'booking-' . (string) $booking->id(), 'type' => 'booking', 'label' => 'Booking #' . (string) $booking->id() . ' · ' . $booking->status()->value, 'route' => '/bookings', ]; if ( count( $items ) > 40 ) { break; } } foreach ( $this->settings->all_public() as $key => $value ) { $hay = strtolower( $key . ' ' . ( is_scalar( $value ) ? (string) $value : '' ) ); if ( ! str_contains( $hay, $q ) ) { continue; } $items[] = [ 'id' => 'setting-' . $key, 'type' => 'setting', 'label' => $key . ' · setting', 'route' => '/settings', ]; } return [ 'items' => array_slice( $items, 0, 40 ) ]; } }