Files
laraundfelix/app/Http/Controllers/Member/DocumentController.php
T
LarsandClaude Sonnet 5.5 81037b9868
Deploy Test / test (push) Successful in 3m0s
Deploy Test / deploy (push) Successful in 25s
Lasse Bilder im Text den Rechten des Textes folgen, gib Bild- und PDF-Adressen ohne Ablauf aus und belege die Abnahme
- Bilder im Text folgen dem Recht am Text; eine eigene Fähigkeit für Bilder ist nicht nötig (ADR-51, fachliche Entscheidung zur Bestätigung).
- Bildadresse und PDF-Adresse des Dokuments laufen nicht ab; jeder Abruf entscheidet neu.
- Die Fähigkeit text:laden ist im Rechteprofil wählbar.
- Dokumentkapitel in der Medienansicht verweisen auf ihr Dokument; die Pille nennt jetzt auch Dokumentkapitel (MedienFilterDialogTest bewusst angepasst).
- Abnahmeprotokoll mit Bildern unter docs/ux/verwaltung/abnahme/dokumente.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-24 12:55:21 +01:00

92 lines
4.2 KiB
PHP

<?php
namespace App\Http\Controllers\Member;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\DocumentGuide;
use App\Domain\Catalog\DocumentPdf;
use App\Domain\Catalog\EmbeddedImages;
use App\Domain\Catalog\ExerciseGuide;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Media\DeliveryLog;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
/**
* Das Dokument innerhalb des erworbenen Moduls oder Programms: als zusammenhängende Seite mit anklickbarem
* Inhaltsverzeichnis und als PDF. Beide zeigen die im Artikel-Stand gebundene Dokumentfassung (ADR-51); über jedes Kapitel
* und jedes Bild entscheidet `DecideAccess`, auch die direkte PDF-Adresse wird bei jedem Abruf neu entschieden.
*/
class DocumentController extends Controller
{
public function show(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): View
{
[$guide, $located] = $this->load($request, $article, $release, $path);
$copy = DeliveryLog::newCopyId();
$shown = false;
foreach ($guide['chapters'] as $chapter) {
if ($chapter['allowed'] && $chapter['grant'] !== null) {
app(DeliveryLog::class)->write($chapter['grant'], $article, $release, $chapter['version'], 'ansehen', 'text', hash('sha256', (string) $chapter['version']->body), 'k2', $copy, $located['version']->id);
$shown = true;
}
}
return view('member.document', [
'guide' => $guide,
'reader' => $request->user()->name,
'copy' => $shown ? $copy : null,
// Ohne Ablauf der Adresse: Die Seite bleibt lange offen; bei jedem Abruf entscheidet `DecideAccess` neu.
'pdfUrl' => app(DocumentGuide::class)->pdfAllowed($guide) ? route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => $path]) : null,
]);
}
public function pdf(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): Response
{
[$guide, $located] = $this->load($request, $article, $release, $path);
abort_unless(app(DocumentGuide::class)->pdfAllowed($guide), 403, 'Für dieses PDF fehlt die Berechtigung für ein Kapitel.');
$copy = DeliveryLog::newCopyId();
$images = app(EmbeddedImages::class)->forPdf($request->user(), $article, $release, array_map(fn (array $chapter): ContentElementVersion => $chapter['version'], $guide['chapters']));
$content = app(DocumentPdf::class)->render($guide, $request->user()->name, $copy, $images);
$checksum = hash('sha256', $content);
foreach ($guide['chapters'] as $chapter) {
$grant = $chapter['download_grant'] ?? $chapter['grant'];
if ($grant !== null) {
app(DeliveryLog::class)->write($grant, $article, $release, $chapter['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
}
}
foreach ($images->used() as $image) {
app(DeliveryLog::class)->write($image['grant'], $article, $release, $image['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
}
return response($content, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.(str($guide['title'])->slug()->value() ?: 'dokument').'.pdf"',
'X-License-Copy' => $copy,
'Cache-Control' => 'private, no-store',
]);
}
/**
* @return array{0: array<string, mixed>, 1: array{version: CompositionVersion, selection: list<string>|null}}
*/
private function load(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): array
{
$guides = app(ExerciseGuide::class);
abort_unless($guides->mayOpen($request->user(), $article, $release), 403);
$located = $guides->locate($release, $path, CompositionKind::Document);
abort_if($located === null, 404);
return [app(DocumentGuide::class)->build($request->user(), $article, $release, $located['version']), $located];
}
}