Ideenbox (0.33.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m16s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m12s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m6s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m6s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 56s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m56s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m53s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m16s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m12s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m6s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m6s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 56s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m56s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m53s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bd7536ab82
commit
858e248d26
160 changed files with 1543 additions and 348 deletions
69
plugins-core/ideen/src/Presenter.php
Normal file
69
plugins-core/ideen/src/Presenter.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ideen;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Ideen\Models\Idea;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaComment;
|
||||
|
||||
class Presenter
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
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<string, mixed>
|
||||
*/
|
||||
public static function detail(Idea $idea, User $user): array
|
||||
{
|
||||
$manager = $user->can('ideas.manage');
|
||||
|
||||
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,
|
||||
'comment_list' => $idea->comments()->with('user')->oldest()->oldest('id')->limit(500)->get()
|
||||
->map(fn (IdeaComment $c) => [
|
||||
'id' => $c->id,
|
||||
'body' => $c->body,
|
||||
'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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue