Loheide-eu-mitarbeiterplatt.../plugins-core/ideen/src/IdeenPlugin.php
Friederich Loheide f9922f7308
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Ideenbox-Moderation und Wochenüberblick per E-Mail (0.36.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:17:47 +00:00

49 lines
2.6 KiB
PHP

<?php
namespace Inhaus\Plugins\Ideen;
use App\Dashboard\Widgets;
use App\Digest\Digest;
use App\Editorial\Editorial;
use App\Models\User;
use App\Plugins\Plugin;
use App\Support\Abilities;
use App\Support\Navigation;
use Carbon\CarbonImmutable;
use Inhaus\Plugins\Ideen\Models\Idea;
class IdeenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('ideen', 'Ideenbox', '/ideen', active: 'ideas.*', sort: 76);
$this->app->make(Digest::class)->add('ideen', 'Neue Ideen', 40, fn (User $user, CarbonImmutable $since) => Idea::query()
->whereNull('hidden_at')->where('created_at', '>=', $since)->orderByDesc('supports_count')->latest()->limit(5)->get()
->map(fn (Idea $idea) => [
'title' => $idea->title,
'url' => route('ideas.show', $idea),
'meta' => $idea->supports_count.' '.($idea->supports_count === 1 ? 'Unterstützung' : 'Unterstützungen'),
])->all());
$this->app->make(Abilities::class)->define('ideas.manage', 'Ideen bewerten, beantworten und moderieren (Gremium)', 'Ideenbox', portal: true);
// Redaktion: was das Gremium noch sichten muss
$this->app->make(Editorial::class)->add('ideen', 'Ideenbox', 'ideen::EditorialIdeas', 34,
fn (User $user) => $user->can('ideas.manage'),
fn (User $user) => [
'reported' => Idea::query()->with('author')->whereHas('reports', fn ($q) => $q->whereNull('resolved_at'))->withCount(['reports' => fn ($q) => $q->whereNull('resolved_at')])
->latest()->limit(20)->get()->map(fn (Idea $idea) => [...Presenter::card($idea), 'reports' => $idea->reports_count, 'hidden' => $idea->hidden_at !== null])->all(),
'ideas' => Idea::query()->with('author')->whereIn('status', ['new', 'review'])
->orderByRaw("status = 'new' DESC")->orderByDesc('supports_count')->latest()->limit(30)->get()
->map(fn (Idea $idea) => Presenter::card($idea))->all(),
]);
// Startseite: beliebteste offene Ideen
$this->app->make(Widgets::class)->add('ideen.popular', 'ideen::Popular', 'aside', sort: 28, props: function () {
$ideas = Idea::query()->with('author')->whereNull('hidden_at')->whereIn('status', ['new', 'review'])->where('created_at', '>=', now()->subDays(60))
->orderByDesc('supports_count')->latest()->limit(3)->get();
return $ideas->isEmpty() ? null : ['ideas' => $ideas->map(fn (Idea $idea) => Presenter::card($idea))->all()];
}, label: 'Ideenbox', mobileSort: 38);
}
}