with(['role', 'element']) ->where('subject_type', $subject->getMorphClass()) ->where('subject_id', $subject->getKey()) ->whereHas('role', fn ($query) => $query->whereIn('slug', self::ROLES)) ->orderBy('position') ->orderBy('id') ->get() ->sortBy(fn (PresentationAssignment $row): int => (int) array_search($row->role?->slug, self::ROLES, true)) ->values(); $unreleased = null; foreach ($assigned as $assignment) { $element = $assignment->element; if (! $element instanceof ContentElement || $element->archived_at !== null || $element->output_class !== 'film') { continue; } $present = $this->media->present($element); if ($present !== null && $present->kind === 'film') { return $this->found($present->url, $present->title, $assignment->role?->slug === 'trailer' ? 'trailer' : 'vorschauclip'); } $unreleased ??= $element; } if ($subject instanceof ContentElement && $subject->output_class === 'film') { $own = $this->media->present($subject); if ($own !== null && $own->kind === 'film') { return $this->found($own->url, $own->title, 'teaser'); } } if (! $preview) { return $this->none(); } if ($unreleased instanceof ContentElement) { $title = (string) ($unreleased->display_title ?: $unreleased->working_title); return $this->none('Der Trailer „'.$title.'“ ist nicht für die Website freigegeben; öffentlich bleibt es beim Kartenbild (Medium öffnen → Reiter „Website“ → freigeben).'); } return $this->none(null, 'Kein Trailer zugeordnet; die Karte zeigt nur das Bild (Rolle „Trailer“ in der Präsentation des Mediums).'); } /** * @return array{url: string|null, title: string, source: string, notice: string|null, hint: string|null} */ private function found(string $url, string $title, string $source): array { return ['url' => $url, 'title' => $title, 'source' => $source, 'notice' => null, 'hint' => null]; } /** * @return array{url: string|null, title: string, source: string, notice: string|null, hint: string|null} */ private function none(?string $notice = null, ?string $hint = null): array { return ['url' => null, 'title' => '', 'source' => 'none', 'notice' => $notice, 'hint' => $hint]; } }