Loheide-eu-mitarbeiterplatt.../app/Profile/ProfilePanels.php
Friederich Loheide 8a59023569
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m41s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m32s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m55s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m30s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m39s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m30s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m3s
Profilseite: Kommentare der Person
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 20:57:09 +00:00

57 lines
1.6 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 App\Profile;
use App\Models\User;
use App\Plugins\PluginAccess;
use Closure;
use Illuminate\Support\Facades\Log;
use Throwable;
/**
* Zusätzliche Bereiche auf der Profilseite einer Person (/personen/{id}),
* beigesteuert von Plugins – z. B. „Kommentare“ aus den Neuigkeiten.
* Die Vue-Komponente liegt unter plugins-core/<plugin>/resources/js/profile-panels/<Name>.vue
* („<plugin>::Name“).
*/
class ProfilePanels
{
/** @var array<string, array{component: string, sort: int, props: Closure}> */
private array $panels = [];
/**
* @param Closure(User $person, User $viewer): (array<string, mixed>|null) $props null = nicht zeigen
*/
public function add(string $key, string $component, int $sort, Closure $props): void
{
$this->panels[$key] = compact('component', 'sort', 'props');
}
/**
* @return list<array{key: string, component: string, props: array<string, mixed>}>
*/
public function resolve(User $person, User $viewer): array
{
$result = [];
foreach (collect($this->panels)->sortBy('sort') as $key => $panel) {
if (! app(PluginAccess::class)->allows($key, $viewer)) {
continue;
}
try {
$props = ($panel['props'])($person, $viewer);
} catch (Throwable $e) {
Log::error("Profilbereich {$key} fehlgeschlagen: ".$e->getMessage());
continue;
}
if ($props !== null) {
$result[] = ['key' => $key, 'component' => $panel['component'], 'props' => $props];
}
}
return $result;
}
}