firstOrCreate( ['user_id' => $user->id, 'idea_id' => $idea->id, 'comment_id' => $comment?->id], ['reason' => $reason, 'note' => $note], ); if (! $report->wasRecentlyCreated) { return; } $open = IdeaReport::query()->where('idea_id', $idea->id)->where('comment_id', $comment?->id)->whereNull('resolved_at')->count(); $subject = $comment ?? $idea; if ($open >= self::HIDE_AFTER && $subject->hidden_at === null) { $subject->forceFill(['hidden_at' => now()])->save(); } // Das Gremium bei der ersten offenen Meldung informieren (nicht bei jeder weiteren) if ($open === 1) { Notification::send($this->moderators()->reject(fn (User $u) => $u->id === $user->id), new PortalNotification( ($comment ? 'Kommentar gemeldet: ' : 'Idee gemeldet: ').Str::limit($idea->title, 60), IdeaReport::REASONS[$reason] ?? $reason, route('ideas.show', $idea, false).($comment ? '#kommentar-'.$comment->id : ''), 'flag', )); } } /** * Gremium: Meldungen erledigen – Inhalt bleibt (wieder sichtbar) oder wird gelöscht. */ public function resolve(Idea $idea, ?IdeaComment $comment, bool $remove): void { IdeaReport::query()->where('idea_id', $idea->id)->where('comment_id', $comment?->id)->whereNull('resolved_at')->update(['resolved_at' => now()]); if ($remove) { $comment ? $comment->delete() : $idea->delete(); $comment && $idea->refreshCounts(); return; } ($comment ?? $idea)->forceFill(['hidden_at' => null])->save(); } public function openCount(): int { return IdeaReport::query()->whereNull('resolved_at')->distinct()->count('idea_id'); } /** * Wer das Recht „ideas.manage“ über eine Rolle hat – ohne solche Personen die Administration. * * @return Collection */ public function moderators(): Collection { $holders = fn (string $ability) => User::query()->active() ->whereHas('roles.grants', fn ($q) => $q->where('ability', $ability))->limit(50)->get(); $moderators = $holders('ideas.manage'); return $moderators->isNotEmpty() ? $moderators : $holders('*'); } }