Führe Übungen als Fassungen mit Varianten, Verwendung und Mitgliederausgabe ein
CI Feature / test (push) Successful in 3m32s
CI Feature / test (push) Successful in 3m32s
Neuer kind 'exercise', Varianten je Fassung, Verwendung (erforderlich/ergänzend) und Variantenauswahl am einbindenden Mitglied; der Stand schreibt nur gewählte Varianten fest. Änderungsnachweis über structure_hash. Formatierte Anleitung im Mitgliederbereich und PDF (Fußzeile, Metadaten, Ausgabenachweis, keine gespeicherten Kopien); Sperre trifft nur das Medium. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef56befc0e
commit
d1f97a351a
26 files changed
+1628
-15
No files matched your search
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ExerciseGuide;
|
||||
use App\Domain\Catalog\ExercisePdf;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Media\DeliveryLog;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\SignedLink;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Die Übung als formatierte Anleitung innerhalb des erworbenen Moduls oder Programms und ihre PDF-Ausgabe. Beide zeigen
|
||||
* die im Artikel-Stand gebundene Übungsfassung und die dort angebotenen Varianten. Über jeden Abschnitt und jedes
|
||||
* Medium entscheidet `DecideAccess`; auch die direkte PDF-Adresse wird bei jedem Abruf neu entschieden.
|
||||
*/
|
||||
class ExerciseController extends Controller
|
||||
{
|
||||
public function show(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): View
|
||||
{
|
||||
[$guide, $located] = $this->load($request, $article, $release, $path);
|
||||
$user = $request->user();
|
||||
$copy = DeliveryLog::newCopyId();
|
||||
$shown = false;
|
||||
|
||||
foreach ($guide['entries'] as $index => $entry) {
|
||||
$link = fn (string $action) => SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'version' => $entry['version']->id,
|
||||
'action' => $action,
|
||||
'reader' => $user->id,
|
||||
]);
|
||||
$guide['entries'][$index]['url'] = $entry['allowed'] && $entry['class'] !== 'text' ? $link($entry['action']) : null;
|
||||
$guide['entries'][$index]['download_url'] = $entry['allowed'] && $entry['may_download'] && $entry['class'] !== 'text' ? $link('laden') : null;
|
||||
|
||||
if ($entry['allowed'] && $entry['class'] === 'text' && $entry['grant'] !== null) {
|
||||
app(DeliveryLog::class)->write($entry['grant'], $article, $release, $entry['version'], 'ansehen', 'text', hash('sha256', (string) $entry['version']->body), 'k2', $copy, $located['version']->id);
|
||||
$shown = true;
|
||||
}
|
||||
}
|
||||
|
||||
$pdfAllowed = app(ExercisePdf::class)->sections($guide) !== null;
|
||||
|
||||
return view('member.exercise', [
|
||||
'guide' => $guide,
|
||||
'article' => $article,
|
||||
'release' => $release,
|
||||
'path' => $path,
|
||||
'reader' => $user->name,
|
||||
'copy' => $shown ? $copy : null,
|
||||
'pdfUrl' => $pdfAllowed ? SignedLink::temporary('member.exercise.pdf', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'path' => $path,
|
||||
'variante' => $guide['chosen'],
|
||||
'reader' => $user->id,
|
||||
]) : null,
|
||||
'variantUrl' => fn (string $key): string => route('member.exercise', ['article' => $article, 'release' => $release, 'path' => $path, 'variante' => $key]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function pdf(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): Response
|
||||
{
|
||||
abort_unless((int) $request->query('reader') === $request->user()->id, 403);
|
||||
|
||||
[$guide, $located] = $this->load($request, $article, $release, $path);
|
||||
$pdf = app(ExercisePdf::class);
|
||||
$sections = $pdf->sections($guide);
|
||||
abort_if($sections === null, 403, 'Für dieses PDF fehlt die Berechtigung oder ein erforderlicher Bestandteil.');
|
||||
|
||||
$copy = DeliveryLog::newCopyId();
|
||||
$variant = collect($guide['variants'])->firstWhere('key', $guide['chosen']);
|
||||
$content = $pdf->render(
|
||||
$guide,
|
||||
$sections,
|
||||
$request->user()->name,
|
||||
$copy,
|
||||
(string) ($variant['name'] ?? ''),
|
||||
route('member.exercise', ['article' => $article, 'release' => $release, 'path' => $path, 'variante' => $guide['chosen']]),
|
||||
);
|
||||
$checksum = hash('sha256', $content);
|
||||
|
||||
foreach ($sections as $section) {
|
||||
$grant = $section['download_grant'] ?? $section['grant'];
|
||||
|
||||
if ($grant !== null) {
|
||||
app(DeliveryLog::class)->write($grant, $article, $release, $section['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
|
||||
}
|
||||
}
|
||||
|
||||
$name = str($guide['title'])->slug()->value() ?: 'uebung';
|
||||
|
||||
return response($content, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="'.$name.'.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);
|
||||
abort_if($located === null, 404);
|
||||
|
||||
$variant = $request->query('variante');
|
||||
|
||||
return [
|
||||
$guides->build($request->user(), $article, $release, $located['version'], $located['selection'], is_string($variant) ? $variant : null),
|
||||
$located,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user