Loheide-eu-mitarbeiterplatt.../plugins-core/umfragen/src/Presenter.php
Friederich Loheide 3f67fde50b
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m33s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 5m25s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 6m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m55s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m12s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 1m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m52s
Umfragen-Plugin (0.32.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 12:54:17 +00:00

60 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Inhaus\Plugins\Umfragen;
use App\Models\User;
use Inhaus\Plugins\Umfragen\Models\Poll;
/**
* Umfrage für die Anzeige (Seite, Baustein, App) – mit dem Stand für diese Person.
*/
class Presenter
{
/**
* @return array<string, mixed>
*/
public static function present(Poll $poll, User $user): array
{
$editor = $user->can('polls.manage');
$voted = $poll->hasVoted($user);
$visible = $editor || match ($poll->results_visibility) {
Poll::EDITORS => false,
Poll::AFTER_END => $poll->isClosed(),
default => $voted || $poll->isClosed(),
};
return [
...self::card($poll),
'description' => $poll->description,
'questions' => $poll->questions,
'anonymous' => $poll->anonymous,
'voted' => $voted,
'can_vote' => $poll->isOpen() && ! $voted,
'results' => $visible ? app(Results::class)->for($poll, $editor) : null,
'results_note' => $visible ? null : match ($poll->results_visibility) {
Poll::EDITORS => 'Die Ergebnisse wertet die Redaktion aus.',
Poll::AFTER_END => $poll->closes_at ? 'Die Ergebnisse erscheinen nach dem Ende der Umfrage am '.$poll->closes_at->timezone(config('app.timezone'))->format('d.m.Y, H:i').' Uhr.' : 'Die Ergebnisse erscheinen nach dem Ende der Umfrage.',
default => 'Die Ergebnisse sehen Sie nach Ihrer Abstimmung.',
},
'edit_url' => $editor ? route('polls.edit', $poll) : null,
'export_url' => $editor ? route('polls.export', $poll) : null,
];
}
/**
* @return array<string, mixed>
*/
public static function card(Poll $poll): array
{
return [
'id' => $poll->id,
'title' => $poll->title,
'status' => $poll->status(),
'open' => $poll->isOpen(),
'closes_at' => $poll->closes_at?->toIso8601String(),
'published_at' => $poll->published_at?->toIso8601String(),
'questions_count' => count($poll->questions ?? []),
'url' => route('polls.show', $poll),
];
}
}