Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m24s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m31s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
31 lines
1.2 KiB
PHP
31 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Events;
|
|
|
|
use App\Models\User;
|
|
use App\Search\GlobalSearch;
|
|
use Inhaus\Plugins\Events\Models\Event;
|
|
|
|
/** Suchquelle für die globale Suche: anstehende Termine zuerst, dann vergangene */
|
|
class EventSearch
|
|
{
|
|
/**
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
public function __invoke(User $user, string $search, int $limit): array
|
|
{
|
|
$query = Event::query()->visibleTo($user)->where('is_published', true);
|
|
GlobalSearch::whereTerms($query, ['title', 'description', 'location'], $search);
|
|
|
|
return $query->orderByRaw('COALESCE(ends_at, starts_at) < ?', [now()])->orderBy('starts_at')->limit($limit)->get()->map(fn (Event $event) => [
|
|
'title' => $event->title,
|
|
'url' => '/termine/'.$event->id,
|
|
'excerpt' => GlobalSearch::excerpt($event->description, $search),
|
|
'meta' => collect([
|
|
$event->all_day ? $event->starts_at->translatedFormat('j. F Y') : $event->starts_at->translatedFormat('j. F Y, H:i').' Uhr',
|
|
$event->location,
|
|
])->filter()->implode(' · '),
|
|
'image' => $event->imageUrl('thumb'),
|
|
])->all();
|
|
}
|
|
}
|