app->make(Navigation::class)->add('umfragen', 'Umfragen', '/umfragen', active: 'polls.*', sort: 74); $this->app->make(Abilities::class)->define('polls.manage', 'Umfragen anlegen und auswerten', 'Umfragen', portal: true); $this->app->make(Editorial::class)->add('umfragen', 'Umfragen', 'umfragen::EditorialPolls', 32, fn (User $user) => $user->can('polls.manage'), fn (User $user) => [ 'polls' => Poll::query()->withCount('responses')->orderByRaw('published_at IS NULL DESC')->latest('published_at')->latest('id')->limit(50)->get() ->map(fn (Poll $poll) => [...Presenter::card($poll), 'responses' => $poll->responses_count, 'edit_url' => route('polls.edit', $poll)])->all(), ]); // Startseite: offene Umfragen, an denen die Person noch nicht teilgenommen hat $this->app->make(Widgets::class)->add('umfragen.open', 'umfragen::Open', 'aside', sort: 25, props: function (User $user) { $polls = Poll::query()->open()->visibleTo($user)->latest('published_at')->limit(10)->get() ->reject(fn (Poll $poll) => $poll->hasVoted($user))->take(3); return $polls->isEmpty() ? null : ['polls' => $polls->map(fn (Poll $poll) => Presenter::card($poll))->values()->all()]; }, label: 'Offene Umfragen', mobileSort: 35); // Baustein: Umfrage direkt in Seite oder Beitrag $this->app->make(Blocks::class)->add(BlockType::make('umfragen.poll', 'Umfrage', 'vote', 'dynamic', 'umfragen::PollBlock') ->description('Eine Umfrage direkt auf der Seite beantworten lassen.') ->fields([ Field::select('poll', 'Umfrage', fn () => Poll::query()->latest('id')->limit(200)->pluck('title', 'id')->mapWithKeys(fn ($t, $id) => [(string) $id => $t])->all()), ]) ->resolveUsing(function (array $data, ?User $user) { $poll = $data['poll'] ? Poll::query()->find($data['poll']) : null; return $poll && $user && ($poll->isPublished() || $user->can('polls.manage')) && $poll->isVisibleTo($user) ? Presenter::present($poll, $user) : null; })); } public function boot(): void { // Geplante Umfragen ankündigen, sobald sie beginnen Schedule::call(fn () => $this->app->make(Announcer::class)->announceDue())->everyTenMinutes()->name('umfragen-announce')->withoutOverlapping(10); } }