*/ public static function card(Idea $idea, ?bool $supported = null): array { return [ 'id' => $idea->id, 'title' => $idea->title, 'excerpt' => Str::limit(preg_replace('/\s+/u', ' ', $idea->body), 180), 'status' => $idea->status, 'status_label' => $idea->statusLabel(), 'supports' => $idea->supports_count, 'comments' => $idea->comments_count, 'supported' => $supported, 'author' => self::author($idea), 'created_at' => $idea->created_at?->toIso8601String(), 'url' => route('ideas.show', $idea), ]; } /** * @return array */ public static function detail(Idea $idea, User $user): array { $manager = $user->can('ideas.manage'); $reports = IdeaReport::query()->where('idea_id', $idea->id)->get(); $mineReported = $reports->where('user_id', $user->id)->map(fn ($r) => $r->comment_id ?? 0)->all(); // Für das Gremium: offene Meldungen je Inhalt – Gründe und Anmerkungen, ohne Namen der Meldenden $open = fn (?int $commentId) => $manager ? $reports->whereNull('resolved_at')->where('comment_id', $commentId)->values() ->map(fn (IdeaReport $r) => ['reason' => IdeaReport::REASONS[$r->reason] ?? $r->reason, 'note' => $r->note])->all() : []; return [ ...self::card($idea, $idea->supporters()->whereKey($user->id)->exists()), 'body' => $idea->body, 'anonymous' => $idea->anonymous, 'status_note' => $idea->status_note, 'status_changed_at' => $idea->status_changed_at?->toIso8601String(), 'mine' => ! $idea->anonymous && $idea->author_id === $user->id, 'can_edit' => ! $idea->anonymous && $idea->author_id === $user->id && $idea->status === 'new', 'can_manage' => $manager, 'hidden' => $idea->hidden_at !== null, 'reported' => in_array(0, $mineReported, true), 'reports' => $open(null), 'comment_list' => $idea->comments()->with('user')->oldest()->oldest('id')->limit(500)->get() ->map(fn (IdeaComment $c) => [ 'id' => $c->id, // Ausgeblendet: nur Gremium und die schreibende Person sehen den Text 'body' => $c->hidden_at && ! $manager && $c->user_id !== $user->id ? null : $c->body, 'hidden' => $c->hidden_at !== null, 'reported' => in_array($c->id, $mineReported, true), 'reports' => $open($c->id), 'official' => $c->official, 'created_at' => $c->created_at?->toIso8601String(), 'author' => $c->user ? ['id' => $c->user->id, 'name' => $c->user->name, 'initials' => $c->user->initials, 'avatar_url' => $c->user->avatarUrl(64)] : null, 'can_delete' => $manager || $c->user_id === $user->id, ])->all(), ]; } /** * @return array{id: int, name: string, initials: string, avatar_url: ?string}|null */ private static function author(Idea $idea): ?array { $author = $idea->anonymous ? null : $idea->author; return $author ? ['id' => $author->id, 'name' => $author->name, 'initials' => $author->initials, 'avatar_url' => $author->avatarUrl(64)] : null; } }