Gruppen-Plugin 1.0.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 17:17:10 +00:00
commit 5bdfb8a082
49 changed files with 4679 additions and 0 deletions

73
src/GruppenPlugin.php Normal file
View file

@ -0,0 +1,73 @@
<?php
namespace Inhaus\Plugins\Gruppen;
use App\Dashboard\Widgets;
use App\Digest\Digest;
use App\Models\User;
use App\Plugins\Plugin;
use App\Search\GlobalSearch;
use App\Support\Abilities;
use App\Support\Navigation;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Inhaus\Plugins\Gruppen\Models\Group;
use Inhaus\Plugins\Gruppen\Models\Member;
use Inhaus\Plugins\Gruppen\Models\Post;
/**
* Diskussionsgruppen – offen, geschlossen oder privat, mit Beiträgen, Kommentaren und Umfragen.
*/
class GruppenPlugin extends Plugin
{
public function register(): void
{
$this->app->singleton(Groups::class);
$this->app->make(Navigation::class)->add('gruppen', 'Gruppen', '/gruppen', active: 'gruppen.*', sort: 25);
$this->app->make(Abilities::class)->define('gruppen.manage', 'Alle Gruppen verwalten (auch private) und bei Meldungen eingreifen', 'Gruppen', portal: true);
$this->app->make(GlobalSearch::class)->add('gruppen', 'Gruppen', 'users', function (User $user, string $search, int $limit) {
$query = Group::query()->discoverableBy($user);
GlobalSearch::whereTerms($query, ['name', 'description'], $search);
return $query->orderByDesc('members_count')->limit($limit)->get()->map(fn (Group $g) => [
'title' => $g->name,
'url' => '/gruppen/'.$g->slug,
'excerpt' => GlobalSearch::excerpt((string) $g->description, $search),
'meta' => Group::PRIVACY[$g->privacy].' · '.$g->members_count.($g->members_count === 1 ? ' Mitglied' : ' Mitglieder'),
])->all();
}, sort: 45);
// Startseite: Neues aus den eigenen Gruppen
$this->app->make(Widgets::class)->add('gruppen.feed', 'gruppen::Recent', 'aside', sort: 35, props: function (User $user) {
$ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id');
$posts = Post::query()->with(['user', 'group'])->whereIn('group_id', $ids)->latest('id')->limit(4)->get();
return $posts->isEmpty() ? null : ['posts' => $posts->map(fn (Post $p) => [
'id' => $p->id,
'group' => $p->group->name,
'user' => Presenter::person($p->user),
'text' => Str::limit((string) ($p->body ?: ($p->poll ? 'Umfrage' : 'Fotos/Dateien')), 90),
'created_at' => $p->created_at?->toIso8601String(),
'url' => route('gruppen.post', [$p->group, $p]),
])->all()];
}, label: 'Gruppen', mobileSort: 42);
if (class_exists(Digest::class)) {
$this->app->make(Digest::class)->add('gruppen', 'Aus Ihren Gruppen', 45, function (User $user, CarbonImmutable $since) {
$ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id');
return Group::query()->whereIn('id', $ids)->withCount(['posts as new_posts' => fn ($q) => $q->where('created_at', '>=', $since)])->get()
->where('new_posts', '>', 0)->sortByDesc('new_posts')->take(6)
->map(fn (Group $g) => ['title' => $g->name, 'url' => route('gruppen.show', $g), 'meta' => $g->new_posts === 1 ? '1 neuer Beitrag' : "{$g->new_posts} neue Beiträge"])->values()->all();
});
}
}
public function uninstall(): void
{
Storage::disk(Files::DISK)->deleteDirectory('gruppen');
}
}