Gestalte den Mitgliederbereich nach Brand-UI-Kit 14 neu
Eine Navigation (Meine Bibliothek, Programme, Meine Lizenzen, Konto-Menü) mit der freigegebenen Wortmarke, Startseite ohne erfundene Inhalte, Bibliothek mit Inhaltsart-Filter und einer Karte je Medienidentität („Verwendet in“), Programm-/Moduldetail, Film und Material im Zusammenhang mit Begleitmaterial und Weg zurück, Lizenzübersicht mit Detailseite je Berechtigung. Alle Größen aus der Größenskala (ADR-44, neues Token --card-min). Tests bewusst angepasst: Der Film spielt auf der Kontextseite statt eingebettet im Programm, Download-Links tragen ein Symbol, der Platzhalter ist ein dekoratives Element, die Wortmarke ist das freigegebene Logo. Die Vorschau der Bibliothekskarte in der Verwaltung nutzt dieselbe Komponente. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f070fbab2
commit
2e6260acca
41 files changed
+3742
-1093
No files matched your search
@@ -95,12 +95,18 @@ public function describe(Offer $offer, OfferVersion $version): array
|
||||
|
||||
public static function termLabel(OfferVersion $version): string
|
||||
{
|
||||
return match ($version->term_rule) {
|
||||
return self::termRuleLabel($version->term_rule);
|
||||
}
|
||||
|
||||
/** Laufzeitregel aus der Angebotsfassung oder aus den Bedingungen eines Erwerbs (gleiche Schlüssel). */
|
||||
public static function termRuleLabel(?string $rule): string
|
||||
{
|
||||
return match ((string) $rule) {
|
||||
'dauerhaft' => 'Dauerhaft nutzbar',
|
||||
'befristet' => 'Befristet',
|
||||
'solange_angebot_aktiv' => 'Solange das Angebot aktiv ist',
|
||||
'periodisch' => 'Laufend, periodisch',
|
||||
default => (string) $version->term_rule,
|
||||
default => (string) $rule,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
@@ -1046,18 +1047,20 @@ public function previewHtml(): string
|
||||
if ($this->previewSurface === 'bibliothek') {
|
||||
$title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->workingTitle);
|
||||
|
||||
return view('member.partials.card', [
|
||||
'href' => '#vorschau',
|
||||
// Dieselbe Karte wie im Mitgliederbereich (<x-member.card>), ohne Verfügbarkeit: Die entscheidet die Lizenz.
|
||||
return Blade::render('<x-member.card :card="$card" />', [
|
||||
'card' => [
|
||||
'type' => $element->output_class === 'film' ? 'film' : 'material',
|
||||
'url' => '#vorschau',
|
||||
'title' => $title !== '' ? $title : $element->working_title,
|
||||
'summary' => trim($this->summary) !== '' ? trim($this->summary) : null,
|
||||
'kind' => PublicMaterialReader::outputLabel((string) $element->output_class),
|
||||
'coverage' => 'offen',
|
||||
'hide_status' => true,
|
||||
'image' => trim($this->thumbnailAlt) !== '' ? trim($this->thumbnailAlt) : $title,
|
||||
'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'error' => 'Vorschau der Kartenform. Ob jemand sie öffnen darf, entscheidet die Lizenz.',
|
||||
],
|
||||
])->render();
|
||||
]);
|
||||
}
|
||||
|
||||
$subject = app(PublicMaterialReader::class)->subject($element->id, true, $draft);
|
||||
|
||||
@@ -39,7 +39,7 @@ public function claim(Request $request, Offer $offer, GrantIssuer $issuer): Redi
|
||||
return back()->withErrors(['offer' => $exception->getMessage()]);
|
||||
}
|
||||
|
||||
return redirect()->route('member.library')->with('status', 'Das Angebot liegt in Ihrer Bibliothek.');
|
||||
return redirect()->route('member.library')->with('status', 'Das Angebot liegt in deiner Bibliothek.');
|
||||
}
|
||||
|
||||
public function place(Request $request, Offer $offer, Checkout $checkout): RedirectResponse
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\CourseOutline;
|
||||
use App\Http\LibraryCatalog;
|
||||
use App\Http\MemberLicenses;
|
||||
use App\Http\SignedLink;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -32,12 +34,28 @@
|
||||
|
||||
class LibraryController extends Controller
|
||||
{
|
||||
/** Inhaltsarten der Bibliothek (Schlüssel der Adresse und des Filters). */
|
||||
public const TYPES = [
|
||||
'programm' => 'Programme',
|
||||
'modul' => 'Module',
|
||||
'film' => 'Filme',
|
||||
'material' => 'Materialien',
|
||||
];
|
||||
|
||||
public function index(Request $request, ?string $sicht = null): View
|
||||
{
|
||||
$catalog = app(LibraryCatalog::class)->index($request->user());
|
||||
$untouched = $catalog['programs'] === [] && $catalog['modules'] === [] && $catalog['materials'] === [];
|
||||
$items = [...$catalog['programs'], ...$catalog['modules'], ...$catalog['materials']];
|
||||
$untouched = $items === [];
|
||||
$query = trim((string) $request->query('q', ''));
|
||||
$nutzung = (string) $request->query('nutzung', '');
|
||||
$sortierung = $request->query('sortierung') === 'titel' ? 'titel' : 'standard';
|
||||
$art = match ($sicht) {
|
||||
'programme' => 'programm',
|
||||
'module' => 'modul',
|
||||
default => (string) $request->query('art', ''),
|
||||
};
|
||||
$art = array_key_exists($art, self::TYPES) ? $art : '';
|
||||
$dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', []))));
|
||||
$saeuleIds = array_values(array_filter(array_map(intval(...), (array) $request->query('saeule', []))));
|
||||
$dimensions = app(IdentityDimension::class);
|
||||
@@ -52,94 +70,60 @@ public function index(Request $request, ?string $sicht = null): View
|
||||
|
||||
$dimensionIds = array_values($dimensionIds);
|
||||
$saeuleIds = array_values(array_unique($saeuleIds));
|
||||
$pillarOptions = $this->visiblePillars($catalog, $saeuleIds);
|
||||
$pillarOptions = $this->visiblePillars($items, $saeuleIds);
|
||||
|
||||
foreach (['programs', 'modules'] as $shelf) {
|
||||
if ($query !== '') {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => $this->matches($card, $query),
|
||||
));
|
||||
}
|
||||
if ($dimensionIds !== []) {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds),
|
||||
));
|
||||
}
|
||||
if ($saeuleIds !== []) {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => $this->hasPillar($card['composition'], $saeuleIds),
|
||||
));
|
||||
}
|
||||
if (in_array($nutzung, ['nutzbar', 'teilweise', 'nicht enthalten'], true)) {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => ($card['coverage'] ?? '') === $nutzung,
|
||||
));
|
||||
// Gemeinsame Filter für alle Inhaltsarten. Die Zahl je Art zeigt, was die übrigen Filter übrig lassen.
|
||||
$matching = array_values(array_filter($items, function (array $card) use ($query, $nutzung, $dimensionIds, $saeuleIds, $dimensions): bool {
|
||||
return ($query === '' || $this->matches($card, $query))
|
||||
&& ($dimensionIds === [] || $dimensions->matches($card['subject'], $dimensionIds))
|
||||
&& ($saeuleIds === [] || $this->hasPillar($card['subject'], $saeuleIds))
|
||||
&& (! in_array($nutzung, ['nutzbar', 'teilweise', 'nicht enthalten'], true) || ($card['coverage'] ?? '') === $nutzung);
|
||||
}));
|
||||
$counts = array_fill_keys(array_keys(self::TYPES), 0);
|
||||
|
||||
foreach ($matching as $card) {
|
||||
$counts[$card['type']]++;
|
||||
}
|
||||
|
||||
$shown = $art === '' ? $matching : array_values(array_filter($matching, fn (array $card): bool => $card['type'] === $art));
|
||||
|
||||
if ($sortierung === 'titel') {
|
||||
usort($shown, fn (array $left, array $right): int => strcoll(mb_strtolower($left['title']), mb_strtolower($right['title'])));
|
||||
}
|
||||
|
||||
$shelves = [];
|
||||
|
||||
foreach (self::TYPES as $type => $label) {
|
||||
$cards = array_values(array_filter($shown, fn (array $card): bool => $card['type'] === $type));
|
||||
|
||||
if ($cards !== []) {
|
||||
$shelves[$type] = ['label' => $label, 'cards' => $cards];
|
||||
}
|
||||
}
|
||||
|
||||
if ($query !== '') {
|
||||
$catalog['materials'] = array_values(array_filter(
|
||||
$catalog['materials'],
|
||||
fn (array $card): bool => $this->matches($card, $query),
|
||||
));
|
||||
}
|
||||
|
||||
if ($dimensionIds !== []) {
|
||||
$catalog['materials'] = array_values(array_filter(
|
||||
$catalog['materials'],
|
||||
function (array $card) use ($dimensions, $dimensionIds): bool {
|
||||
$release = $card['article']->currentRelease;
|
||||
$subject = $release?->rootCompositionVersion?->composition
|
||||
?? $release?->rootElementVersion?->element
|
||||
?? $card['article'];
|
||||
|
||||
return $dimensions->matches($subject, $dimensionIds);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
if ($saeuleIds !== []) {
|
||||
$catalog['materials'] = array_values(array_filter(
|
||||
$catalog['materials'],
|
||||
fn (array $card): bool => $this->hasPillar($this->materialSubject($card), $saeuleIds),
|
||||
));
|
||||
}
|
||||
|
||||
if ($nutzung === 'teilweise' || $nutzung === 'nicht enthalten') {
|
||||
$catalog['materials'] = [];
|
||||
}
|
||||
$filterActive = $query !== '' || $nutzung !== '' || $dimensionIds !== [] || $saeuleIds !== [] || $art !== '';
|
||||
|
||||
return view('member.library', [
|
||||
...$catalog,
|
||||
'shelves' => $shelves,
|
||||
'total' => count($shown),
|
||||
'counts' => $counts,
|
||||
'allCount' => count($matching),
|
||||
'art' => $art,
|
||||
'types' => self::TYPES,
|
||||
'query' => $query,
|
||||
'sicht' => $sicht,
|
||||
'nutzung' => $nutzung,
|
||||
'sortierung' => $sortierung,
|
||||
'dimensionIds' => $dimensionIds,
|
||||
'saeuleIds' => $saeuleIds,
|
||||
'filterPillars' => $pillarOptions,
|
||||
'filterDimensions' => app(EditorialVocabulary::class)->memberFilterDimensions(array_map(intval(...), $dimensionIds)),
|
||||
'libraryEmpty' => $untouched,
|
||||
'filterActive' => $filterActive,
|
||||
'filterCount' => count($dimensionIds) + count($saeuleIds) + ($nutzung !== '' ? 1 : 0),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subjekt eines Materialkarte: Programm oder Modul, Medium oder der Artikel selbst.
|
||||
*
|
||||
* @param array<string, mixed> $card
|
||||
*/
|
||||
private function materialSubject(array $card): Model
|
||||
{
|
||||
$release = $card['article']->currentRelease;
|
||||
|
||||
return $release?->rootCompositionVersion?->composition
|
||||
?? $release?->rootElementVersion?->element
|
||||
?? $card['article'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Direkte Säulenzuordnung des Objekts selbst; die Säulen enthaltener Medien zählen hier nicht.
|
||||
*
|
||||
@@ -154,22 +138,16 @@ private function hasPillar(Model $subject, array $pillarIds): bool
|
||||
* Säulen für den Filter: nur solche, die ein sichtbares Objekt der Bibliothek tatsächlich trägt, und eine bereits
|
||||
* gewählte. So erscheinen neue oder interne Säulen ohne Zuordnung nicht in der Bibliothek.
|
||||
*
|
||||
* @param array<string, mixed> $catalog
|
||||
* @param list<array<string, mixed>> $items
|
||||
* @param list<int> $selected
|
||||
* @return Collection<int, Pillar>
|
||||
*/
|
||||
private function visiblePillars(array $catalog, array $selected)
|
||||
private function visiblePillars(array $items, array $selected)
|
||||
{
|
||||
$used = [];
|
||||
|
||||
foreach (array_merge($catalog['programs'], $catalog['modules']) as $card) {
|
||||
foreach ($card['composition']->pillars()->pluck('pillars.id') as $id) {
|
||||
$used[(int) $id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($catalog['materials'] as $card) {
|
||||
foreach ($this->materialSubject($card)->pillars()->pluck('pillars.id') as $id) {
|
||||
foreach ($items as $card) {
|
||||
foreach ($card['subject']->pillars()->pluck('pillars.id') as $id) {
|
||||
$used[(int) $id] = true;
|
||||
}
|
||||
}
|
||||
@@ -193,20 +171,55 @@ public function program(Request $request, Composition $composition): View
|
||||
return view('member.program', app(LibraryCatalog::class)->program($request->user(), $composition));
|
||||
}
|
||||
|
||||
public function materials(Request $request): View
|
||||
/**
|
||||
* Film oder Material im Zusammenhang seines Programms oder Moduls. Die Seite zeigt nur Stellen, die in der
|
||||
* angezeigten Fassung des Programms stehen; die Wiedergabe- und Downloadadressen kommen aus DecideAccess.
|
||||
*/
|
||||
public function content(Request $request, Composition $composition, int $version): View|Response
|
||||
{
|
||||
return view('member.materials', [
|
||||
'grants' => $this->grantQuery($request)->with('article.currentRelease.contents.elementVersion.element')->get(),
|
||||
]);
|
||||
$data = app(LibraryCatalog::class)->content($request->user(), $composition, $version);
|
||||
abort_if($data === null, 404);
|
||||
|
||||
return response()->view('member.content', $data, $data['allowed'] ? 200 : 403);
|
||||
}
|
||||
|
||||
/** Die frühere Seite „Materialien“ ist ein Filter der Bibliothek (eine Navigation statt zwei). */
|
||||
public function materials(): RedirectResponse
|
||||
{
|
||||
return redirect()->route('member.library', ['art' => 'material']);
|
||||
}
|
||||
|
||||
public function grants(Request $request): View
|
||||
{
|
||||
$entries = app(MemberLicenses::class)->overview($request->user());
|
||||
$filter = in_array($request->query('status'), ['aktiv', 'inaktiv'], true) ? (string) $request->query('status') : 'alle';
|
||||
|
||||
return view('member.grants', [
|
||||
'grants' => $this->grantQuery($request)->get(),
|
||||
'entries' => match ($filter) {
|
||||
'aktiv' => $entries->where('active', true)->values(),
|
||||
'inaktiv' => $entries->where('active', false)->values(),
|
||||
default => $entries,
|
||||
},
|
||||
'filter' => $filter,
|
||||
'counts' => [
|
||||
'aktiv' => $entries->where('active', true)->count(),
|
||||
'inaktiv' => $entries->where('active', false)->count(),
|
||||
'alle' => $entries->count(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** Eine einzelne Berechtigung. Nur eigene (oder die der eigenen Organisation mit Bestellrecht); sonst nicht gefunden. */
|
||||
public function grant(Request $request, Grant $grant): View
|
||||
{
|
||||
abort_unless(
|
||||
Grant::query()->usableBy($request->user())->whereKey($grant->id)->exists(),
|
||||
404,
|
||||
);
|
||||
|
||||
return view('member.grant', app(MemberLicenses::class)->detail($request->user(), $grant));
|
||||
}
|
||||
|
||||
public function show(Request $request, LicenseArticle $article): View
|
||||
{
|
||||
$release = $article->currentRelease()->with('contents.elementVersion.element.pillars')->first();
|
||||
@@ -219,6 +232,7 @@ public function show(Request $request, LicenseArticle $article): View
|
||||
$metadata = is_array($version->metadata) ? $version->metadata : [];
|
||||
$action = $class === 'film' || $class === 'audio' ? 'streamen' : 'ansehen';
|
||||
$decision = app(DecideAccess::class)($request->user(), $article, $release, $version, $action);
|
||||
$download = app(DecideAccess::class)($request->user(), $article, $release, $version, 'laden');
|
||||
$file = $metadata['file'] ?? null;
|
||||
$entries[] = [
|
||||
'content' => $content,
|
||||
@@ -232,6 +246,15 @@ public function show(Request $request, LicenseArticle $article): View
|
||||
: null,
|
||||
'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'),
|
||||
'playback' => app(FilmPlayback::class)->mode($version->id),
|
||||
'download_url' => $download->allowed
|
||||
? SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'version' => $version->id,
|
||||
'action' => 'laden',
|
||||
'reader' => $request->user()->id,
|
||||
])
|
||||
: null,
|
||||
'pillars' => $version->element->pillars->pluck('name')->all(),
|
||||
'url' => $decision->allowed
|
||||
? SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
@@ -352,7 +375,7 @@ public function thumbnail(Request $request, string $kind, int $subject): Streame
|
||||
*/
|
||||
private function matches(array $card, string $query): bool
|
||||
{
|
||||
$haystack = mb_strtolower(($card['title'] ?? '').' '.($card['summary'] ?? ''));
|
||||
$haystack = mb_strtolower(($card['title'] ?? '').' '.($card['summary'] ?? '').' '.($card['subject']->search_terms ?? ''));
|
||||
|
||||
return str_contains($haystack, mb_strtolower($query));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\LibraryCatalog;
|
||||
use App\Http\MemberLicenses;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -14,11 +15,17 @@ class MemberController extends Controller
|
||||
public function dashboard(Request $request): View
|
||||
{
|
||||
$catalog = app(LibraryCatalog::class)->index($request->user());
|
||||
$films = array_filter($catalog['materials'], fn (array $card): bool => $card['type'] === 'film');
|
||||
|
||||
return view('member.dashboard', [
|
||||
'programCount' => count($catalog['programs']),
|
||||
'moduleCount' => count($catalog['modules']),
|
||||
'materialCount' => count($catalog['materials']),
|
||||
'programs' => array_slice($catalog['programs'], 0, 4),
|
||||
'counts' => [
|
||||
'programm' => count($catalog['programs']),
|
||||
'modul' => count($catalog['modules']),
|
||||
'film' => count($films),
|
||||
'material' => count($catalog['materials']) - count($films),
|
||||
],
|
||||
'licenseCount' => app(MemberLicenses::class)->overview($request->user())->where('active', true)->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
+326
-45
@@ -9,6 +9,7 @@
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Catalog\ReleaseStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
@@ -18,24 +19,48 @@
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Liest die Mitgliederbibliothek aus den vorhandenen Fachobjekten (Kompositionen, Medien, Artikelstände, Berechtigungen).
|
||||
* Sie hält keine eigenen Daten. Jede Zugriffsfrage entscheidet DecideAccess; die Oberfläche zeigt nur das Ergebnis.
|
||||
*
|
||||
* Einmalaufbau: Der Strukturbaum einer Komposition wird je Anfrage nur einmal gebaut und für Verfügbarkeit,
|
||||
* Zählungen und die programmübergreifende Medienliste gemeinsam genutzt.
|
||||
*/
|
||||
class LibraryCatalog
|
||||
{
|
||||
/** @var array<string, list<array<string, mixed>>> */
|
||||
private array $trees = [];
|
||||
|
||||
/** @var array<string, array{title: string, summary: ?string, description: ?string}> */
|
||||
private array $texts = [];
|
||||
|
||||
/** @var array<int, ?ContentElement> */
|
||||
private array $elements = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly CompositionDisplayRelease $display,
|
||||
private readonly CompositionStructureReader $structure,
|
||||
private readonly DecideAccess $access,
|
||||
private readonly EditorialProfileReader $profiles,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Programme, Module und einzelne Medien (Filme und Materialien) der Berechtigungen des Kontos.
|
||||
*
|
||||
* Einzelne Medien erscheinen genau einmal je stabiler Medienidentität (Inhaltselement), gleich in wie vielen Programmen
|
||||
* oder Modulen sie vorkommen. „used_in“ nennt diese Verwendungen. Innerhalb eines Programms bleibt jede Einbindung an
|
||||
* ihrer Stelle erhalten (program()). Gleiche Titel verschiedener Elemente bleiben getrennt.
|
||||
*
|
||||
* @return array{programs: list<array<string, mixed>>, modules: list<array<string, mixed>>, materials: list<array<string, mixed>>}
|
||||
*/
|
||||
public function index(User $user): array
|
||||
{
|
||||
$programs = [];
|
||||
$modules = [];
|
||||
$materials = [];
|
||||
$media = [];
|
||||
|
||||
foreach ($this->grants($user) as $grant) {
|
||||
$article = $grant->article;
|
||||
@@ -44,124 +69,360 @@ public function index(User $user): array
|
||||
$version = $release?->rootCompositionVersion;
|
||||
|
||||
if ($composition !== null && $version !== null && $this->display->isReleased($version)) {
|
||||
$shown = $this->display->highestReleasedVersion($composition);
|
||||
$nodes = $shown === null ? [] : $this->tree($user, $shown, false, $composition->id);
|
||||
$picture = app(EditorialCatalog::class)->visiblePicture($composition, $version);
|
||||
$text = $this->text($composition);
|
||||
$card = [
|
||||
'type' => $composition->editorialContentKind?->slug === 'modul' ? 'modul' : 'programm',
|
||||
'composition' => $composition,
|
||||
'subject' => $composition,
|
||||
'version' => $version,
|
||||
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
|
||||
'summary' => $composition->summary,
|
||||
'title' => $text['title'],
|
||||
'summary' => $text['summary'],
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
'coverage' => $this->coverageLabel($user, $composition),
|
||||
'coverage' => $this->coverage($nodes),
|
||||
'module_count' => $this->countCompositions($nodes),
|
||||
'duration_minutes' => $shown?->duration_minutes,
|
||||
'image' => $picture['alt'] ?? null,
|
||||
'image_url' => $picture === null ? null : route('member.thumbnail', [
|
||||
'kind' => $picture['kind'],
|
||||
'subject' => $picture['subject'],
|
||||
]),
|
||||
'url' => route('member.program', $composition),
|
||||
];
|
||||
$shelf = $composition->editorialContentKind?->slug === 'modul' ? 'modules' : 'programs';
|
||||
if ($shelf === 'modules') {
|
||||
|
||||
if ($card['type'] === 'modul') {
|
||||
$modules[$composition->id] = $card;
|
||||
} else {
|
||||
$programs[$composition->id] = $card;
|
||||
}
|
||||
|
||||
$this->collect($media, $nodes, [['title' => $text['title'], 'url' => $card['url'], 'id' => $composition->id]], $composition);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$element = $release?->rootElementVersion?->element;
|
||||
$elementId = $element?->id;
|
||||
$key = $composition !== null
|
||||
? 'komposition-'.$composition->id
|
||||
: ($elementId !== null ? 'element-'.$elementId : 'artikel-'.$article->id);
|
||||
: ($element?->id !== null ? 'element-'.$element->id : 'artikel-'.$article->id);
|
||||
$subject = $element ?? $composition ?? $article;
|
||||
$text = $element !== null ? $this->text($element) : null;
|
||||
$imageUrl = $element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path);
|
||||
$materials[$key] = [
|
||||
'article' => $article,
|
||||
'title' => app(CourseOutline::class)->title($article),
|
||||
'summary' => $element?->summary ?? $composition?->summary,
|
||||
'kind' => app(CourseOutline::class)->kindLabel($article),
|
||||
'coverage' => 'nutzbar',
|
||||
'image' => $imageUrl === null ? null : ($element->thumbnail_alt ?: $element->working_title),
|
||||
'image_url' => $imageUrl,
|
||||
$media[$key] = ($media[$key] ?? []) + [
|
||||
'used_in' => [],
|
||||
'versions' => [],
|
||||
'context' => null,
|
||||
];
|
||||
$media[$key] = [
|
||||
...$media[$key],
|
||||
'key' => $key,
|
||||
'type' => $element?->output_class === 'film' ? 'film' : 'material',
|
||||
'article' => $article,
|
||||
'subject' => $subject,
|
||||
'title' => $text['title'] ?? app(CourseOutline::class)->title($article),
|
||||
'summary' => $text['summary'] ?? $element?->summary ?? $composition?->summary,
|
||||
'kind' => app(CourseOutline::class)->kindLabel($article) ?? ($element === null ? null : $this->outputLabel($element->output_class)),
|
||||
'coverage' => 'nutzbar',
|
||||
'image' => $imageUrl === null ? null : ($element->thumbnail_alt ?: ($text['title'] ?? $element->working_title)),
|
||||
'image_url' => $imageUrl,
|
||||
'url' => route('member.article', $article),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($media as $key => $item) {
|
||||
if (! isset($item['url'])) {
|
||||
$media[$key]['url'] = route('member.content', [
|
||||
'composition' => $item['context']['composition']->id,
|
||||
'version' => $item['context']['version_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'programs' => array_values($programs),
|
||||
'modules' => array_values($modules),
|
||||
'materials' => array_values($materials),
|
||||
'materials' => array_values($media),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{composition: Composition, title: string, kind: ?string, nodes: list<array<string, mixed>>}
|
||||
* Programm- oder Moduldetail: gesamte Struktur mit allen Einbindungen an ihrer Stelle.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function program(User $user, Composition $composition): array
|
||||
{
|
||||
$version = $this->display->highestReleasedVersion($composition);
|
||||
abort_if($version === null, 404);
|
||||
|
||||
$nodes = array_map(
|
||||
fn (StructureNode $node): array => $this->present($user, $node),
|
||||
$this->structure->tree($version),
|
||||
);
|
||||
$nodes = $this->tree($user, $version, true, $composition->id);
|
||||
$leaves = $this->leaves($nodes);
|
||||
$open = count(array_filter($leaves, fn (array $leaf): bool => $leaf['view_url'] !== null));
|
||||
$text = $this->text($composition);
|
||||
|
||||
return [
|
||||
'composition' => $composition,
|
||||
'picture' => app(EditorialCatalog::class)->visiblePicture($composition, $version),
|
||||
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
|
||||
'summary' => $composition->summary,
|
||||
'title' => $text['title'],
|
||||
'summary' => $text['summary'],
|
||||
'description' => $text['description'],
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
'is_module' => $composition->editorialContentKind?->slug === 'modul',
|
||||
'learning_goal' => $version->learning_goal,
|
||||
'duration_minutes' => $version->duration_minutes,
|
||||
'material_note' => $version->material_note,
|
||||
'coverage' => $leaves === [] ? 'nicht enthalten' : ($open === count($leaves) ? 'nutzbar' : ($open === 0 ? 'nicht enthalten' : 'teilweise')),
|
||||
'coverage' => $this->coverage($nodes),
|
||||
'module_count' => $this->countCompositions($nodes),
|
||||
'film_count' => count(array_filter($leaves, fn (array $leaf): bool => $leaf['output_class'] === 'film')),
|
||||
'material_count' => count(array_filter($leaves, fn (array $leaf): bool => $leaf['element_id'] !== null && $leaf['output_class'] !== 'film')),
|
||||
'open_count' => count(array_filter($leaves, fn (array $leaf): bool => $leaf['view_url'] !== null)),
|
||||
'leaf_count' => count($leaves),
|
||||
'nodes' => $nodes,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Filmstelle oder ein Material im Zusammenhang seines Programms oder Moduls.
|
||||
* Gesucht wird die Einbindung in der angezeigten Fassung; was dort nicht steht, gibt es hier nicht.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function content(User $user, Composition $composition, int $elementVersionId): ?array
|
||||
{
|
||||
$version = $this->display->highestReleasedVersion($composition);
|
||||
|
||||
if ($version === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nodes = $this->tree($user, $version, true, $composition->id);
|
||||
$found = $this->locate($nodes, $elementVersionId, []);
|
||||
|
||||
if ($found === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node = $found['node'];
|
||||
$element = $node['element_id'] === null ? null : $this->element($node['element_id']);
|
||||
$text = $element === null ? ['title' => $node['title'], 'summary' => null, 'description' => null] : $this->text($element);
|
||||
$rootText = $this->text($composition);
|
||||
$trail = [['label' => $rootText['title'], 'url' => route('member.program', $composition)]];
|
||||
|
||||
foreach ($found['parents'] as $parent) {
|
||||
if ($parent['program_url'] !== null && $parent['composition_id'] !== $composition->id) {
|
||||
$trail[] = ['label' => $parent['title'], 'url' => $parent['program_url']];
|
||||
}
|
||||
}
|
||||
|
||||
$companions = array_values(array_filter(
|
||||
$found['siblings'],
|
||||
fn (array $sibling): bool => $sibling['children'] === []
|
||||
&& $sibling['element_id'] !== null
|
||||
&& $sibling['version_id'] !== $elementVersionId,
|
||||
));
|
||||
|
||||
return [
|
||||
'composition' => $composition,
|
||||
'program_title' => $rootText['title'],
|
||||
'node' => $node,
|
||||
'element' => $element,
|
||||
'title' => $text['title'],
|
||||
'summary' => $text['summary'],
|
||||
'description' => $text['description'],
|
||||
'trail' => $trail,
|
||||
'back' => $trail[array_key_last($trail)],
|
||||
'companions' => $companions,
|
||||
'allowed' => $node['view_url'] !== null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzeigetitel und -texte für die Mitgliederbibliothek: Abweichung für „Mitgliederbibliothek“, sonst die zentrale Angabe,
|
||||
* zuletzt die interne Bezeichnung. Nichts wird kopiert oder ergänzt.
|
||||
*
|
||||
* @return array{title: string, summary: ?string, description: ?string}
|
||||
*/
|
||||
public function text(Model $subject): array
|
||||
{
|
||||
$key = $subject->getMorphClass().':'.$subject->getKey();
|
||||
|
||||
if (isset($this->texts[$key])) {
|
||||
return $this->texts[$key];
|
||||
}
|
||||
|
||||
$profile = $this->profiles->read($subject, 'bibliothek');
|
||||
|
||||
return $this->texts[$key] = [
|
||||
'title' => $profile->value('display_title') ?? $profile->workingTitle ?? '',
|
||||
'summary' => $profile->value('summary') ?? $profile->value('teaser'),
|
||||
'description' => $profile->value('description'),
|
||||
];
|
||||
}
|
||||
|
||||
public function outputLabel(?string $outputClass): ?string
|
||||
{
|
||||
return match ($outputClass) {
|
||||
'film' => 'Film',
|
||||
'audio' => 'Hörstück',
|
||||
'document', 'pdf' => 'Dokument',
|
||||
'text' => 'Text',
|
||||
'bild' => 'Bild',
|
||||
null => null,
|
||||
default => $outputClass,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
* @param list<array{title: string, url: string, id: int}> $contexts
|
||||
* @param array<string, array<string, mixed>> $media
|
||||
*/
|
||||
private function collect(array &$media, array $nodes, array $contexts, Composition $root): void
|
||||
{
|
||||
foreach ($nodes as $node) {
|
||||
if ($node['children'] !== []) {
|
||||
$nested = $contexts;
|
||||
|
||||
if ($node['composition_id'] !== null && $node['program_url'] !== null && $node['composition_id'] !== $root->id) {
|
||||
$nested[] = ['title' => $node['title'], 'url' => $node['program_url'], 'id' => $node['composition_id']];
|
||||
}
|
||||
|
||||
$this->collect($media, $node['children'], $nested, $root);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node['element_id'] === null || $node['view_url'] === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = 'element-'.$node['element_id'];
|
||||
$element = $this->element($node['element_id']);
|
||||
$text = $element === null ? ['title' => $node['title'], 'summary' => null] : $this->text($element);
|
||||
$item = $media[$key] ?? [
|
||||
'key' => $key,
|
||||
'type' => $node['output_class'] === 'film' ? 'film' : 'material',
|
||||
'article' => null,
|
||||
'subject' => $element,
|
||||
'title' => $text['title'],
|
||||
'summary' => $text['summary'],
|
||||
'kind' => $node['kind'] ?? $this->outputLabel($node['output_class']),
|
||||
'coverage' => 'nutzbar',
|
||||
'image' => $node['poster_url'] === null ? null : ($element?->thumbnail_alt ?: $text['title']),
|
||||
'image_url' => $node['poster_url'],
|
||||
'used_in' => [],
|
||||
'versions' => [],
|
||||
'context' => null,
|
||||
];
|
||||
|
||||
foreach ($contexts as $context) {
|
||||
$item['used_in'][$context['id']] = ['title' => $context['title'], 'url' => $context['url']];
|
||||
}
|
||||
|
||||
$item['versions'][$node['version_id']] = true;
|
||||
$item['context'] ??= ['composition' => $root, 'version_id' => $node['version_id']];
|
||||
$media[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function tree(User $user, CompositionVersion $version, bool $full, int $rootId): array
|
||||
{
|
||||
$key = $version->id.':'.($full ? 'voll' : 'kurz').':'.$rootId;
|
||||
|
||||
return $this->trees[$key] ??= array_map(
|
||||
fn (StructureNode $node): array => $this->present($user, $node, $full, $rootId),
|
||||
$this->structure->tree($version),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(User $user, StructureNode $node): array
|
||||
private function present(User $user, StructureNode $node, bool $full, int $rootId): array
|
||||
{
|
||||
$view = null;
|
||||
$download = null;
|
||||
|
||||
$playback = 'file';
|
||||
|
||||
$poster = null;
|
||||
$element = $node->contentElementId === null ? null : $this->element($node->contentElementId);
|
||||
|
||||
if ($node->contentElementVersionId !== null) {
|
||||
$view = $this->open($user, $node->contentElementVersionId, $this->viewAction($node->outputClass));
|
||||
$download = $this->open($user, $node->contentElementVersionId, 'laden');
|
||||
$playback = app(FilmPlayback::class)->mode($node->contentElementVersionId);
|
||||
if ($view !== null && $node->contentElementId !== null) {
|
||||
$path = ContentElement::query()->whereKey($node->contentElementId)->value('thumbnail_path');
|
||||
$poster = ThumbnailRef::url('member.thumbnail', 'element', $node->contentElementId, $path);
|
||||
|
||||
if ($full) {
|
||||
$download = $this->open($user, $node->contentElementVersionId, 'laden');
|
||||
$playback = app(FilmPlayback::class)->mode($node->contentElementVersionId);
|
||||
}
|
||||
|
||||
if ($view !== null && $element !== null) {
|
||||
$poster = ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path);
|
||||
}
|
||||
}
|
||||
|
||||
$title = $node->title;
|
||||
|
||||
if ($element !== null) {
|
||||
$title = $this->text($element)['title'] ?: $title;
|
||||
} elseif ($node->compositionId !== null) {
|
||||
$nested = Composition::query()->find($node->compositionId);
|
||||
$title = $nested === null ? $title : ($this->text($nested)['title'] ?: $title);
|
||||
}
|
||||
|
||||
return [
|
||||
'role' => $node->role,
|
||||
'title' => $node->title,
|
||||
'kind' => $node->editorialKindLabel ?? $node->technicalKindLabel,
|
||||
'title' => $title,
|
||||
'summary' => $element === null ? null : $this->text($element)['summary'],
|
||||
'kind' => $node->editorialKindLabel ?? $this->outputLabel($node->technicalKindLabel) ?? $node->technicalKindLabel,
|
||||
'output_class' => $node->outputClass,
|
||||
'playback' => $playback,
|
||||
'view_url' => $view,
|
||||
'poster_url' => $poster,
|
||||
'download_url' => $download,
|
||||
'program_url' => $this->programUrl($node),
|
||||
'composition_id' => $node->compositionId,
|
||||
'element_id' => $node->contentElementId,
|
||||
'version_id' => $node->contentElementVersionId,
|
||||
'content_url' => $node->contentElementVersionId === null ? null : route('member.content', [
|
||||
'composition' => $rootId,
|
||||
'version' => $node->contentElementVersionId,
|
||||
]),
|
||||
'children' => array_map(
|
||||
fn (StructureNode $child): array => $this->present($user, $child),
|
||||
fn (StructureNode $child): array => $this->present($user, $child, $full, $rootId),
|
||||
$node->children,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
* @param list<array<string, mixed>> $parents
|
||||
* @return array{node: array<string, mixed>, parents: list<array<string, mixed>>, siblings: list<array<string, mixed>>}|null
|
||||
*/
|
||||
private function locate(array $nodes, int $versionId, array $parents): ?array
|
||||
{
|
||||
foreach ($nodes as $node) {
|
||||
if ($node['version_id'] === $versionId) {
|
||||
return ['node' => $node, 'parents' => $parents, 'siblings' => $nodes];
|
||||
}
|
||||
|
||||
if ($node['children'] !== []) {
|
||||
$found = $this->locate($node['children'], $versionId, [...$parents, $node]);
|
||||
|
||||
if ($found !== null) {
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
* @return list<array<string, mixed>>
|
||||
@@ -183,18 +444,29 @@ private function leaves(array $nodes): array
|
||||
return $leaves;
|
||||
}
|
||||
|
||||
private function coverageLabel(User $user, Composition $composition): string
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
*/
|
||||
private function countCompositions(array $nodes): int
|
||||
{
|
||||
$version = $this->display->highestReleasedVersion($composition);
|
||||
$count = 0;
|
||||
|
||||
if ($version === null) {
|
||||
return 'nicht enthalten';
|
||||
foreach ($nodes as $node) {
|
||||
if ($node['composition_id'] !== null) {
|
||||
$count++;
|
||||
}
|
||||
|
||||
$count += $this->countCompositions($node['children']);
|
||||
}
|
||||
|
||||
$nodes = array_map(
|
||||
fn (StructureNode $node): array => $this->present($user, $node),
|
||||
$this->structure->tree($version),
|
||||
);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $nodes
|
||||
*/
|
||||
private function coverage(array $nodes): string
|
||||
{
|
||||
$leaves = $this->leaves($nodes);
|
||||
$open = count(array_filter($leaves, fn (array $leaf): bool => $leaf['view_url'] !== null));
|
||||
|
||||
@@ -205,6 +477,15 @@ private function coverageLabel(User $user, Composition $composition): string
|
||||
return $open === count($leaves) ? 'nutzbar' : 'teilweise';
|
||||
}
|
||||
|
||||
private function element(int $id): ?ContentElement
|
||||
{
|
||||
if (! array_key_exists($id, $this->elements)) {
|
||||
$this->elements[$id] = ContentElement::query()->find($id);
|
||||
}
|
||||
|
||||
return $this->elements[$id];
|
||||
}
|
||||
|
||||
private function programUrl(StructureNode $node): ?string
|
||||
{
|
||||
if ($node->compositionId === null || $node->compositionVersionId === null) {
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Commerce\OrderLine;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Domain\Entitlement\AcquisitionType;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Identity\PartyType;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Lizenzübersicht für Mitglieder: macht Erwerb, Zweck, Aktionen und Zeitraum je Berechtigung lesbar.
|
||||
*
|
||||
* Es gibt keine eigene Rechtelogik. Gezeigt wird je Berechtigung (Grant) genau das, was in ihr steht; Rechte verschiedener
|
||||
* Erwerbe werden weder zusammengezählt noch zu einem Gesamtprofil vereinigt. Den Zustand „aktiv“ bestimmt dieselbe Regel
|
||||
* wie die Zugriffsentscheidung (Status, Beginn und Ende), damit die Anzeige nie mehr verspricht als DecideAccess erlaubt.
|
||||
*/
|
||||
class MemberLicenses
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LibraryCatalog $catalog,
|
||||
private readonly CompositionStructureReader $structure,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function overview(User $user): Collection
|
||||
{
|
||||
return $this->grants($user)->map(fn (Grant $grant): array => $this->entry($user, $grant))->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function detail(User $user, Grant $grant): array
|
||||
{
|
||||
$grant->loadMissing('article.currentRelease.contents.elementVersion.element', 'article.currentRelease.rootCompositionVersion.composition');
|
||||
$entry = $this->entry($user, $grant);
|
||||
$release = $grant->article->currentRelease;
|
||||
$classes = [];
|
||||
$contents = [];
|
||||
|
||||
foreach ($release?->contents ?? [] as $content) {
|
||||
$element = $content->elementVersion?->element;
|
||||
|
||||
if ($element === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[$element->output_class] = ($classes[$element->output_class] ?? 0) + 1;
|
||||
$contents[$element->id] = [
|
||||
'title' => $this->catalog->text($element)['title'],
|
||||
'kind' => $this->catalog->outputLabel($element->output_class),
|
||||
'role' => $content->role,
|
||||
];
|
||||
}
|
||||
|
||||
$moduleCount = 0;
|
||||
$rootVersion = $release?->rootCompositionVersion;
|
||||
|
||||
if ($rootVersion !== null) {
|
||||
$moduleCount = $this->countCompositions($this->structure->tree($rootVersion));
|
||||
}
|
||||
|
||||
$scope = [];
|
||||
|
||||
if ($moduleCount > 0) {
|
||||
$scope[] = $moduleCount.' '.($moduleCount === 1 ? 'Modul' : 'Module');
|
||||
}
|
||||
|
||||
foreach ($classes as $class => $count) {
|
||||
$scope[] = $count.' '.$this->plural((string) $class, $count);
|
||||
}
|
||||
|
||||
$granted = $this->granted($grant);
|
||||
$restrictions = [];
|
||||
|
||||
foreach (array_keys($classes) as $class) {
|
||||
foreach (CatalogLabels::FAEHIGKEITEN as $key => $label) {
|
||||
if (str_starts_with($key, $class.':') && ! in_array($key, $granted, true)) {
|
||||
$restrictions[] = $label.' ist in diesem Erwerb nicht enthalten.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($entry['state'] !== 'aktiv') {
|
||||
array_unshift($restrictions, $entry['state_note']);
|
||||
}
|
||||
|
||||
if ($entry['holder_kind'] === 'organisation') {
|
||||
$restrictions[] = 'Die Nutzung gilt, solange deine Mitgliedschaft in dieser Organisation mit Bestellberechtigung besteht.';
|
||||
}
|
||||
|
||||
return $entry + [
|
||||
'scope' => $scope,
|
||||
'contents' => array_values($contents),
|
||||
'restrictions' => $restrictions,
|
||||
'composition' => $rootVersion?->composition,
|
||||
'open_url' => $rootVersion?->composition !== null
|
||||
? route('member.program', $rootVersion->composition)
|
||||
: route('member.article', $grant->article),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function entry(User $user, Grant $grant): array
|
||||
{
|
||||
$grant->loadMissing('article.currentRelease.rootCompositionVersion.composition.editorialContentKind', 'article.currentRelease.rootElementVersion.element', 'acquisition.party');
|
||||
$article = $grant->article;
|
||||
$release = $article->currentRelease;
|
||||
$state = $this->state($grant);
|
||||
$snapshot = is_array($grant->rights_snapshot) ? $grant->rights_snapshot : [];
|
||||
$conditions = is_array($grant->acquisition?->conditions) ? $grant->acquisition->conditions : [];
|
||||
$holderKind = $grant->acquisition?->party?->type === PartyType::Organisation ? 'organisation' : 'person';
|
||||
$composition = $release?->rootCompositionVersion?->composition;
|
||||
$element = $release?->rootElementVersion?->element;
|
||||
$imageUrl = null;
|
||||
|
||||
if ($grant->status === GrantStatus::Aktiv) {
|
||||
$imageUrl = $composition !== null
|
||||
? ThumbnailRef::url('member.thumbnail', 'komposition', $composition->id, $composition->thumbnail_path)
|
||||
: ($element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path));
|
||||
}
|
||||
|
||||
$title = $composition !== null
|
||||
? $this->catalog->text($composition)['title']
|
||||
: ($element !== null ? $this->catalog->text($element)['title'] : app(CourseOutline::class)->title($article));
|
||||
|
||||
return [
|
||||
'grant' => $grant,
|
||||
'id' => $grant->id,
|
||||
'title' => $title !== '' ? $title : $article->code,
|
||||
'kind' => app(CourseOutline::class)->kindLabel($article),
|
||||
'code' => $article->code,
|
||||
'image_url' => $imageUrl,
|
||||
'state' => $state['key'],
|
||||
'state_label' => $state['label'],
|
||||
'state_note' => $state['note'],
|
||||
'active' => $state['key'] === 'aktiv',
|
||||
'purpose' => filled($snapshot['purpose'] ?? null) ? CatalogLabels::zweck((string) $snapshot['purpose']) : null,
|
||||
'rights' => CatalogLabels::faehigkeiten(is_array($snapshot['capabilities'] ?? null) ? $snapshot['capabilities'] : []),
|
||||
'valid_from' => $grant->valid_from,
|
||||
'valid_until' => $grant->valid_until,
|
||||
'validity' => $this->validity($grant, $conditions),
|
||||
'term' => filled($conditions['term_rule'] ?? null) ? ProductOptions::termRuleLabel((string) $conditions['term_rule']) : null,
|
||||
'updates' => ($conditions['update_promise'] ?? null) === 'alle_freigegebenen_fassungen'
|
||||
? 'Spätere freigegebene Fassungen sind eingeschlossen.'
|
||||
: null,
|
||||
'source' => $this->source($user, $grant),
|
||||
'holder_kind' => $holderKind,
|
||||
'holder' => $holderKind === 'organisation' ? (string) ($grant->acquisition?->party?->display_name ?? 'Organisation') : 'Persönlich',
|
||||
'url' => route('member.grant', $grant),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zustand wie in DecideAccess: Status aktiv, Beginn erreicht, Ende nicht überschritten.
|
||||
*
|
||||
* @return array{key: string, label: string, note: string}
|
||||
*/
|
||||
private function state(Grant $grant): array
|
||||
{
|
||||
$now = now();
|
||||
|
||||
if ($grant->status === GrantStatus::Widerrufen) {
|
||||
return ['key' => 'widerrufen', 'label' => 'Widerrufen', 'note' => 'Diese Berechtigung wurde widerrufen.'.$this->reason($grant)];
|
||||
}
|
||||
|
||||
if ($grant->status === GrantStatus::Ausgesetzt) {
|
||||
return ['key' => 'ausgesetzt', 'label' => 'Ausgesetzt', 'note' => 'Diese Berechtigung ist derzeit ausgesetzt.'.$this->reason($grant)];
|
||||
}
|
||||
|
||||
if ($grant->status === GrantStatus::Abgelaufen || ($grant->valid_until !== null && ! $grant->valid_until->greaterThan($now))) {
|
||||
return ['key' => 'abgelaufen', 'label' => 'Abgelaufen', 'note' => 'Der Zeitraum dieser Berechtigung ist abgelaufen.'];
|
||||
}
|
||||
|
||||
if ($grant->valid_from !== null && $grant->valid_from->greaterThan($now)) {
|
||||
return ['key' => 'geplant', 'label' => 'Noch nicht gültig', 'note' => 'Diese Berechtigung beginnt am '.$this->date($grant->valid_from).'.'];
|
||||
}
|
||||
|
||||
return ['key' => 'aktiv', 'label' => 'Aktiv', 'note' => ''];
|
||||
}
|
||||
|
||||
private function reason(Grant $grant): string
|
||||
{
|
||||
return filled($grant->status_reason) ? ' Grund: '.$grant->status_reason : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $conditions
|
||||
*/
|
||||
private function validity(Grant $grant, array $conditions): string
|
||||
{
|
||||
$parts = [];
|
||||
|
||||
if ($grant->valid_from !== null) {
|
||||
$parts[] = 'seit '.$this->date($grant->valid_from);
|
||||
}
|
||||
|
||||
if ($grant->valid_until !== null) {
|
||||
$parts[] = 'bis '.$this->date($grant->valid_until);
|
||||
} elseif (($conditions['term_rule'] ?? 'dauerhaft') === 'dauerhaft') {
|
||||
$parts[] = 'ohne Ablaufdatum';
|
||||
} else {
|
||||
$parts[] = 'Ende nicht hinterlegt';
|
||||
}
|
||||
|
||||
return implode(' · ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Herkunft des Rechts: Art des Erwerbs und, soweit vorhanden, die Bezeichnung des Angebots.
|
||||
*
|
||||
* @return array{label: string, detail: ?string, url: ?string}
|
||||
*/
|
||||
private function source(User $user, Grant $grant): array
|
||||
{
|
||||
$acquisition = $grant->acquisition;
|
||||
$type = $acquisition?->type;
|
||||
$label = match ($type) {
|
||||
AcquisitionType::Bestellposition => 'Kauf',
|
||||
AcquisitionType::FreierAbruf => 'Kostenloser Abruf',
|
||||
AcquisitionType::ManuelleVergabe => 'Vergabe durch das Team',
|
||||
AcquisitionType::Abonnement => 'Abonnement',
|
||||
default => 'Erwerb',
|
||||
};
|
||||
$detail = null;
|
||||
$url = null;
|
||||
|
||||
if ($type === AcquisitionType::Bestellposition && $acquisition?->reference_type === 'order_line') {
|
||||
$line = OrderLine::query()->with('order')->find($acquisition->reference_id);
|
||||
|
||||
if ($line !== null) {
|
||||
$detail = $line->offer_name;
|
||||
|
||||
if ($line->order?->user_id === $user->id) {
|
||||
$url = route('member.order', $line->order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['label' => $label, 'detail' => $detail, 'url' => $url];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string> Schlüssel „Klasse:Aktion“ der Berechtigung
|
||||
*/
|
||||
private function granted(Grant $grant): array
|
||||
{
|
||||
$keys = [];
|
||||
$capabilities = is_array($grant->rights_snapshot['capabilities'] ?? null) ? $grant->rights_snapshot['capabilities'] : [];
|
||||
|
||||
foreach ($capabilities as $class => $actions) {
|
||||
foreach ((array) $actions as $action) {
|
||||
$keys[] = $class.':'.$action;
|
||||
}
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<StructureNode> $nodes
|
||||
*/
|
||||
private function countCompositions(array $nodes): int
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if ($node->compositionId !== null) {
|
||||
$count++;
|
||||
}
|
||||
|
||||
$count += $this->countCompositions($node->children);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
private function plural(string $class, int $count): string
|
||||
{
|
||||
$forms = match ($class) {
|
||||
'film' => ['Film', 'Filme'],
|
||||
'audio' => ['Hörstück', 'Hörstücke'],
|
||||
'document', 'pdf' => ['Dokument', 'Dokumente'],
|
||||
'text' => ['Text', 'Texte'],
|
||||
'bild' => ['Bild', 'Bilder'],
|
||||
default => [$class, $class],
|
||||
};
|
||||
|
||||
return $count === 1 ? $forms[0] : $forms[1];
|
||||
}
|
||||
|
||||
private function date(CarbonInterface $date): string
|
||||
{
|
||||
return $date->timezone(config('app.timezone'))->format('d.m.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Berechtigungen des Kontos, auch nicht mehr aktive: Inaktive sollen nachvollziehbar bleiben.
|
||||
*
|
||||
* @return Collection<int, Grant>
|
||||
*/
|
||||
private function grants(User $user): Collection
|
||||
{
|
||||
return Grant::query()
|
||||
->usableBy($user)
|
||||
->with('article.currentRelease', 'acquisition.party')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user