Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
881703ba0e | ||
|
|
bbee288e69 | ||
|
|
d1f97a351a | ||
|
|
ef56befc0e |
No files matched your search
@@ -70,3 +70,7 @@ PAYMENT_DRIVER=test
|
||||
MEDIA_PUBLIC_PATH=
|
||||
MEDIA_DERIVED_PATH=
|
||||
MEDIA_ORIGINALS_PATH=
|
||||
|
||||
# Übernahme von Übungen aus Shinkan (Test: erst nach Freigabe der Anbindung eintragen; Werte nie ins Repository)
|
||||
SHINKAN_DISTRIBUTION_URL=
|
||||
SHINKAN_DISTRIBUTION_KEY=
|
||||
@@ -57,6 +57,8 @@ public function publishRelease(
|
||||
'content_element_version_id' => $row['version_id'],
|
||||
'role' => $row['role'] !== '' ? $row['role'] : $row['path'],
|
||||
'path' => $row['path'],
|
||||
'requirement' => $row['requirement'] ?? null,
|
||||
'variant_key' => $row['variant'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -141,6 +143,10 @@ private function checkedRows(ContentElementVersion|CompositionVersion $root): ar
|
||||
{
|
||||
$root->refresh();
|
||||
|
||||
if (app(ForeignCompositions::class)->reaches($root)) {
|
||||
throw new DomainRuleException('Der Aufbau enthält einen Bestandteil, den dieser Programmstand nicht kennt. Er wird hier nicht veröffentlicht, damit nichts fehlt oder zu viel ausgegeben wird.');
|
||||
}
|
||||
|
||||
if ($root->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Ein Artikel-Stand kann nur eine bereitgestellte Fassung festschreiben.');
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class CompatibilityAttestation extends Model
|
||||
protected $fillable = [
|
||||
'composition_version_id',
|
||||
'resolved_hash',
|
||||
'structure_hash',
|
||||
'confirmed_by',
|
||||
'confirmed_at',
|
||||
'note',
|
||||
|
||||
@@ -36,6 +36,11 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new SupportedKindScope);
|
||||
}
|
||||
|
||||
public function editorialContentKind(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EditorialContentKind::class);
|
||||
|
||||
@@ -7,13 +7,24 @@ enum CompositionKind: string
|
||||
case Kombination = 'kombination';
|
||||
case Uebung = 'uebung';
|
||||
case Kurs = 'kurs';
|
||||
/** Seit der Übungsverwaltung: die fachliche Übung. Der ältere Wert `uebung` bezeichnet in der Verwaltung das Modul. */
|
||||
case Exercise = 'exercise';
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(fn (self $case): string => $case->value, self::cases());
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Kombination => 'Fachliche Kombination',
|
||||
self::Uebung => 'Übung',
|
||||
self::Uebung => 'Modul',
|
||||
self::Kurs => 'Kurs',
|
||||
self::Exercise => 'Übung',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,8 +32,9 @@ public function plural(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Kombination => 'Fachliche Kombinationen',
|
||||
self::Uebung => 'Übungen',
|
||||
self::Uebung => 'Module',
|
||||
self::Kurs => 'Kurse',
|
||||
self::Exercise => 'Übungen',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,8 +42,9 @@ public function createLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Kombination => 'Kombination anlegen',
|
||||
self::Uebung => 'Übung anlegen',
|
||||
self::Uebung => 'Modul anlegen',
|
||||
self::Kurs => 'Kurs anlegen',
|
||||
self::Exercise => 'Übung anlegen',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,6 +54,7 @@ public function explanation(): string
|
||||
self::Kombination => 'Didaktische oder thematische Zusammenstellung, zum Beispiel ein Materialsatz. Sie wird in Übungen und Kursen wiederverwendet und ist selbst kein Kurs.',
|
||||
self::Uebung => 'Eine konkrete Lernsituation, zum Beispiel aus Film und Merkblatt. Dieselben Medien können in mehreren Übungen stecken.',
|
||||
self::Kurs => 'Ein Ablauf für den Kursbetrieb aus Übungen, Kombinationen und Medien. Ein Kurs ist keine Übung.',
|
||||
self::Exercise => 'Eine Übung mit Lernziel, Vorbereitung, Durchführung und Varianten, mit Texten und Medien in fester Abfolge. Sie wird in Module und Programme aufgenommen.',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,6 +64,7 @@ public function deskLabel(): string
|
||||
self::Kombination => 'Fachliche Kombination',
|
||||
self::Uebung => 'Modul',
|
||||
self::Kurs => 'Programm',
|
||||
self::Exercise => 'Übung',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,6 +74,7 @@ public function deskExplanation(): string
|
||||
self::Kombination => $this->explanation(),
|
||||
self::Uebung => 'Ein Modul mit Lernziel, Zeit, Material und geordneten Bestandteilen. Dieselben Medien können in mehreren Modulen stecken.',
|
||||
self::Kurs => 'Ein Programm aus Modulen und weiteren Inhalten.',
|
||||
self::Exercise => $this->explanation(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,21 @@ class CompositionMember extends Model
|
||||
'placement_note',
|
||||
'content_element_version_id',
|
||||
'nested_composition_version_id',
|
||||
'variant_id',
|
||||
'requirement',
|
||||
'variant_selection',
|
||||
'origin',
|
||||
];
|
||||
|
||||
public const REQUIRED = 'erforderlich';
|
||||
|
||||
public const SUPPLEMENTARY = 'ergaenzend';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['variant_selection' => 'array'];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (CompositionMember $member): void {
|
||||
@@ -41,6 +54,11 @@ public function contentElementVersion(): BelongsTo
|
||||
return $this->belongsTo(ContentElementVersion::class);
|
||||
}
|
||||
|
||||
public function variant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CompositionVersionVariant::class, 'variant_id');
|
||||
}
|
||||
|
||||
public function nestedCompositionVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CompositionVersion::class, 'nested_composition_version_id');
|
||||
|
||||
@@ -54,6 +54,7 @@ public function publish(
|
||||
?string $note,
|
||||
array $didactic,
|
||||
bool $consent,
|
||||
array $variants = [],
|
||||
): CompositionVersion {
|
||||
$review = $this->review($host, $members);
|
||||
|
||||
@@ -67,8 +68,8 @@ public function publish(
|
||||
|
||||
$this->publishedDrafts = [];
|
||||
|
||||
return DB::transaction(function () use ($host, $members, $actor, $note, $didactic): CompositionVersion {
|
||||
return $this->materialize($host, $members, $didactic, $actor, $note, []);
|
||||
return DB::transaction(function () use ($host, $members, $actor, $note, $didactic, $variants): CompositionVersion {
|
||||
return $this->materialize($host, $members, $didactic, $actor, $note, [], $variants);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -220,6 +221,12 @@ private function inspectReleasedComposition(
|
||||
): void {
|
||||
$version = CompositionVersion::query()->with('composition', 'members')->find($id);
|
||||
|
||||
if ($version instanceof CompositionVersion && $version->composition === null && app(ForeignCompositions::class)->isForeignVersion($version->id)) {
|
||||
$blocked[] = $this->block('Bestandteil', 'Dieser Bestandteil stammt aus einer neueren Programmversion und kann hier nicht freigegeben werden.', $depth, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $version instanceof CompositionVersion || $version->composition === null) {
|
||||
$blocked[] = $this->block('Modul', 'Ein Bestandteil ist nicht mehr vorhanden.', $depth, null);
|
||||
|
||||
@@ -324,6 +331,7 @@ private function materialize(
|
||||
?User $actor,
|
||||
?string $note,
|
||||
array $stack,
|
||||
array $variants = [],
|
||||
): CompositionVersion {
|
||||
if (isset($this->publishedDrafts[$composition->id])) {
|
||||
return $this->publishedDrafts[$composition->id];
|
||||
@@ -341,6 +349,10 @@ private function materialize(
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'note' => trim((string) ($member['note'] ?? '')),
|
||||
'target' => $this->resolveTarget((string) ($member['target'] ?? ''), $actor, $stack),
|
||||
'variant' => isset($member['variant']) && $member['variant'] !== '' ? (string) $member['variant'] : null,
|
||||
'requirement' => $member['requirement'] ?? 'erforderlich',
|
||||
'selection' => is_array($member['selection'] ?? null) && $member['selection'] !== [] ? array_values($member['selection']) : null,
|
||||
'origin' => $member['origin'] ?? 'lokal',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -352,8 +364,11 @@ private function materialize(
|
||||
[
|
||||
'learning_goal' => $didactic['learning_goal'] ?? null,
|
||||
'duration_minutes' => $didactic['duration_minutes'] ?? null,
|
||||
'duration_max' => $didactic['duration_max'] ?? null,
|
||||
'material_note' => $didactic['material_note'] ?? null,
|
||||
'prerequisites' => $didactic['prerequisites'] ?? null,
|
||||
],
|
||||
$variants,
|
||||
);
|
||||
$this->publishedDrafts[$composition->id] = $version;
|
||||
|
||||
@@ -414,11 +429,14 @@ private function resolveTarget(string $target, ?User $actor, array $stack): Cont
|
||||
[
|
||||
'learning_goal' => $draft['learning_goal'] ?? null,
|
||||
'duration_minutes' => $draft['duration_minutes'] ?? null,
|
||||
'duration_max' => $draft['duration_max'] ?? null,
|
||||
'material_note' => $draft['material_note'] ?? null,
|
||||
'prerequisites' => $draft['prerequisites'] ?? null,
|
||||
],
|
||||
$actor,
|
||||
is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null,
|
||||
$stack,
|
||||
is_array($draft['variants'] ?? null) ? $draft['variants'] : [],
|
||||
);
|
||||
app(EditorialWorkingDraft::class)->clear($composition);
|
||||
|
||||
|
||||
@@ -60,6 +60,11 @@ private function members(CompositionVersion $version, array $stack = []): array
|
||||
$nested->loadMissing('composition.editorialContentKind', 'composition');
|
||||
$composition = $nested->composition;
|
||||
|
||||
// Bestandteil einer Art, die dieser Programmstand nicht kennt: nicht anzeigen (Rückfallschutz).
|
||||
if ($composition === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$nodes[] = new StructureNode(
|
||||
role: $member->role,
|
||||
position: $member->position,
|
||||
|
||||
@@ -17,6 +17,10 @@ class CompositionVersion extends Model
|
||||
'learning_goal',
|
||||
'duration_minutes',
|
||||
'material_note',
|
||||
'duration_max',
|
||||
'prerequisites',
|
||||
'structure_hash',
|
||||
'source_snapshot_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -60,6 +64,11 @@ public function members(): HasMany
|
||||
return $this->hasMany(CompositionMember::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function variants(): HasMany
|
||||
{
|
||||
return $this->hasMany(CompositionVersionVariant::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function attestations(): HasMany
|
||||
{
|
||||
return $this->hasMany(CompatibilityAttestation::class);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Durchführungsvariante einer Übungsfassung. Der Schlüssel ist je Fassung eindeutig und bleibt über Fassungen hinweg
|
||||
* gleich, damit eine Auswahl im Modul oder Programm und der Abgleich mit einer Quelle dieselbe Variante meinen.
|
||||
* Wie die Mitglieder ist sie nur im Entwurf der Fassung schreibbar.
|
||||
*/
|
||||
class CompositionVersionVariant extends Model
|
||||
{
|
||||
protected $fillable = ['composition_version_id', 'key', 'position', 'name', 'description', 'origin'];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (CompositionVersionVariant $variant): void {
|
||||
$status = CompositionVersion::query()->whereKey($variant->composition_version_id)->value('status');
|
||||
|
||||
if (StatusValue::of($status) === ContentVersionStatus::Bereit->value) {
|
||||
throw new DomainRuleException('Eine bestätigte Kompositionsfassung nimmt keine weiteren Varianten auf.');
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function (): void {
|
||||
throw new DomainRuleException('Varianten einer Komposition werden nicht verändert, sondern durch eine neue Fassung ersetzt.');
|
||||
});
|
||||
}
|
||||
|
||||
public function compositionVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CompositionVersion::class);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class ContentElement extends Model
|
||||
'preview_path',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
'source_ref',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
|
||||
@@ -5,9 +5,14 @@
|
||||
class ContentResolver
|
||||
{
|
||||
/**
|
||||
* @return list<array{version_id: int, role: string, path: string}>
|
||||
* Löst eine Wurzel zu den enthaltenen Medienfassungen auf. Eine Übung wird nur mit ihren gemeinsamen Mitgliedern und
|
||||
* den ausgewählten Varianten aufgelöst: Das Mitglied, das die Übungsfassung einbindet, trägt die Auswahl
|
||||
* (`variant_selection`, Liste von Variantenschlüsseln; leer gelassen bedeutet alle Varianten).
|
||||
*
|
||||
* @param list<string>|null $selection Variantenschlüssel, die für diese Fassung gelten; null = alle
|
||||
* @return list<array{version_id: int, role: string, path: string, requirement: string, variant: string|null}>
|
||||
*/
|
||||
public function expand(ContentElementVersion|CompositionVersion $node, string $path = '', array $stack = []): array
|
||||
public function expand(ContentElementVersion|CompositionVersion $node, string $path = '', array $stack = [], ?array $selection = null): array
|
||||
{
|
||||
if ($node instanceof ContentElementVersion) {
|
||||
$node->loadMissing('element');
|
||||
@@ -16,6 +21,8 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
||||
'version_id' => $node->id,
|
||||
'role' => $path,
|
||||
'path' => $path !== '' ? $path : $node->element->working_title,
|
||||
'requirement' => CompositionMember::REQUIRED,
|
||||
'variant' => null,
|
||||
]];
|
||||
}
|
||||
|
||||
@@ -26,7 +33,13 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
||||
$stack[] = $node->composition_id;
|
||||
$rows = [];
|
||||
|
||||
foreach ($node->members()->orderBy('position')->get() as $member) {
|
||||
foreach ($node->members()->with('variant')->orderBy('position')->get() as $member) {
|
||||
$variantKey = $member->variant?->key;
|
||||
|
||||
if ($variantKey !== null && $selection !== null && ! in_array($variantKey, $selection, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$segment = $path === '' ? $member->role : $path.' / '.$member->role;
|
||||
|
||||
if ($member->content_element_version_id !== null) {
|
||||
@@ -34,6 +47,8 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
||||
'version_id' => $member->content_element_version_id,
|
||||
'role' => $member->role,
|
||||
'path' => $segment,
|
||||
'requirement' => $member->requirement ?: CompositionMember::REQUIRED,
|
||||
'variant' => $variantKey,
|
||||
];
|
||||
|
||||
continue;
|
||||
@@ -45,7 +60,20 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
||||
throw new DomainRuleException('Ein Kompositionsmitglied braucht genau ein Ziel.');
|
||||
}
|
||||
|
||||
$rows = array_merge($rows, $this->expand($nested, $segment, $stack));
|
||||
// Bestandteil einer Art, die dieser Programmstand nicht kennt: nicht auflösen (Rückfallschutz).
|
||||
// Veröffentlichen verweigern die aufrufenden Stellen über ForeignCompositions.
|
||||
$nested->loadMissing('composition');
|
||||
|
||||
if ($nested->composition === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows = array_merge($rows, $this->expand(
|
||||
$nested,
|
||||
$segment,
|
||||
$stack,
|
||||
is_array($member->variant_selection) ? array_values(array_map('strval', $member->variant_selection)) : null,
|
||||
));
|
||||
}
|
||||
|
||||
return $rows;
|
||||
|
||||
@@ -225,7 +225,9 @@ public function releaseElementVersion(ContentElementVersion $version): ContentEl
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion}> $members
|
||||
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion, note?: string|null, variant?: string|null, requirement?: string|null, selection?: list<string>|null}> $members
|
||||
* @param array{learning_goal?: mixed, duration_minutes?: mixed, duration_max?: mixed, material_note?: mixed, prerequisites?: mixed} $didactic
|
||||
* @param list<array{key: string, name: string, description?: string|null, origin?: string}> $variants Durchführungsvarianten einer Übung
|
||||
*/
|
||||
public function publishComposition(
|
||||
Composition $composition,
|
||||
@@ -233,18 +235,21 @@ public function publishComposition(
|
||||
?User $confirmedBy = null,
|
||||
?string $note = null,
|
||||
array $didactic = [],
|
||||
array $variants = [],
|
||||
): CompositionVersion {
|
||||
if ($members === []) {
|
||||
throw new DomainRuleException('Eine Komposition braucht mindestens ein Mitglied.');
|
||||
}
|
||||
|
||||
$variants = $this->checkedVariants($variants);
|
||||
$this->assertAcyclic($composition->id, $members);
|
||||
|
||||
foreach ($members as $member) {
|
||||
$this->assertReadyMember($member['target']);
|
||||
$this->assertMemberPlacement($member, $variants);
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($composition, $members, $confirmedBy, $note, $didactic): CompositionVersion {
|
||||
return DB::transaction(function () use ($composition, $members, $confirmedBy, $note, $didactic, $variants): CompositionVersion {
|
||||
$number = ((int) $composition->versions()->max('number')) + 1;
|
||||
$version = $composition->versions()->create([
|
||||
'number' => $number,
|
||||
@@ -253,28 +258,52 @@ public function publishComposition(
|
||||
'resolved_hash' => 'pending',
|
||||
'learning_goal' => $this->optionalText($didactic['learning_goal'] ?? null),
|
||||
'duration_minutes' => isset($didactic['duration_minutes']) ? (int) $didactic['duration_minutes'] : null,
|
||||
'duration_max' => isset($didactic['duration_max']) ? (int) $didactic['duration_max'] : null,
|
||||
'material_note' => $this->optionalText($didactic['material_note'] ?? null),
|
||||
'prerequisites' => $this->optionalText($didactic['prerequisites'] ?? null),
|
||||
'source_snapshot_id' => isset($didactic['source_snapshot_id']) ? (int) $didactic['source_snapshot_id'] : null,
|
||||
]);
|
||||
|
||||
$variantIds = [];
|
||||
|
||||
foreach ($variants as $index => $variant) {
|
||||
$variantIds[$variant['key']] = $version->variants()->create([
|
||||
'key' => $variant['key'],
|
||||
'position' => $index + 1,
|
||||
'name' => $variant['name'],
|
||||
'description' => $variant['description'],
|
||||
'origin' => $variant['origin'],
|
||||
])->id;
|
||||
}
|
||||
|
||||
foreach (array_values($members) as $index => $member) {
|
||||
$target = $member['target'];
|
||||
$selection = $target instanceof CompositionVersion ? ($member['selection'] ?? null) : null;
|
||||
$version->members()->create([
|
||||
'position' => $index + 1,
|
||||
'role' => $this->required($member['role'], 'Die Rolle eines Mitglieds fehlt.'),
|
||||
'placement_note' => $this->optionalText($member['note'] ?? null),
|
||||
'content_element_version_id' => $target instanceof ContentElementVersion ? $target->id : null,
|
||||
'nested_composition_version_id' => $target instanceof CompositionVersion ? $target->id : null,
|
||||
'variant_id' => isset($member['variant']) ? $variantIds[$member['variant']] : null,
|
||||
'requirement' => $member['requirement'] ?? CompositionMember::REQUIRED,
|
||||
'variant_selection' => $selection === null ? null : array_values($selection),
|
||||
'origin' => ($member['origin'] ?? 'lokal') === 'quelle' ? 'quelle' : 'lokal',
|
||||
]);
|
||||
}
|
||||
|
||||
$version->load('members.variant', 'variants');
|
||||
$resolvedHash = $this->resolver->resolvedHash($version);
|
||||
$structureHash = $this->structureHash($version);
|
||||
$version->attestations()->create([
|
||||
'resolved_hash' => $resolvedHash,
|
||||
'structure_hash' => $structureHash,
|
||||
'confirmed_by' => $confirmedBy?->id,
|
||||
'confirmed_at' => now(),
|
||||
'note' => $note,
|
||||
]);
|
||||
$version->resolved_hash = $resolvedHash;
|
||||
$version->structure_hash = $structureHash;
|
||||
$version->status = ContentVersionStatus::Bereit;
|
||||
$version->save();
|
||||
|
||||
@@ -282,6 +311,103 @@ public function publishComposition(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Änderungsnachweis einer Fassung: Felder, Varianten und die Verwendung jedes Mitglieds. Anders als der
|
||||
* `resolved_hash` (nur die Menge der enthaltenen Medienfassungen) ändert er sich auch dann, wenn Variante,
|
||||
* Verwendung, Reihenfolge oder Variantenauswahl wechseln und die Medien gleich bleiben.
|
||||
*/
|
||||
public function structureHash(CompositionVersion $version): string
|
||||
{
|
||||
$version->loadMissing('members.variant', 'variants');
|
||||
|
||||
return hash('sha256', json_encode([
|
||||
'fields' => [
|
||||
$version->learning_goal,
|
||||
$version->duration_minutes,
|
||||
$version->duration_max,
|
||||
$version->material_note,
|
||||
$version->prerequisites,
|
||||
],
|
||||
'variants' => $version->variants->map(fn (CompositionVersionVariant $variant): array => [
|
||||
$variant->key, $variant->position, $variant->name, $variant->description, $variant->origin,
|
||||
])->all(),
|
||||
'members' => $version->members->map(fn (CompositionMember $member): array => [
|
||||
$member->position,
|
||||
$member->role,
|
||||
$member->placement_note,
|
||||
$member->content_element_version_id,
|
||||
$member->nested_composition_version_id,
|
||||
$member->variant?->key,
|
||||
$member->requirement,
|
||||
$member->variant_selection,
|
||||
$member->origin,
|
||||
])->all(),
|
||||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{key?: string, name?: string, description?: string|null}> $variants
|
||||
* @return list<array{key: string, name: string, description: string|null}>
|
||||
*/
|
||||
private function checkedVariants(array $variants): array
|
||||
{
|
||||
$checked = [];
|
||||
$keys = [];
|
||||
|
||||
foreach (array_values($variants) as $variant) {
|
||||
$key = trim((string) ($variant['key'] ?? ''));
|
||||
|
||||
if ($key === '' || in_array($key, $keys, true)) {
|
||||
throw new DomainRuleException('Jede Variante braucht einen eigenen Schlüssel.');
|
||||
}
|
||||
|
||||
$keys[] = $key;
|
||||
$checked[] = [
|
||||
'key' => $key,
|
||||
'name' => $this->required((string) ($variant['name'] ?? ''), 'Jede Variante braucht einen Namen.'),
|
||||
'description' => $this->optionalText($variant['description'] ?? null),
|
||||
'origin' => ($variant['origin'] ?? 'lokal') === 'quelle' ? 'quelle' : 'lokal',
|
||||
];
|
||||
}
|
||||
|
||||
return $checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{target: ContentElementVersion|CompositionVersion, variant?: string|null, requirement?: string|null, selection?: list<string>|null} $member
|
||||
* @param list<array{key: string, name: string, description: string|null}> $variants
|
||||
*/
|
||||
private function assertMemberPlacement(array $member, array $variants): void
|
||||
{
|
||||
$variant = $member['variant'] ?? null;
|
||||
|
||||
if ($variant !== null && ! in_array($variant, array_column($variants, 'key'), true)) {
|
||||
throw new DomainRuleException('Ein Mitglied verweist auf eine Variante, die es in dieser Fassung nicht gibt.');
|
||||
}
|
||||
|
||||
$requirement = $member['requirement'] ?? CompositionMember::REQUIRED;
|
||||
|
||||
if (! in_array($requirement, [CompositionMember::REQUIRED, CompositionMember::SUPPLEMENTARY], true)) {
|
||||
throw new DomainRuleException('Die Verwendung eines Mitglieds ist erforderlich oder ergänzend.');
|
||||
}
|
||||
|
||||
$selection = $member['selection'] ?? null;
|
||||
|
||||
if ($selection === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $member['target'] instanceof CompositionVersion) {
|
||||
throw new DomainRuleException('Eine Variantenauswahl gibt es nur an einer eingebundenen Übungsfassung.');
|
||||
}
|
||||
|
||||
$offered = $member['target']->variants()->pluck('key')->all();
|
||||
|
||||
if ($selection === [] || array_diff($selection, $offered) !== []) {
|
||||
throw new DomainRuleException('Die Variantenauswahl nennt eine Variante, die die eingebundene Fassung nicht anbietet, oder keine.');
|
||||
}
|
||||
}
|
||||
|
||||
public function createComposition(string $designation, CompositionKind $kind = CompositionKind::Uebung): Composition
|
||||
{
|
||||
return Composition::query()->create([
|
||||
@@ -345,6 +471,10 @@ private function assertAcyclic(int $compositionId, array $members, array $stack
|
||||
|
||||
private function assertReadyMember(ContentElementVersion|CompositionVersion $target): void
|
||||
{
|
||||
if (app(ForeignCompositions::class)->reaches($target)) {
|
||||
throw new DomainRuleException('Dieser Bestandteil stammt aus einer neueren Programmversion und wird hier nicht in eine Fassung aufgenommen.');
|
||||
}
|
||||
|
||||
if ($target->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Eine Komposition darf nur bereitgestellte Fassungen enthalten.');
|
||||
}
|
||||
@@ -365,6 +495,9 @@ private function membersHash(array $members): string
|
||||
'note' => $this->optionalText($member['note'] ?? null),
|
||||
'element_version_id' => $target instanceof ContentElementVersion ? $target->id : null,
|
||||
'composition_version_id' => $target instanceof CompositionVersion ? $target->id : null,
|
||||
'variant' => $member['variant'] ?? null,
|
||||
'requirement' => $member['requirement'] ?? CompositionMember::REQUIRED,
|
||||
'selection' => $member['selection'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ class EditorialContentKind extends Model
|
||||
public const CONTEXTS = [
|
||||
'medium' => 'Medium',
|
||||
'modul' => 'Modul',
|
||||
'uebung' => 'Übung',
|
||||
'programm' => 'Programm',
|
||||
'lizenzartikel' => 'Lizenzartikel',
|
||||
];
|
||||
@@ -26,7 +27,7 @@ class EditorialContentKind extends Model
|
||||
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
|
||||
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
|
||||
*/
|
||||
public const SYSTEM_SLUGS = ['programm', 'modul', 'traineranleitung'];
|
||||
public const SYSTEM_SLUGS = ['programm', 'modul', 'uebung', 'traineranleitung'];
|
||||
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
|
||||
@@ -46,6 +46,7 @@ public static function compositionContext(?CompositionKind $kind): ?string
|
||||
return match ($kind) {
|
||||
CompositionKind::Kurs => 'programm',
|
||||
CompositionKind::Uebung => 'modul',
|
||||
CompositionKind::Exercise => 'uebung',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
@@ -137,6 +138,7 @@ private function usedKindIds(string $context): array
|
||||
'lizenzartikel' => DB::table('license_articles'),
|
||||
'programm' => DB::table('compositions')->where('kind', CompositionKind::Kurs->value),
|
||||
'modul' => DB::table('compositions')->where('kind', CompositionKind::Uebung->value),
|
||||
'uebung' => DB::table('compositions')->where('kind', CompositionKind::Exercise->value),
|
||||
default => null,
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Http\LibraryCatalog;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Die Anleitung einer Übung, wie ein Stand sie festschreibt: die im Stand gebundene Übungsfassung, die angebotenen
|
||||
* Varianten und je Abschnitt oder Medium die Entscheidung der zentralen Rechteprüfung (`DecideAccess`). Ansicht und
|
||||
* PDF lesen dieses Ergebnis und zeigen damit dieselbe Fassung.
|
||||
*
|
||||
* Eine Sperre oder fehlende Berechtigung betrifft nur den betroffenen Abschnitt oder das Medium. Anleitung und übrige
|
||||
* Inhalte bleiben im selben Stand erreichbar. Fehlt in einer Variante ein erforderlicher Bestandteil, gilt die Variante
|
||||
* als derzeit nicht vollständig durchführbar; ein ergänzender Bestandteil entfällt mit einem Hinweis.
|
||||
*/
|
||||
class ExerciseGuide
|
||||
{
|
||||
public function __construct(private readonly DecideAccess $access) {}
|
||||
|
||||
/**
|
||||
* Darf dieses Konto den Stand überhaupt sehen? Aktive, nutzbare Berechtigung auf den Artikel und ein auslieferbarer
|
||||
* Stand. Über die einzelnen Inhalte entscheidet danach `DecideAccess`.
|
||||
*/
|
||||
public function mayOpen(User $user, LicenseArticle $article, ArticleRelease $release): bool
|
||||
{
|
||||
if ($release->license_article_id !== $article->id
|
||||
|| ! in_array($release->status, [ReleaseStatus::Veroeffentlicht, ReleaseStatus::AbgeloestVerfuegbar], true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Grant::query()
|
||||
->where('license_article_id', $article->id)
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->usableBy($user)
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Übungsfassung an einer Stelle des Stands. Der Pfad nennt die Positionen der Mitglieder von der Wurzel des
|
||||
* Stands abwärts („2“ oder „1-3“). So ist auch dieselbe Übung an zwei Stellen eines Produkts unterscheidbar.
|
||||
*
|
||||
* @return array{version: CompositionVersion, selection: list<string>|null}|null
|
||||
*/
|
||||
public function locate(ArticleRelease $release, string $path): ?array
|
||||
{
|
||||
if (preg_match('/^\d+(-\d+)*$/', $path) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $release->rootCompositionVersion;
|
||||
$selection = null;
|
||||
|
||||
foreach (array_map('intval', explode('-', $path)) as $position) {
|
||||
if ($version === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$member = $version->members()->where('position', $position)->first();
|
||||
|
||||
if ($member === null || $member->nested_composition_version_id === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$selection = is_array($member->variant_selection) ? array_values(array_map('strval', $member->variant_selection)) : null;
|
||||
$version = $member->nestedCompositionVersion;
|
||||
}
|
||||
|
||||
$version?->loadMissing('composition');
|
||||
|
||||
if ($version === null || $version->composition === null || $version->composition->kind !== CompositionKind::Exercise) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['version' => $version, 'selection' => $selection];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pfad zur ersten Stelle, an der die Wurzel die Übungsfassung einbindet.
|
||||
*/
|
||||
public function pathTo(CompositionVersion $root, int $versionId, array $stack = []): ?string
|
||||
{
|
||||
if (in_array($root->id, $stack, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($root->members()->orderBy('position')->get() as $member) {
|
||||
if ($member->nested_composition_version_id === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($member->nested_composition_version_id === $versionId) {
|
||||
return (string) $member->position;
|
||||
}
|
||||
|
||||
$below = $this->pathTo($member->nestedCompositionVersion, $versionId, [...$stack, $root->id]);
|
||||
|
||||
if ($below !== null) {
|
||||
return $member->position.'-'.$below;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string>|null $selection angebotene Variantenschlüssel; null = alle
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function build(User $user, LicenseArticle $article, ArticleRelease $release, CompositionVersion $exercise, ?array $selection, ?string $variantKey = null): array
|
||||
{
|
||||
$exercise->loadMissing(['composition', 'variants', 'members.variant', 'members.contentElementVersion.element']);
|
||||
$library = app(LibraryCatalog::class);
|
||||
$offered = $exercise->variants->filter(fn (CompositionVersionVariant $variant): bool => $selection === null || in_array($variant->key, $selection, true))->values();
|
||||
$chosen = $offered->firstWhere('key', $variantKey) ?? $offered->first();
|
||||
$entries = [];
|
||||
|
||||
foreach ($exercise->members as $member) {
|
||||
$version = $member->contentElementVersion;
|
||||
|
||||
if ($version === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $member->variant?->key;
|
||||
$class = (string) $version->element->output_class;
|
||||
$action = in_array($class, ['film', 'audio'], true) ? 'streamen' : 'ansehen';
|
||||
$decision = ($this->access)($user, $article, $release, $version, $action);
|
||||
$download = $action === 'ansehen' ? ($this->access)($user, $article, $release, $version, 'laden') : null;
|
||||
|
||||
$entries[] = [
|
||||
'variant' => $key,
|
||||
'role' => $member->role,
|
||||
'note' => $member->placement_note,
|
||||
'title' => $library->text($version->element)['title'] ?: $version->element->working_title,
|
||||
'class' => $class,
|
||||
'requirement' => $member->requirement ?: CompositionMember::REQUIRED,
|
||||
'action' => $action,
|
||||
'version' => $version,
|
||||
'allowed' => $decision->allowed,
|
||||
'may_download' => $download?->allowed ?? false,
|
||||
'grant' => $decision->grant,
|
||||
'download_grant' => $download?->grant,
|
||||
'state' => $decision->allowed ? 'ok' : ($version->status === ContentVersionStatus::Gesperrt ? 'gesperrt' : 'nicht_lizenziert'),
|
||||
'blocks' => $decision->allowed && $class === 'text' ? GuideText::blocks($version->body) : null,
|
||||
];
|
||||
}
|
||||
|
||||
$variants = $offered->map(function (CompositionVersionVariant $variant) use ($entries): array {
|
||||
$missing = array_values(array_filter($entries, fn (array $entry): bool => ($entry['variant'] === null || $entry['variant'] === $variant->key)
|
||||
&& $entry['requirement'] === CompositionMember::REQUIRED
|
||||
&& ! $entry['allowed']));
|
||||
|
||||
return [
|
||||
'key' => $variant->key,
|
||||
'name' => $variant->name,
|
||||
'description' => $variant->description,
|
||||
'complete' => $missing === [],
|
||||
'missing' => array_map(fn (array $entry): string => $entry['title'], $missing),
|
||||
];
|
||||
})->all();
|
||||
|
||||
$shown = array_values(array_filter($entries, fn (array $entry): bool => $entry['variant'] === null || $entry['variant'] === $chosen?->key));
|
||||
|
||||
return [
|
||||
'exercise' => $exercise,
|
||||
'title' => $library->text($exercise->composition)['title'],
|
||||
'summary' => $library->text($exercise->composition)['summary'],
|
||||
'learning_goal' => $exercise->learning_goal,
|
||||
'duration_minutes' => $exercise->duration_minutes,
|
||||
'duration_max' => $exercise->duration_max,
|
||||
'prerequisites' => $exercise->prerequisites,
|
||||
'material_note' => $exercise->material_note,
|
||||
'variants' => $variants,
|
||||
'chosen' => $chosen?->key,
|
||||
'entries' => $shown,
|
||||
'entry_total' => count($entries),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExerciseImportRun extends Model
|
||||
{
|
||||
protected $fillable = ['source_system', 'status', 'cursor', 'added', 'updated', 'removed', 'error', 'started_at', 'finished_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['started_at' => 'datetime', 'finished_at' => 'datetime'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||
use Transliterator;
|
||||
|
||||
/**
|
||||
* Druckbare Ausgabe einer Übung (DIN A4, mehrere Seiten) aus demselben Ergebnis wie die Ansicht ({@see ExerciseGuide}).
|
||||
* Kennzeichnung: Fußzeile mit Lizenznehmer und Lizenzkopie auf jeder Seite (K2) und die Kennung in den Metadaten (K1).
|
||||
* Das Dokument wird bei jedem Abruf neu erzeugt und nie abgelegt, damit eine spätere Sperre keine ältere Kopie
|
||||
* ausliefern kann.
|
||||
*/
|
||||
class ExercisePdf
|
||||
{
|
||||
private const LEFT = 56.0;
|
||||
|
||||
private const RIGHT = 539.0;
|
||||
|
||||
private const TOP = 790.0;
|
||||
|
||||
private const BOTTOM = 72.0;
|
||||
|
||||
private PdfDocument $pdf;
|
||||
|
||||
private float $y = self::TOP;
|
||||
|
||||
private int $page = 0;
|
||||
|
||||
private string $footer = '';
|
||||
|
||||
/**
|
||||
* Welche Abschnitte gehören ins PDF? Erforderliche Textabschnitte der Auswahl müssen für `laden` zulässig sein, sonst
|
||||
* ist das PDF nicht erlaubt (null). Ergänzende ohne Berechtigung entfallen. Videos und Dokumente erscheinen nur als
|
||||
* Hinweis.
|
||||
*
|
||||
* @param array<string, mixed> $guide Ergebnis von {@see ExerciseGuide::build}
|
||||
* @return list<array<string, mixed>>|null
|
||||
*/
|
||||
public function sections(array $guide): ?array
|
||||
{
|
||||
$included = [];
|
||||
|
||||
foreach ($guide['entries'] as $entry) {
|
||||
if ($entry['class'] === 'text') {
|
||||
if ($entry['may_download'] && $entry['allowed']) {
|
||||
$included[] = $entry;
|
||||
} elseif ($entry['requirement'] === CompositionMember::REQUIRED) {
|
||||
return null;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($entry['allowed']) {
|
||||
$included[] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter($included, fn (array $entry): bool => $entry['class'] === 'text') === [] ? null : $included;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $guide
|
||||
* @param list<array<string, mixed>> $sections
|
||||
*/
|
||||
public function render(array $guide, array $sections, string $licensee, string $copyId, string $variantName, string $guideUrl): string
|
||||
{
|
||||
$this->pdf = new PdfDocument;
|
||||
$this->page = 0;
|
||||
$this->footer = self::printable('Lizenziert für '.$licensee.' · Lizenzkopie '.$copyId);
|
||||
$this->newPage();
|
||||
|
||||
$this->write(self::printable((string) $guide['title']), 18, true, 8);
|
||||
|
||||
if ($variantName !== '') {
|
||||
$this->write(self::printable('Variante: '.$variantName), 11, true, 6);
|
||||
}
|
||||
|
||||
$facts = array_filter([
|
||||
filled($guide['learning_goal']) ? 'Lernziel: '.$guide['learning_goal'] : null,
|
||||
$guide['duration_minutes'] !== null ? 'Dauer: '.$guide['duration_minutes'].($guide['duration_max'] !== null ? ' bis '.$guide['duration_max'] : '').' Minuten' : null,
|
||||
filled($guide['prerequisites']) ? 'Voraussetzungen: '.$guide['prerequisites'] : null,
|
||||
filled($guide['material_note']) ? 'Ausstattung: '.$guide['material_note'] : null,
|
||||
]);
|
||||
|
||||
foreach ($facts as $fact) {
|
||||
$this->write(self::printable($fact), 10.5, false, 4);
|
||||
}
|
||||
|
||||
$this->y -= 6;
|
||||
|
||||
foreach ($sections as $section) {
|
||||
$this->section($section, $guideUrl);
|
||||
}
|
||||
|
||||
$this->closePage();
|
||||
|
||||
$ascii = Transliterator::create('Any-Latin; Latin-ASCII');
|
||||
|
||||
return $this->pdf->output($ascii?->transliterate((string) $guide['title']) ?: 'Uebung', 'Lizenzkopie '.$copyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeichen außerhalb von Windows-1252 werden, wo möglich, lesbar ersetzt (Pfeil, Ungleichheitszeichen, andere
|
||||
* lateinische Buchstaben); sonst bleibt „?“.
|
||||
*/
|
||||
public static function printable(string $text): string
|
||||
{
|
||||
$text = strtr($text, ['→' => '->', '←' => '<-', '≥' => '>=', '≤' => '<=', '✓' => '+', '✗' => 'x', '≠' => '!=', '≈' => '~']);
|
||||
$latin = Transliterator::create('Any-Latin; Latin-ASCII');
|
||||
$out = '';
|
||||
|
||||
foreach (mb_str_split($text) as $char) {
|
||||
$encoded = mb_convert_encoding($char, 'Windows-1252', 'UTF-8');
|
||||
$out .= $encoded === '?' && $char !== '?' ? ($latin?->transliterate($char) ?: '?') : $char;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $section
|
||||
*/
|
||||
private function section(array $section, string $guideUrl): void
|
||||
{
|
||||
$title = self::printable((string) $section['title']);
|
||||
|
||||
if ($section['class'] !== 'text') {
|
||||
$label = in_array($section['class'], ['film', 'audio'], true)
|
||||
? 'Film: '.$title.' - online abrufbar im Mitgliederbereich (geschützte Wiedergabe): '.$guideUrl
|
||||
: 'Material: '.$title.' - im Mitgliederbereich abrufbar: '.$guideUrl;
|
||||
$this->write(self::printable($label), 10, false, 6);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->write($title, 12.5, true, 5);
|
||||
|
||||
foreach ($section['blocks'] ?? [] as $block) {
|
||||
match ($block['type']) {
|
||||
'heading' => $this->write(self::printable($block['text']), 11, true, 4),
|
||||
'paragraph' => $this->write(self::printable($block['text']), 10.5, false, 5),
|
||||
'bullets' => $this->items($block['items'], fn (int $n): string => '•'),
|
||||
'numbered' => $this->items($block['items'], fn (int $n): string => $n.'.'),
|
||||
};
|
||||
}
|
||||
|
||||
$this->y -= 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $items
|
||||
*/
|
||||
private function items(array $items, callable $marker): void
|
||||
{
|
||||
foreach ($items as $index => $item) {
|
||||
$lines = PdfDocument::wrap(self::printable($item), self::RIGHT - self::LEFT - 18, 10.5);
|
||||
|
||||
foreach ($lines as $line => $text) {
|
||||
$this->room(14);
|
||||
|
||||
if ($line === 0) {
|
||||
$this->pdf->text(self::LEFT + 4, $this->y, $marker($index + 1), 10.5);
|
||||
}
|
||||
|
||||
$this->pdf->text(self::LEFT + 18, $this->y, $text, 10.5);
|
||||
$this->y -= 14;
|
||||
}
|
||||
}
|
||||
|
||||
$this->y -= 3;
|
||||
}
|
||||
|
||||
private function write(string $text, float $size, bool $bold, float $after): void
|
||||
{
|
||||
foreach (PdfDocument::wrap($text, self::RIGHT - self::LEFT, $size, $bold) as $line) {
|
||||
$this->room($size + 4);
|
||||
$this->pdf->text(self::LEFT, $this->y, $line, $size, $bold);
|
||||
$this->y -= $size + 4;
|
||||
}
|
||||
|
||||
$this->y -= $after;
|
||||
}
|
||||
|
||||
private function room(float $needed): void
|
||||
{
|
||||
if ($this->y - $needed < self::BOTTOM) {
|
||||
$this->closePage();
|
||||
$this->newPage();
|
||||
}
|
||||
}
|
||||
|
||||
private function newPage(): void
|
||||
{
|
||||
$this->pdf->addPage();
|
||||
$this->page++;
|
||||
$this->y = self::TOP;
|
||||
}
|
||||
|
||||
private function closePage(): void
|
||||
{
|
||||
$this->pdf->line(self::LEFT, 54, self::RIGHT, 54, 0.4);
|
||||
$this->pdf->text(self::LEFT, 40, $this->footer, 8);
|
||||
$this->pdf->textRight(self::RIGHT, 40, 'Seite '.$this->page, 8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* Eine Übung der Quelle, gebunden an ihre stabile Kennung. `availability` hält nur fest, ob die Quelle sie noch
|
||||
* bereitstellt. Das ist kein Rechtsvorgang: Eine rechtliche Sperre ist der lokale `block`.
|
||||
*/
|
||||
class ExerciseSource extends Model
|
||||
{
|
||||
public const PROVIDED = 'bereitgestellt';
|
||||
|
||||
public const WITHDRAWN = 'nicht_mehr_bereitgestellt';
|
||||
|
||||
protected $fillable = ['source_system', 'source_id', 'composition_id', 'title', 'availability', 'last_hash', 'last_seen_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['last_seen_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function composition(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Composition::class);
|
||||
}
|
||||
|
||||
public function snapshots(): HasMany
|
||||
{
|
||||
return $this->hasMany(ExerciseSourceSnapshot::class)->orderBy('id');
|
||||
}
|
||||
|
||||
public function latestSnapshot(): ?ExerciseSourceSnapshot
|
||||
{
|
||||
return $this->snapshots()->reorder()->orderByDesc('id')->first();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Ein abgerufener Inhaltsstand einer Quellübung (Prüfsumme der Quelle und ihre Nutzlast). Er ist unveränderlich;
|
||||
* nur die Übernahme trägt die daraus entstandene lokale Fassung ein.
|
||||
*/
|
||||
class ExerciseSourceSnapshot extends Model
|
||||
{
|
||||
protected $fillable = ['exercise_source_id', 'content_hash', 'payload', 'adopted_version_id', 'fetched_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['payload' => 'array', 'fetched_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function source(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ExerciseSource::class, 'exercise_source_id');
|
||||
}
|
||||
|
||||
public function adoptedVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CompositionVersion::class, 'adopted_version_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
/**
|
||||
* Verwendungsnachweis: Wo wird eine Übungsfassung tatsächlich verwendet, und was trifft eine Sperre? Der Nachweis steigt
|
||||
* über die Verschachtelung bis zu den Wurzeln der Artikel-Stände auf und erfasst damit auch ältere, abgelöste und
|
||||
* gesperrte Stände. Er liest nur und ändert keinen Stand.
|
||||
*/
|
||||
class ExerciseUsage
|
||||
{
|
||||
/**
|
||||
* Je Fassung der Komposition: die einbindenden Fassungen (mit Rolle, Position und Variantenauswahl) und die
|
||||
* Artikel-Stände, deren Wurzel die Fassung selbst oder eine einbindende Fassung ist.
|
||||
*
|
||||
* @return list<array{version: CompositionVersion, hosts: list<array<string, mixed>>, releases: list<array<string, mixed>>}>
|
||||
*/
|
||||
public function forComposition(Composition $composition): array
|
||||
{
|
||||
$guide = app(ExerciseGuide::class);
|
||||
$result = [];
|
||||
|
||||
foreach ($composition->versions()->orderBy('number')->get() as $version) {
|
||||
$hosts = [];
|
||||
$roots = [$version->id => $version];
|
||||
$queue = [$version->id];
|
||||
$seen = [$version->id];
|
||||
|
||||
while ($queue !== []) {
|
||||
$current = array_shift($queue);
|
||||
|
||||
foreach (CompositionMember::query()->where('nested_composition_version_id', $current)->with('compositionVersion.composition')->orderBy('id')->get() as $member) {
|
||||
$host = $member->compositionVersion;
|
||||
|
||||
if ($host === null || $host->composition === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hosts[] = [
|
||||
'composition' => $host->composition,
|
||||
'version' => $host,
|
||||
'role' => $member->role,
|
||||
'position' => $member->position,
|
||||
'selection' => $member->variant_selection,
|
||||
'direct' => $current === $version->id,
|
||||
];
|
||||
|
||||
if (! in_array($host->id, $seen, true)) {
|
||||
$seen[] = $host->id;
|
||||
$roots[$host->id] = $host;
|
||||
$queue[] = $host->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$releases = [];
|
||||
|
||||
foreach (ArticleRelease::query()->whereIn('root_composition_version_id', array_keys($roots))->with('article')->orderBy('license_article_id')->orderBy('number')->get() as $release) {
|
||||
$root = $roots[$release->root_composition_version_id];
|
||||
$releases[] = [
|
||||
'article' => $release->article,
|
||||
'release' => $release,
|
||||
'status' => $release->status,
|
||||
'path' => $root->id === $version->id ? null : $guide->pathTo($root, $version->id),
|
||||
'root' => $root,
|
||||
];
|
||||
}
|
||||
|
||||
$result[] = ['version' => $version, 'hosts' => $hosts, 'releases' => $releases];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Folgen einer Sperre dieser Medienfassung je Artikel-Stand. Die Festschreibung bleibt unverändert; gesperrt wird
|
||||
* nur die Ausgabe des Mediums.
|
||||
*
|
||||
* @return list<array{article: LicenseArticle, release: ArticleRelease, status: ReleaseStatus, variant: string|null, requirement: string|null, path: string, effect: string}>
|
||||
*/
|
||||
public function blockImpact(ContentElementVersion $version): array
|
||||
{
|
||||
$impact = [];
|
||||
|
||||
foreach (ReleaseContent::query()->where('content_element_version_id', $version->id)->with('release.article')->orderBy('id')->get() as $content) {
|
||||
$release = $content->release;
|
||||
$required = ($content->requirement ?? CompositionMember::REQUIRED) === CompositionMember::REQUIRED;
|
||||
$effect = match (true) {
|
||||
! $required => 'Nur dieses ergänzende Medium entfällt. Die Übung bleibt vollständig durchführbar.',
|
||||
$content->variant_key !== null => 'Die Variante „'.$content->variant_key.'“ ist nicht mehr vollständig durchführbar. Andere Varianten bleiben nutzbar.',
|
||||
default => 'Ein erforderlicher Bestandteil entfällt. Die Anleitung bleibt lesbar.',
|
||||
};
|
||||
$impact[] = [
|
||||
'article' => $release->article,
|
||||
'release' => $release,
|
||||
'status' => $release->status,
|
||||
'variant' => $content->variant_key,
|
||||
'requirement' => $content->requirement,
|
||||
'path' => $content->path,
|
||||
'effect' => $effect,
|
||||
];
|
||||
}
|
||||
|
||||
return $impact;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Erkennt Kompositionen, deren Art dieser Programmstand nicht kennt (siehe {@see SupportedKindScope}), und Aufbauten, die
|
||||
* solche Bestandteile enthalten. Gelesen wird am Modell vorbei, weil der Bereichsfilter diese Zeilen ausblendet.
|
||||
*
|
||||
* Wozu: Eine ältere Programmversion darf eine Fassung mit unbekanntem Bestandteil weder neu veröffentlichen noch
|
||||
* überarbeiten. Sie würde den Bestandteil auslassen oder ohne seine Variantenwahl auflösen und damit Inhalt verlieren
|
||||
* oder zu viel ausgeben.
|
||||
*/
|
||||
class ForeignCompositions
|
||||
{
|
||||
public function isForeignVersion(int $compositionVersionId): bool
|
||||
{
|
||||
return DB::table('composition_versions as v')
|
||||
->join('compositions as c', 'c.id', '=', 'v.composition_id')
|
||||
->where('v.id', $compositionVersionId)
|
||||
->whereNotIn('c.kind', CompositionKind::values())
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $target „composition:ID“ (Fassung) oder „composition-draft:ID“ (Komposition)
|
||||
*/
|
||||
public function isForeignTarget(string $target): bool
|
||||
{
|
||||
if (preg_match('/^composition:(\d+)$/', $target, $match) === 1) {
|
||||
return $this->isForeignVersion((int) $match[1]);
|
||||
}
|
||||
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $match) === 1) {
|
||||
return DB::table('compositions')
|
||||
->where('id', (int) $match[1])
|
||||
->whereNotIn('kind', CompositionKind::values())
|
||||
->exists();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ist die Fassung selbst unbekannt oder erreicht sie, auch verschachtelt, einen unbekannten Bestandteil?
|
||||
*/
|
||||
public function reaches(ContentElementVersion|CompositionVersion $node): bool
|
||||
{
|
||||
return $node instanceof CompositionVersion && $this->reachesVersion($node->id, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enthält irgendeine Fassung dieser Komposition einen unbekannten Bestandteil?
|
||||
*/
|
||||
public function compositionHasForeignMembers(int $compositionId): bool
|
||||
{
|
||||
return DB::table('composition_members as m')
|
||||
->join('composition_versions as host', 'host.id', '=', 'm.composition_version_id')
|
||||
->join('composition_versions as nested', 'nested.id', '=', 'm.nested_composition_version_id')
|
||||
->join('compositions as c', 'c.id', '=', 'nested.composition_id')
|
||||
->where('host.composition_id', $compositionId)
|
||||
->whereNotIn('c.kind', CompositionKind::values())
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $seen
|
||||
*/
|
||||
private function reachesVersion(int $versionId, array $seen): bool
|
||||
{
|
||||
if (in_array($versionId, $seen, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isForeignVersion($versionId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$seen[] = $versionId;
|
||||
|
||||
foreach (DB::table('composition_members')
|
||||
->where('composition_version_id', $versionId)
|
||||
->whereNotNull('nested_composition_version_id')
|
||||
->pluck('nested_composition_version_id') as $nestedId) {
|
||||
if ($this->reachesVersion((int) $nestedId, $seen)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
/**
|
||||
* Anleitungstext als Klartext mit wenigen Konventionen: Absätze an Leerzeilen, Listen mit „- “ oder „• “ und
|
||||
* nummerierte Listen mit „1. “, Zwischenüberschriften mit „## “. Ansicht und PDF lesen dieselben Blöcke und zeigen damit
|
||||
* dieselbe Fassung. Es gibt kein freies HTML.
|
||||
*/
|
||||
final class GuideText
|
||||
{
|
||||
/**
|
||||
* @return list<array{type: 'paragraph'|'bullets'|'numbered'|'heading', text?: string, items?: list<string>}>
|
||||
*/
|
||||
public static function blocks(?string $body): array
|
||||
{
|
||||
$blocks = [];
|
||||
$paragraph = [];
|
||||
$list = null;
|
||||
|
||||
$flushParagraph = function () use (&$blocks, &$paragraph): void {
|
||||
if ($paragraph !== []) {
|
||||
$blocks[] = ['type' => 'paragraph', 'text' => implode(' ', $paragraph)];
|
||||
$paragraph = [];
|
||||
}
|
||||
};
|
||||
$flushList = function () use (&$blocks, &$list): void {
|
||||
if ($list !== null) {
|
||||
$blocks[] = ['type' => $list['type'], 'items' => $list['items']];
|
||||
$list = null;
|
||||
}
|
||||
};
|
||||
|
||||
foreach (preg_split('/\R/u', trim((string) $body)) ?: [] as $line) {
|
||||
$line = rtrim($line);
|
||||
|
||||
if (trim($line) === '') {
|
||||
$flushParagraph();
|
||||
$flushList();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^##\s+(.+)$/u', $line, $match) === 1) {
|
||||
$flushParagraph();
|
||||
$flushList();
|
||||
$blocks[] = ['type' => 'heading', 'text' => trim($match[1])];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*(?:[-•*])\s+(.+)$/u', $line, $match) === 1) {
|
||||
$flushParagraph();
|
||||
if ($list === null || $list['type'] !== 'bullets') {
|
||||
$flushList();
|
||||
$list = ['type' => 'bullets', 'items' => []];
|
||||
}
|
||||
|
||||
$list['items'][] = trim($match[1]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*\d+[.)]\s+(.+)$/u', $line, $match) === 1) {
|
||||
$flushParagraph();
|
||||
if ($list === null || $list['type'] !== 'numbered') {
|
||||
$flushList();
|
||||
$list = ['type' => 'numbered', 'items' => []];
|
||||
}
|
||||
|
||||
$list['items'][] = trim($match[1]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$flushList();
|
||||
$paragraph[] = trim($line);
|
||||
}
|
||||
|
||||
$flushParagraph();
|
||||
$flushList();
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,27 @@ class OfferCoverage
|
||||
{
|
||||
public function __construct(private readonly ContentResolver $resolver) {}
|
||||
|
||||
/**
|
||||
* Bestandteile der Fassung, deren Medienfassung gesperrt ist. Ein Angebot soll nicht aktiviert werden, solange sein
|
||||
* Umfang gesperrte Bestandteile enthält; die Prüfung nennt sie vorab.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function blockedLeaves(CompositionVersion $version): array
|
||||
{
|
||||
$rows = $this->resolver->expand($version);
|
||||
$blocked = ContentElementVersion::query()
|
||||
->whereIn('id', array_column($rows, 'version_id'))
|
||||
->where('status', ContentVersionStatus::Gesperrt->value)
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
return array_values(array_map(
|
||||
fn (array $row): string => $row['path'],
|
||||
array_filter($rows, fn (array $row): bool => in_array($row['version_id'], $blocked, true)),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<LicenseArticle> $articles
|
||||
* @return list<string>
|
||||
|
||||
@@ -277,6 +277,10 @@ private function assertCoverage(array $lines, array $attributes): void
|
||||
}
|
||||
|
||||
$version = CompositionVersion::query()->findOrFail($versionId);
|
||||
|
||||
if (app(ForeignCompositions::class)->reaches($version)) {
|
||||
throw new DomainRuleException('Der Aufbau enthält einen Bestandteil, den dieser Programmstand nicht kennt. Das Angebot wird hier nicht aktiviert.');
|
||||
}
|
||||
$articles = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
@@ -285,6 +289,12 @@ private function assertCoverage(array $lines, array $attributes): void
|
||||
}
|
||||
}
|
||||
|
||||
$blocked = app(OfferCoverage::class)->blockedLeaves($version);
|
||||
|
||||
if ($blocked !== []) {
|
||||
throw new DomainRuleException('Das Angebot enthält gesperrte Bestandteile: '.implode(', ', $blocked));
|
||||
}
|
||||
|
||||
$missing = app(OfferCoverage::class)->missingLeaves($version, $articles);
|
||||
|
||||
if ($missing !== []) {
|
||||
|
||||
@@ -13,6 +13,8 @@ class ReleaseContent extends Model
|
||||
'content_element_version_id',
|
||||
'role',
|
||||
'path',
|
||||
'requirement',
|
||||
'variant_key',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Übernahme von Übungen aus dem Shinkan-Katalog (`GET /api/distribution/v1/catalog` und Detailroute) in denselben
|
||||
* Übungsbestand wie die lokalen Übungen.
|
||||
*
|
||||
* Grundsätze:
|
||||
* - Die Quellübung ist an ihre stabile Kennung gebunden. Jeder Inhaltsstand (Prüfsumme der Quelle) wird genau einmal
|
||||
* festgehalten; ein wiederholter Abruf erzeugt nichts Neues.
|
||||
* - Eine lokale Fassung entsteht nur durch die bewusste Übernahme ({@see adopt}) und ist danach unveränderlich. Lokale
|
||||
* Ergänzungen (Herkunft „lokal“) bleiben bei einer neuen Quellfassung erhalten.
|
||||
* - Das Ausblenden an der Quelle setzt nur die Verfügbarkeit. Lokale Fassungen und Verwendungen bleiben unberührt; eine
|
||||
* rechtliche Sperre ist der lokale `block`.
|
||||
* - Medien des Katalogs sind Metadaten ohne Datei. Sie begründen weder eine Ausgabe noch eine Nutzungsberechtigung und
|
||||
* stehen nie in einem Artikel-Stand.
|
||||
* - Ein fehlgeschlagener Abruf verändert den gespeicherten Stand nicht und rückt den Cursor nicht vor.
|
||||
*/
|
||||
class ShinkanImport
|
||||
{
|
||||
/** Abschnitte der Quelle in Lesereihenfolge: Feld => [Bezeichnung, Rolle]. */
|
||||
private const SECTIONS = [
|
||||
'preparation' => 'Vorbereitung',
|
||||
'execution' => 'Durchführung',
|
||||
'trainer_notes' => 'Trainerhinweise',
|
||||
];
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return filled(config('services.shinkan.url')) && filled(config('services.shinkan.key'));
|
||||
}
|
||||
|
||||
public function fetch(): ExerciseImportRun
|
||||
{
|
||||
$run = ExerciseImportRun::query()->create(['status' => 'laeuft', 'started_at' => now()]);
|
||||
|
||||
if (! $this->configured()) {
|
||||
return $this->finish($run, 'fehler', error: 'Die Anbindung ist nicht eingerichtet. Adresse und Schlüssel fehlen in der Umgebung.');
|
||||
}
|
||||
|
||||
$previous = ExerciseImportRun::query()->where('status', 'ok')->orderByDesc('id')->value('cursor');
|
||||
$counts = ['added' => 0, 'updated' => 0, 'removed' => 0];
|
||||
|
||||
try {
|
||||
try {
|
||||
$catalog = $this->get('/catalog', $previous === null ? [] : ['cursor' => $previous]);
|
||||
} catch (RequestException $exception) {
|
||||
// Ein ungültiger Cursor heißt nur: ganz neu abgleichen.
|
||||
if ($previous === null || $exception->response->status() !== 400) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$catalog = $this->get('/catalog');
|
||||
}
|
||||
|
||||
foreach ((array) ($catalog['changes'] ?? []) as $change) {
|
||||
$id = (string) ($change['source_id'] ?? '');
|
||||
$kind = (string) ($change['change'] ?? '');
|
||||
|
||||
if ($id === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($kind === 'removed') {
|
||||
ExerciseSource::query()->where('source_system', 'shinkan')->where('source_id', $id)
|
||||
->update(['availability' => ExerciseSource::WITHDRAWN]);
|
||||
$counts['removed']++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$document = $this->get('/catalog/'.$id);
|
||||
$this->record($document);
|
||||
$counts[$kind === 'added' ? 'added' : 'updated']++;
|
||||
}
|
||||
|
||||
foreach ((array) ($catalog['exercises'] ?? []) as $listed) {
|
||||
ExerciseSource::query()->where('source_system', 'shinkan')->where('source_id', (string) ($listed['source_id'] ?? ''))
|
||||
->update(['availability' => ExerciseSource::PROVIDED, 'last_seen_at' => now()]);
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
return $this->finish($run, 'fehler', $counts, 'Der Abruf ist fehlgeschlagen: '.$this->plain($exception).' Der gespeicherte Stand blieb unverändert.');
|
||||
}
|
||||
|
||||
return $this->finish($run, 'ok', $counts, null, (string) ($catalog['next_cursor'] ?? $previous));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hält einen abgerufenen Inhaltsstand fest. Derselbe Stand (Quelle und Prüfsumme) wird nie doppelt gespeichert.
|
||||
*
|
||||
* @param array<string, mixed> $document Detail der Quelle mit `source_id`, `content_hash` und den Feldern
|
||||
*/
|
||||
public function record(array $document): ExerciseSourceSnapshot
|
||||
{
|
||||
$id = (string) ($document['source_id'] ?? '');
|
||||
$hash = (string) ($document['content_hash'] ?? '');
|
||||
|
||||
if ($id === '' || $hash === '') {
|
||||
throw new DomainRuleException('Der Abruf liefert keine Quellkennung oder Prüfsumme.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($id, $hash, $document): ExerciseSourceSnapshot {
|
||||
$source = ExerciseSource::query()->firstOrCreate(
|
||||
['source_system' => 'shinkan', 'source_id' => $id],
|
||||
['title' => (string) ($document['title'] ?? '')],
|
||||
);
|
||||
$source->update([
|
||||
'title' => (string) ($document['title'] ?? $source->title),
|
||||
'availability' => ExerciseSource::PROVIDED,
|
||||
'last_hash' => $hash,
|
||||
'last_seen_at' => now(),
|
||||
]);
|
||||
|
||||
return $source->snapshots()->firstOrCreate(
|
||||
['content_hash' => $hash],
|
||||
['payload' => $document, 'fetched_at' => now()],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Zustand einer Quellübung für die Redaktion.
|
||||
*/
|
||||
public function state(ExerciseSource $source): string
|
||||
{
|
||||
$latest = $source->latestSnapshot();
|
||||
|
||||
return match (true) {
|
||||
$source->availability === ExerciseSource::WITHDRAWN => 'nicht_mehr_bereitgestellt',
|
||||
$latest === null => 'neu',
|
||||
$latest->adopted_version_id !== null => 'uebernommen',
|
||||
$source->composition_id !== null => 'geaendert',
|
||||
default => 'neu',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Die bewusste Übernahme: aus dem Inhaltsstand wird eine neue, unveränderliche lokale Fassung. Wiederholt man sie,
|
||||
* entsteht keine zweite Fassung. Lokale Ergänzungen der bisherigen Fassung werden übernommen.
|
||||
*/
|
||||
public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null): CompositionVersion
|
||||
{
|
||||
$snapshot->refresh();
|
||||
|
||||
if ($snapshot->adopted_version_id !== null) {
|
||||
return $snapshot->adoptedVersion;
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($snapshot, $actor): CompositionVersion {
|
||||
$source = $snapshot->source;
|
||||
$document = $snapshot->payload;
|
||||
$content = app(ContentService::class);
|
||||
$title = trim((string) ($document['title'] ?? '')) ?: 'Übung aus Shinkan';
|
||||
$composition = $source->composition ?? $this->createComposition($title, (string) ($document['summary'] ?? ''));
|
||||
$previous = $composition->versions()->orderByDesc('number')->with('members.variant', 'variants')->first();
|
||||
|
||||
$variants = [];
|
||||
$members = [];
|
||||
|
||||
foreach (self::SECTIONS as $field => $label) {
|
||||
$text = trim((string) ($document[$field] ?? ''));
|
||||
|
||||
if ($text !== '') {
|
||||
$members[] = [
|
||||
'role' => $label,
|
||||
'target' => $this->section($source, $field, $title.' · '.$label, $text),
|
||||
'origin' => 'quelle',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) ($document['variants'] ?? []) as $variant) {
|
||||
$key = (string) ($variant['id'] ?? '');
|
||||
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$variants[] = [
|
||||
'key' => $key,
|
||||
'name' => (string) ($variant['name'] ?? '') ?: 'Variante',
|
||||
'description' => (string) ($variant['description'] ?? ''),
|
||||
'origin' => 'quelle',
|
||||
];
|
||||
$changes = trim((string) ($variant['execution_changes'] ?? ''));
|
||||
|
||||
if ($changes !== '') {
|
||||
$members[] = [
|
||||
'role' => 'Abweichung der Durchführung',
|
||||
'target' => $this->section($source, 'variant:'.$key, $title.' · '.($variant['name'] ?? 'Variante').' · Abweichung', $changes),
|
||||
'variant' => $key,
|
||||
'origin' => 'quelle',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
[$localMembers, $localVariants] = $this->localAdditions($previous, array_column($variants, 'key'));
|
||||
$version = $content->publishComposition(
|
||||
$composition,
|
||||
[...$members, ...$localMembers],
|
||||
$actor,
|
||||
'Übernahme aus Shinkan',
|
||||
[
|
||||
'learning_goal' => $document['goal'] ?? null,
|
||||
'duration_minutes' => $document['duration_min'] ?? null,
|
||||
'duration_max' => $document['duration_max'] ?? null,
|
||||
'material_note' => $document['equipment'] ?? null,
|
||||
'source_snapshot_id' => $snapshot->id,
|
||||
],
|
||||
[...$variants, ...$localVariants],
|
||||
);
|
||||
|
||||
$snapshot->update(['adopted_version_id' => $version->id]);
|
||||
$source->update(['composition_id' => $composition->id]);
|
||||
|
||||
return $version;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Was die Redaktion lokal ergänzt hat, bleibt bei einer neuen Quellfassung erhalten. Eine lokale Zuordnung zu einer
|
||||
* Quellvariante, die es nicht mehr gibt, wandert in den gemeinsamen Teil, damit nichts verloren geht.
|
||||
*
|
||||
* @param list<string> $sourceVariantKeys
|
||||
* @return array{0: list<array<string, mixed>>, 1: list<array<string, mixed>>}
|
||||
*/
|
||||
private function localAdditions(?CompositionVersion $previous, array $sourceVariantKeys): array
|
||||
{
|
||||
if ($previous === null) {
|
||||
return [[], []];
|
||||
}
|
||||
|
||||
$localVariants = $previous->variants->where('origin', 'lokal')->map(fn (CompositionVersionVariant $variant): array => [
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => $variant->description, 'origin' => 'lokal',
|
||||
])->values()->all();
|
||||
$known = [...$sourceVariantKeys, ...array_column($localVariants, 'key')];
|
||||
$members = [];
|
||||
|
||||
foreach ($previous->members->where('origin', 'lokal') as $member) {
|
||||
$variant = $member->variant?->key;
|
||||
$members[] = [
|
||||
'role' => $member->role,
|
||||
'note' => $member->placement_note,
|
||||
'target' => $member->content_element_version_id !== null ? $member->contentElementVersion : $member->nestedCompositionVersion,
|
||||
'variant' => $variant !== null && in_array($variant, $known, true) ? $variant : null,
|
||||
'requirement' => $member->requirement,
|
||||
'selection' => $member->variant_selection,
|
||||
'origin' => 'lokal',
|
||||
];
|
||||
}
|
||||
|
||||
return [$members, $localVariants];
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Textfassung eines Abschnitts der Quelle. Unveränderter Text bleibt dieselbe Fassung.
|
||||
*/
|
||||
private function section(ExerciseSource $source, string $field, string $title, string $text): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$ref = 'shinkan:'.$source->source_id.':'.$field;
|
||||
$element = ContentElement::query()->where('source_ref', $ref)->first();
|
||||
|
||||
if ($element === null) {
|
||||
$element = $content->createElement('text', 'text', $title);
|
||||
$element->source_ref = $ref;
|
||||
$element->save();
|
||||
}
|
||||
|
||||
$latest = $element->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->first();
|
||||
|
||||
return $latest !== null && trim((string) $latest->body) === $text
|
||||
? $latest
|
||||
: $content->publishElementVersion($element, $text, [], 'Übernahme aus Shinkan');
|
||||
}
|
||||
|
||||
private function createComposition(string $title, string $summary): Composition
|
||||
{
|
||||
$composition = app(ContentService::class)->createComposition($title, CompositionKind::Exercise);
|
||||
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'uebung')->value('id');
|
||||
|
||||
if ($summary !== '') {
|
||||
$composition->summary = $summary;
|
||||
}
|
||||
|
||||
$composition->save();
|
||||
|
||||
return $composition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $query
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function get(string $path, array $query = []): array
|
||||
{
|
||||
$response = Http::withToken((string) config('services.shinkan.key'))
|
||||
->acceptJson()
|
||||
->timeout(20)
|
||||
->get(rtrim((string) config('services.shinkan.url'), '/').'/api/distribution/v1'.$path, $query)
|
||||
->throw();
|
||||
|
||||
$json = $response->json();
|
||||
|
||||
if (! is_array($json)) {
|
||||
throw new DomainRuleException('Die Antwort der Quelle ist kein gültiges JSON.');
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{added?: int, updated?: int, removed?: int} $counts
|
||||
*/
|
||||
private function finish(ExerciseImportRun $run, string $status, array $counts = [], ?string $error = null, ?string $cursor = null): ExerciseImportRun
|
||||
{
|
||||
$run->update([
|
||||
'status' => $status,
|
||||
'cursor' => $cursor,
|
||||
'added' => $counts['added'] ?? 0,
|
||||
'updated' => $counts['updated'] ?? 0,
|
||||
'removed' => $counts['removed'] ?? 0,
|
||||
'error' => $error,
|
||||
'finished_at' => now(),
|
||||
]);
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
/** Fehlertext ohne Adresse und Schlüssel. */
|
||||
private function plain(Throwable $exception): string
|
||||
{
|
||||
if ($exception instanceof RequestException) {
|
||||
return 'Die Quelle antwortete mit Status '.$exception->response->status().'.';
|
||||
}
|
||||
|
||||
return $exception instanceof DomainRuleException ? $exception->getMessage() : 'Die Quelle ist nicht erreichbar.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
/**
|
||||
* Rückfallschutz: Dieser Code kennt nur die Kompositionsarten aus {@see CompositionKind}. Eine Komposition mit einem
|
||||
* Wert, den erst eine neuere Programmversion einführt, gilt hier als nicht vorhanden. Sie wird weder geladen (der
|
||||
* Enum-Zugriff würde sonst abstürzen) noch angezeigt, bearbeitet oder veröffentlicht. Eine neuere Programmversion
|
||||
* kennt den Wert und sieht die Zeile wieder.
|
||||
*/
|
||||
class SupportedKindScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$builder->whereIn($model->qualifyColumn('kind'), CompositionKind::values());
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public static function width(string $text, float $size = 10, bool $bold = false)
|
||||
/**
|
||||
* @param string $title Nur ASCII (Dokumenttitel)
|
||||
*/
|
||||
public function output(string $title): string
|
||||
public function output(string $title, ?string $keywords = null): string
|
||||
{
|
||||
$pages = $this->pages === [] ? [''] : $this->pages;
|
||||
$objects = [];
|
||||
@@ -125,7 +125,8 @@ public function output(string $title): string
|
||||
$objects[2] = '<< /Type /Pages /Kids ['.implode(' ', $kids).'] /Count '.count($pages).' >>';
|
||||
$objects[3] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>';
|
||||
$objects[4] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>';
|
||||
$objects[5] = '<< /Title ('.preg_replace('/[^\x20-\x7E]/', '?', str_replace(['\\', '(', ')'], ['', '', ''], $title)).') /Producer (Lara und Felix) >>';
|
||||
$ascii = fn (string $value): string => (string) preg_replace('/[^\x20-\x7E]/', '?', str_replace(['\\', '(', ')'], ['', '', ''], $value));
|
||||
$objects[5] = '<< /Title ('.$ascii($title).')'.($keywords === null ? '' : ' /Keywords ('.$ascii($keywords).')').' /Producer (Lara und Felix) >>';
|
||||
ksort($objects);
|
||||
|
||||
$pdf = "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n";
|
||||
|
||||
@@ -16,6 +16,7 @@ class MediaDelivery extends Model
|
||||
'copy_id',
|
||||
'checksum',
|
||||
'marking',
|
||||
'composition_version_id',
|
||||
'delivered_at',
|
||||
];
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ public function write(
|
||||
string $format,
|
||||
?string $checksum,
|
||||
string $marking,
|
||||
?string $copyId = null,
|
||||
?int $compositionVersionId = null,
|
||||
): MediaDelivery {
|
||||
return MediaDelivery::query()->create([
|
||||
'grant_id' => $grant->id,
|
||||
@@ -27,10 +29,16 @@ public function write(
|
||||
'content_element_version_id' => $version->id,
|
||||
'action' => $action,
|
||||
'format' => $format,
|
||||
'copy_id' => 'LK-'.strtoupper(bin2hex(random_bytes(6))),
|
||||
'copy_id' => $copyId ?? self::newCopyId(),
|
||||
'composition_version_id' => $compositionVersionId,
|
||||
'checksum' => $checksum,
|
||||
'marking' => $marking,
|
||||
'delivered_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function newCopyId(): string
|
||||
{
|
||||
return 'LK-'.strtoupper(bin2hex(random_bytes(6)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\ExerciseImportRun;
|
||||
use App\Domain\Catalog\ExerciseSource;
|
||||
use App\Domain\Catalog\ExerciseSourceSnapshot;
|
||||
use App\Domain\Catalog\ShinkanImport;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
/**
|
||||
* Übernahme aus Shinkan: Welche Übungen stellt die Quelle bereit, was ist neu oder geändert, was ist übernommen und was
|
||||
* stellt die Quelle nicht mehr bereit? Abrufen verändert nur den Quellenstand; erst „Übernehmen“ legt eine lokale
|
||||
* Fassung an, und erst eine Produktveröffentlichung setzt sie ein.
|
||||
*/
|
||||
class Uebernahme extends Page
|
||||
{
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Übernahme (Shinkan)';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static ?string $slug = 'uebernahme';
|
||||
|
||||
protected static ?string $title = 'Übernahme aus Shinkan';
|
||||
|
||||
protected string $view = 'filament.pages.uebernahme';
|
||||
|
||||
public string $feedback = '';
|
||||
|
||||
public bool $feedbackError = false;
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return ContentElementResource::editor();
|
||||
}
|
||||
|
||||
public function getHeading(): string|Htmlable|null
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getMaxContentWidth(): Width|string|null
|
||||
{
|
||||
return Width::Full;
|
||||
}
|
||||
|
||||
public function fetch(): void
|
||||
{
|
||||
abort_unless(static::canAccess(), 403);
|
||||
|
||||
$run = app(ShinkanImport::class)->fetch();
|
||||
$this->feedbackError = $run->status !== 'ok';
|
||||
$this->feedback = $run->status === 'ok'
|
||||
? 'Abruf abgeschlossen: '.$run->added.' neu, '.$run->updated.' geändert, '.$run->removed.' nicht mehr bereitgestellt. Es wurde noch keine lokale Fassung angelegt.'
|
||||
: (string) $run->error;
|
||||
}
|
||||
|
||||
public function adopt(int $snapshotId): void
|
||||
{
|
||||
abort_unless(static::canAccess(), 403);
|
||||
|
||||
try {
|
||||
$user = Filament::auth()->user();
|
||||
$version = app(ShinkanImport::class)->adopt(ExerciseSourceSnapshot::query()->findOrFail($snapshotId), $user instanceof User ? $user : null);
|
||||
$this->feedbackError = false;
|
||||
$this->feedback = 'Fassung '.$version->number.' ist lokal angelegt und unveränderlich. Produkte verwenden sie erst, wenn du sie dort bewusst einsetzt und das Produkt veröffentlichst.';
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedbackError = true;
|
||||
$this->feedback = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function daten(): array
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$labels = [
|
||||
'neu' => ['Neu bei der Quelle', 'offen'],
|
||||
'geaendert' => ['Neue Quellfassung zur Übernahme', 'offen'],
|
||||
'uebernommen' => ['Übernommen', 'gut'],
|
||||
'nicht_mehr_bereitgestellt' => ['An der Quelle nicht mehr bereitgestellt', 'leise'],
|
||||
];
|
||||
$rows = [];
|
||||
|
||||
foreach (ExerciseSource::query()->with('composition')->orderBy('title')->get() as $source) {
|
||||
$state = $import->state($source);
|
||||
$latest = $source->latestSnapshot();
|
||||
$payload = $latest?->payload ?? [];
|
||||
$rows[] = [
|
||||
'titel' => $source->title ?: $source->source_id,
|
||||
'zustand' => $labels[$state][0],
|
||||
'ton' => $labels[$state][1],
|
||||
'snapshot' => $latest !== null && $latest->adopted_version_id === null ? $latest->id : null,
|
||||
'lokal' => $source->composition === null ? null : PracticeResource::getUrl('edit', ['record' => $source->composition]),
|
||||
'varianten' => count($payload['variants'] ?? []),
|
||||
'quellmedien' => array_map(fn (array $media): string => ($media['title'] ?? '').' ('.($media['media_type'] ?? '').')', (array) ($payload['media'] ?? [])),
|
||||
'hinweis' => $state === 'nicht_mehr_bereitgestellt'
|
||||
? 'Lokale Fassungen und Verwendungen bleiben unverändert. Eine rechtliche Sperre ist ein eigener Vorgang am Medium.'
|
||||
: null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'zeilen' => $rows,
|
||||
'eingerichtet' => app(ShinkanImport::class)->configured(),
|
||||
'letzterLauf' => ExerciseImportRun::query()->orderByDesc('id')->first(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||
use App\Domain\Catalog\ForeignCompositions;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -39,6 +40,7 @@
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
@@ -68,6 +70,15 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public string $materialNote = '';
|
||||
|
||||
/** @var list<array{key: string, name: string, description: string}> Durchführungsvarianten einer Übung */
|
||||
public array $variants = [];
|
||||
|
||||
public string $durationMax = '';
|
||||
|
||||
public string $prerequisites = '';
|
||||
|
||||
public string $newVariantName = '';
|
||||
|
||||
public string $revisionNote = '';
|
||||
|
||||
public string $search = '';
|
||||
@@ -489,8 +500,173 @@ public function cancelText(): void
|
||||
$this->newTextBody = '';
|
||||
}
|
||||
|
||||
public function isExercise(): bool
|
||||
{
|
||||
return $this->hostKind() === CompositionKind::Exercise;
|
||||
}
|
||||
|
||||
public function addVariant(): void
|
||||
{
|
||||
$name = trim($this->newVariantName);
|
||||
|
||||
if ($name === '') {
|
||||
$this->feedback = 'Eine Variante braucht einen Namen.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$base = Str::slug($name) ?: 'variante';
|
||||
$key = $base;
|
||||
$n = 2;
|
||||
|
||||
while (in_array($key, array_column($this->variants, 'key'), true)) {
|
||||
$key = $base.'-'.$n++;
|
||||
}
|
||||
|
||||
$this->variants[] = ['key' => $key, 'name' => $name, 'description' => '', 'origin' => 'lokal'];
|
||||
$this->newVariantName = '';
|
||||
$this->feedback = 'Variante „'.$name.'“ ist angelegt. Ordne ihr Bestandteile zu. Gespeichert wird mit „Entwurf speichern“.';
|
||||
}
|
||||
|
||||
public function removeVariant(string $key): void
|
||||
{
|
||||
foreach ($this->members as $member) {
|
||||
if (($member['variant'] ?? null) === $key) {
|
||||
$this->feedback = 'Diese Variante hat noch Bestandteile. Ordne sie zuerst einer anderen Variante oder dem gemeinsamen Teil zu.';
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->variants = array_values(array_filter($this->variants, fn (array $variant): bool => $variant['key'] !== $key));
|
||||
$this->feedback = 'Die Variante ist aus diesem Entwurf genommen. Eine freigegebene Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
public function setMemberVariant(int $index, string $key): void
|
||||
{
|
||||
if (! isset($this->members[$index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->members[$index]['variant'] = $key === '' ? null : $key;
|
||||
}
|
||||
|
||||
public function setMemberRequirement(int $index, string $requirement): void
|
||||
{
|
||||
if (! isset($this->members[$index]) || ! in_array($requirement, ['erforderlich', 'ergaenzend'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->members[$index]['requirement'] = $requirement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Angebotene Varianten der eingebundenen Übungsfassung. Ohne Auswahl werden alle angeboten.
|
||||
*/
|
||||
public function toggleVariantSelection(int $index, string $key): void
|
||||
{
|
||||
if (! isset($this->members[$index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$all = array_column($this->offeredVariants((string) ($this->members[$index]['target'] ?? '')), 'key');
|
||||
$current = $this->members[$index]['selection'] ?? null;
|
||||
$current = is_array($current) ? $current : $all;
|
||||
$current = in_array($key, $current, true) ? array_values(array_diff($current, [$key])) : [...$current, $key];
|
||||
|
||||
if ($current === []) {
|
||||
$this->feedback = 'Mindestens eine Variante muss angeboten werden.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->members[$index]['selection'] = count($current) === count($all) ? null : array_values($current);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, name: string}>
|
||||
*/
|
||||
public function offeredVariants(string $target): array
|
||||
{
|
||||
if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return CompositionVersion::query()->find((int) $match[1])?->variants
|
||||
->map(fn ($variant): array => ['key' => $variant->key, 'name' => $variant->name])
|
||||
->all() ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $member
|
||||
* @return array{variant: string|null, requirement: string, selection: list<string>|null, origin: string}
|
||||
*/
|
||||
private function memberExtras(array $member): array
|
||||
{
|
||||
$selection = $member['selection'] ?? null;
|
||||
|
||||
return [
|
||||
'variant' => isset($member['variant']) && $member['variant'] !== '' ? (string) $member['variant'] : null,
|
||||
'requirement' => ($member['requirement'] ?? 'erforderlich') === 'ergaenzend' ? 'ergaenzend' : 'erforderlich',
|
||||
'selection' => is_array($selection) && $selection !== [] ? array_values(array_map('strval', $selection)) : null,
|
||||
'origin' => ($member['origin'] ?? 'lokal') === 'quelle' ? 'quelle' : 'lokal',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, name: string, description: string}>
|
||||
*/
|
||||
private function normalizeVariants(mixed $variants): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach (is_array($variants) ? $variants : [] as $variant) {
|
||||
if (is_array($variant) && trim((string) ($variant['key'] ?? '')) !== '') {
|
||||
$result[] = [
|
||||
'key' => trim((string) $variant['key']),
|
||||
'name' => trim((string) ($variant['name'] ?? '')),
|
||||
'description' => trim((string) ($variant['description'] ?? '')),
|
||||
'origin' => ($variant['origin'] ?? 'lokal') === 'quelle' ? 'quelle' : 'lokal',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rückfallschutz: Enthält dieser Aufbau (in einer Fassung oder im Entwurf) einen Bestandteil, den dieser Programmstand
|
||||
* nicht kennt, bleibt er schreibgeschützt. Der Editor könnte den Bestandteil sonst nicht laden und würde ihn beim
|
||||
* Speichern oder Freigeben still weglassen.
|
||||
*/
|
||||
public function schreibschutz(): ?string
|
||||
{
|
||||
$foreign = app(ForeignCompositions::class);
|
||||
$reason = 'Dieser Aufbau enthält einen Bestandteil aus einer neueren Programmversion. Er kann hier nur angesehen werden, damit nichts verloren geht.';
|
||||
|
||||
if ($foreign->compositionHasForeignMembers((int) $this->getRecord()->getKey())) {
|
||||
return $reason;
|
||||
}
|
||||
|
||||
$draft = app(EditorialWorkingDraft::class)->read($this->getRecord());
|
||||
|
||||
foreach (is_array($draft['members'] ?? null) ? $draft['members'] : [] as $member) {
|
||||
if (is_array($member) && $foreign->isForeignTarget((string) ($member['target'] ?? ''))) {
|
||||
return $reason;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function saveDraft(): void
|
||||
{
|
||||
if (($reason = $this->schreibschutz()) !== null) {
|
||||
$this->feedback = $reason;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
$minutes = $this->minutes($this->durationMinutes);
|
||||
|
||||
@@ -508,6 +684,13 @@ public function saveDraft(): void
|
||||
|
||||
public function armRelease(): void
|
||||
{
|
||||
if (($reason = $this->schreibschutz()) !== null) {
|
||||
$this->releaseArmed = false;
|
||||
$this->feedback = $reason;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
|
||||
if ($this->members === []) {
|
||||
@@ -585,6 +768,12 @@ protected function selectFirstPart(): void
|
||||
|
||||
public function discardDraft(): void
|
||||
{
|
||||
if (($reason = $this->schreibschutz()) !== null) {
|
||||
$this->feedback = $reason;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Composition $record */
|
||||
$record = $this->getRecord();
|
||||
app(EditorialWorkingDraft::class)->clear($record);
|
||||
@@ -924,7 +1113,7 @@ private function includePart(string $target, bool $allowDraft): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->members as $index => $member) {
|
||||
foreach ($this->isExercise() ? [] : $this->members as $index => $member) {
|
||||
if (($member['target'] ?? '') === $target) {
|
||||
$this->selected = $index;
|
||||
$this->panel = 'bestandteil';
|
||||
@@ -944,6 +1133,7 @@ private function includePart(string $target, bool $allowDraft): bool
|
||||
|
||||
$row['role'] = app(EditorialCatalog::class)->defaultRole((string) $row['kind']);
|
||||
$row['note'] = '';
|
||||
$row = [...$row, ...$this->memberExtras([])];
|
||||
$this->members[] = $row;
|
||||
$this->members = array_values($this->members);
|
||||
$this->selected = array_key_last($this->members);
|
||||
@@ -1034,6 +1224,7 @@ public function useVersion(int $index, string $target): void
|
||||
$this->commitRoleDraft();
|
||||
$row['role'] = $this->members[$index]['role'] ?? $row['kind'];
|
||||
$row['note'] = $this->members[$index]['note'] ?? '';
|
||||
$row = [...$row, ...$this->memberExtras($this->members[$index])];
|
||||
$this->members[$index] = $row;
|
||||
$this->syncRoleDraft();
|
||||
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Der Entwurf speichert das. Eine freigegebene Fassung bleibt unverändert.';
|
||||
@@ -1521,6 +1712,12 @@ public function presentationChips(): array
|
||||
|
||||
public function publishRevision(): bool
|
||||
{
|
||||
if (($reason = $this->schreibschutz()) !== null) {
|
||||
$this->feedback = $reason;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
|
||||
if ($this->members === []) {
|
||||
@@ -1560,9 +1757,12 @@ public function publishRevision(): bool
|
||||
[
|
||||
'learning_goal' => $this->blank($this->learningGoal),
|
||||
'duration_minutes' => $minutes,
|
||||
'duration_max' => $this->blank($this->durationMax),
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
'prerequisites' => $this->blank($this->prerequisites),
|
||||
],
|
||||
$this->releaseConsent,
|
||||
$this->normalizeVariants($this->variants),
|
||||
);
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedback = $exception->getMessage();
|
||||
@@ -1679,7 +1879,8 @@ protected function loadAufbau(): void
|
||||
$this->imageCaptionText = $this->captionFor($composition->thumbnail_source);
|
||||
$this->catalogScope = match ($this->hostKind()) {
|
||||
CompositionKind::Kurs => 'module',
|
||||
CompositionKind::Uebung => 'medien',
|
||||
CompositionKind::Uebung => 'uebungen',
|
||||
CompositionKind::Exercise => 'medien',
|
||||
default => 'alles',
|
||||
};
|
||||
|
||||
@@ -1693,6 +1894,9 @@ protected function loadAufbau(): void
|
||||
|
||||
if ($version === null) {
|
||||
$this->members = [];
|
||||
$this->variants = [];
|
||||
$this->durationMax = '';
|
||||
$this->prerequisites = '';
|
||||
$this->learningGoal = '';
|
||||
$this->durationMinutes = '';
|
||||
$this->materialNote = '';
|
||||
@@ -1726,10 +1930,14 @@ protected function applyDraft(array $draft): void
|
||||
|
||||
$row['role'] = (string) ($member['role'] ?? $row['kind']);
|
||||
$row['note'] = trim((string) ($member['note'] ?? ''));
|
||||
$row = [...$row, ...$this->memberExtras($member)];
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$this->members = $rows;
|
||||
$this->variants = $this->normalizeVariants($draft['variants'] ?? []);
|
||||
$this->durationMax = ($draft['duration_max'] ?? null) === null ? '' : (string) $draft['duration_max'];
|
||||
$this->prerequisites = (string) ($draft['prerequisites'] ?? '');
|
||||
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
|
||||
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
|
||||
$this->materialNote = (string) ($draft['material_note'] ?? '');
|
||||
@@ -1747,6 +1955,11 @@ protected function applyDraft(array $draft): void
|
||||
protected function applyVersion(CompositionVersion $version): void
|
||||
{
|
||||
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
|
||||
$this->variants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description,
|
||||
])->all());
|
||||
$this->durationMax = $version->duration_max === null ? '' : (string) $version->duration_max;
|
||||
$this->prerequisites = (string) ($version->prerequisites ?? '');
|
||||
$this->learningGoal = (string) ($version->learning_goal ?? '');
|
||||
$this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes;
|
||||
$this->materialNote = (string) ($version->material_note ?? '');
|
||||
@@ -1833,18 +2046,21 @@ protected function needsRevision(): bool
|
||||
|
||||
protected function sameMembers(CompositionVersion $version): bool
|
||||
{
|
||||
$version->loadMissing('members');
|
||||
$version->loadMissing('members.variant');
|
||||
$current = $version->members->map(function ($member): string {
|
||||
$target = $member->content_element_version_id
|
||||
? 'element:'.$member->content_element_version_id
|
||||
: 'composition:'.$member->nested_composition_version_id;
|
||||
|
||||
return $member->role.'|'.$target.'|'.trim((string) ($member->placement_note ?? ''));
|
||||
return $member->role.'|'.$target.'|'.trim((string) ($member->placement_note ?? ''))
|
||||
.'|'.($member->variant?->key ?? '').'|'.($member->requirement ?: 'erforderlich').'|'.json_encode($member->variant_selection);
|
||||
})->all();
|
||||
$next = array_values(array_map(
|
||||
fn (array $member): string => trim((string) ($member['role'] ?? '')).'|'.($member['target'] ?? '').'|'.trim((string) ($member['note'] ?? '')),
|
||||
$this->members,
|
||||
));
|
||||
$next = array_values(array_map(function (array $member): string {
|
||||
$extras = $this->memberExtras($member);
|
||||
|
||||
return trim((string) ($member['role'] ?? '')).'|'.($member['target'] ?? '').'|'.trim((string) ($member['note'] ?? ''))
|
||||
.'|'.($extras['variant'] ?? '').'|'.$extras['requirement'].'|'.json_encode($extras['selection']);
|
||||
}, $this->members));
|
||||
|
||||
return $current === $next;
|
||||
}
|
||||
@@ -1859,8 +2075,15 @@ protected function didacticChanged(CompositionVersion $version): bool
|
||||
|
||||
$storedMinutes = $version->duration_minutes === null ? null : (int) $version->duration_minutes;
|
||||
|
||||
$storedVariants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description,
|
||||
])->all());
|
||||
|
||||
return $version->learning_goal !== $this->blank($this->learningGoal)
|
||||
|| $version->material_note !== $this->blank($this->materialNote)
|
||||
|| $version->prerequisites !== $this->blank($this->prerequisites)
|
||||
|| ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax)
|
||||
|| $storedVariants !== $this->normalizeVariants($this->variants)
|
||||
|| $storedMinutes !== $minutes;
|
||||
}
|
||||
|
||||
@@ -1929,6 +2152,12 @@ protected function persistRedaktion(): bool
|
||||
|
||||
protected function persistDraft(): bool
|
||||
{
|
||||
if (($reason = $this->schreibschutz()) !== null) {
|
||||
$this->feedback = $reason;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->minutes($this->durationMinutes) === false) {
|
||||
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
|
||||
|
||||
@@ -2065,12 +2294,16 @@ protected function payload(): array
|
||||
'learning_goal' => $this->blank($this->learningGoal),
|
||||
'duration_minutes' => $minutes === false ? $this->durationMinutes : $minutes,
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
'duration_max' => $this->blank($this->durationMax),
|
||||
'prerequisites' => $this->blank($this->prerequisites),
|
||||
'variants' => $this->normalizeVariants($this->variants),
|
||||
'revision_note' => $this->blank($this->revisionNote),
|
||||
'members' => array_values(array_map(
|
||||
fn (array $member): array => [
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'target' => (string) ($member['target'] ?? ''),
|
||||
'note' => trim((string) ($member['note'] ?? '')),
|
||||
...$this->memberExtras($member),
|
||||
],
|
||||
$members,
|
||||
)),
|
||||
@@ -2105,6 +2338,9 @@ protected function readyPayload(): array
|
||||
'learning_goal' => null,
|
||||
'duration_minutes' => null,
|
||||
'material_note' => null,
|
||||
'duration_max' => null,
|
||||
'prerequisites' => null,
|
||||
'variants' => [],
|
||||
'revision_note' => null,
|
||||
'members' => [],
|
||||
];
|
||||
@@ -2116,12 +2352,18 @@ protected function readyPayload(): array
|
||||
'learning_goal' => $version->learning_goal,
|
||||
'duration_minutes' => $version->duration_minutes === null ? null : (int) $version->duration_minutes,
|
||||
'material_note' => $version->material_note,
|
||||
'duration_max' => $version->duration_max === null ? null : (string) $version->duration_max,
|
||||
'prerequisites' => $version->prerequisites,
|
||||
'variants' => $this->normalizeVariants($version->variants->map(fn ($variant): array => [
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||
])->all()),
|
||||
'revision_note' => null,
|
||||
'members' => array_values(array_map(
|
||||
fn (array $row): array => [
|
||||
'role' => trim((string) ($row['role'] ?? '')),
|
||||
'target' => (string) ($row['target'] ?? ''),
|
||||
'note' => trim((string) ($row['note'] ?? '')),
|
||||
...$this->memberExtras($row),
|
||||
],
|
||||
$rows,
|
||||
)),
|
||||
@@ -2145,6 +2387,7 @@ protected function normalizePayload(array $payload): array
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'target' => (string) ($member['target'] ?? ''),
|
||||
'note' => trim((string) ($member['note'] ?? '')),
|
||||
...$this->memberExtras($member),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2152,6 +2395,9 @@ protected function normalizePayload(array $payload): array
|
||||
'learning_goal' => $payload['learning_goal'] ?? null,
|
||||
'duration_minutes' => $payload['duration_minutes'] ?? null,
|
||||
'material_note' => $payload['material_note'] ?? null,
|
||||
'duration_max' => isset($payload['duration_max']) && $payload['duration_max'] !== '' ? (string) $payload['duration_max'] : null,
|
||||
'prerequisites' => $payload['prerequisites'] ?? null,
|
||||
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
|
||||
'revision_note' => $payload['revision_note'] ?? null,
|
||||
'members' => $members,
|
||||
];
|
||||
|
||||
@@ -33,12 +33,12 @@ protected function fixedKind(): ?CompositionKind
|
||||
|
||||
private function onDesk(): bool
|
||||
{
|
||||
return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true);
|
||||
return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung, CompositionKind::Exercise], true);
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
$desk = $this->onDesk() ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
|
||||
$desk = $this->onDesk() && $this->kind() !== CompositionKind::Exercise ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
|
||||
|
||||
return $this->kind()->deskExplanation().$desk;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Practices\Pages;
|
||||
|
||||
use App\Filament\Resources\Compositions\Pages\EditComposition;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
|
||||
class EditPractice extends EditComposition
|
||||
{
|
||||
protected static string $resource = PracticeResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Practices\Pages;
|
||||
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Filament\Resources\Compositions\Pages\ListCompositionKind;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
|
||||
class ListPractices extends ListCompositionKind
|
||||
{
|
||||
protected static string $resource = PracticeResource::class;
|
||||
|
||||
protected function kind(): CompositionKind
|
||||
{
|
||||
return CompositionKind::Exercise;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Practices;
|
||||
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Filament\Resources\Compositions\CompositionKindResource;
|
||||
use App\Filament\Resources\Practices\Pages\EditPractice;
|
||||
use App\Filament\Resources\Practices\Pages\ListPractices;
|
||||
|
||||
/**
|
||||
* Die fachliche Übung. Der ältere Eintrag „Module“ (`ExerciseResource`, Adresse `uebungen`) bleibt unverändert und
|
||||
* zeigt die Zusammenstellungen der Art `uebung`; hier stehen die Übungen mit Varianten.
|
||||
*/
|
||||
class PracticeResource extends CompositionKindResource
|
||||
{
|
||||
protected static ?string $slug = 'fachuebungen';
|
||||
|
||||
protected static ?string $navigationLabel = 'Übungen';
|
||||
|
||||
protected static ?string $modelLabel = 'Übung';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Übungen';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function kind(): CompositionKind
|
||||
{
|
||||
return CompositionKind::Exercise;
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPractices::route('/'),
|
||||
'edit' => EditPractice::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public static function assignmentTargets(?int $exceptCompositionId = null): arra
|
||||
$media['element:'.$version->id] = self::elementLabel($version);
|
||||
}
|
||||
|
||||
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
||||
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->whereHas('composition')->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
||||
if ($exceptCompositionId !== null && (int) $version->composition_id === $exceptCompositionId) {
|
||||
continue;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public static function readyTargets(): array
|
||||
$options['element:'.$version->id] = self::elementLabel($version);
|
||||
}
|
||||
|
||||
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
||||
foreach (CompositionVersion::query()->where('status', ContentVersionStatus::Bereit)->whereHas('composition')->with('composition.editorialContentKind')->orderBy('id')->get() as $version) {
|
||||
$options['composition:'.$version->id] = self::compositionLabel($version);
|
||||
}
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ public function elementUsage(ContentElement $element): array
|
||||
->get();
|
||||
|
||||
foreach ($members as $member) {
|
||||
$lines[] = self::compositionLabel($member->compositionVersion->composition)
|
||||
$lines[] = self::compositionLabelOf($member->compositionVersion->composition)
|
||||
.' · Fassung '.$member->compositionVersion->number
|
||||
.' · Rolle '.$member->role;
|
||||
}
|
||||
@@ -280,7 +280,9 @@ public function elementUsage(ContentElement $element): array
|
||||
foreach ($contents as $content) {
|
||||
$lines[] = 'Lizenzartikel '.$content->release->article->code
|
||||
.' · Stand '.$content->release->number
|
||||
.' · '.$content->path;
|
||||
.' · '.$content->path
|
||||
.($content->variant_key !== null ? ' · Variante '.$content->variant_key : '')
|
||||
.($content->requirement === CompositionMember::SUPPLEMENTARY ? ' · ergänzend' : '');
|
||||
}
|
||||
|
||||
return $lines === []
|
||||
@@ -313,7 +315,7 @@ public function compositionMembers(Composition $composition): array
|
||||
}
|
||||
|
||||
$nested = $member->nestedCompositionVersion;
|
||||
$lines[] = $member->role.' — '.($nested === null ? 'fehlt' : self::compositionLabel($nested->composition));
|
||||
$lines[] = $member->role.' — '.($nested === null ? 'fehlt' : self::compositionLabelOf($nested->composition));
|
||||
}
|
||||
|
||||
return $lines;
|
||||
@@ -365,7 +367,7 @@ public function compositionUsage(Composition $composition): array
|
||||
->get();
|
||||
|
||||
foreach ($parents as $member) {
|
||||
$lines[] = self::compositionLabel($member->compositionVersion->composition)
|
||||
$lines[] = self::compositionLabelOf($member->compositionVersion->composition)
|
||||
.' · Fassung '.$member->compositionVersion->number
|
||||
.' · Rolle '.$member->role;
|
||||
}
|
||||
@@ -448,6 +450,16 @@ private function purpose(string $purpose): string
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Zusammenstellung, die dieser Programmstand nicht kennt, erscheint nur als Hinweis ohne Namen und Inhalt.
|
||||
*/
|
||||
private static function compositionLabelOf(?Composition $composition): string
|
||||
{
|
||||
return $composition === null
|
||||
? 'Zusammenstellung einer neueren Programmversion'
|
||||
: self::compositionLabel($composition);
|
||||
}
|
||||
|
||||
private static function compositionLabel(Composition $composition): string
|
||||
{
|
||||
$kind = $composition->kind;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -33,6 +34,7 @@ class EditorialCatalog
|
||||
public function rows(CompositionVersion $version, int $exceptCompositionId): array
|
||||
{
|
||||
$version->loadMissing([
|
||||
'members.variant',
|
||||
'members.contentElementVersion.element.editorialContentKind',
|
||||
'members.nestedCompositionVersion.composition.editorialContentKind',
|
||||
]);
|
||||
@@ -50,6 +52,10 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
|
||||
|
||||
$row['role'] = $member->role;
|
||||
$row['note'] = trim((string) ($member->placement_note ?? ''));
|
||||
$row['variant'] = $member->variant?->key;
|
||||
$row['requirement'] = $member->requirement ?: 'erforderlich';
|
||||
$row['selection'] = is_array($member->variant_selection) ? $member->variant_selection : null;
|
||||
$row['origin'] = $member->origin ?: 'lokal';
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
@@ -140,6 +146,12 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
}
|
||||
|
||||
$composition = $version->composition;
|
||||
|
||||
// Art, die dieser Programmstand nicht kennt: nicht anbieten und nicht laden (Rückfallschutz).
|
||||
if ($composition === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$kind = $composition->editorialContentKind?->label
|
||||
?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung');
|
||||
|
||||
@@ -238,7 +250,11 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
->with('composition.editorialContentKind')
|
||||
->whereHas('composition', function ($builder) use ($scope, $query, $like): void {
|
||||
if ($scope === 'module') {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
$builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]);
|
||||
}
|
||||
|
||||
if ($scope === 'uebungen') {
|
||||
$builder->where('kind', CompositionKind::Exercise);
|
||||
}
|
||||
|
||||
if ($query === '') {
|
||||
@@ -311,7 +327,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
->where('composition_id', '!=', $exceptCompositionId)
|
||||
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void {
|
||||
if ($kind === 'modul') {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
$builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]);
|
||||
}
|
||||
|
||||
if ($dimensionId > 0) {
|
||||
@@ -357,7 +373,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$builder->where('status', ContentVersionStatus::Bereit);
|
||||
})
|
||||
->when($kind === 'modul', function ($builder): void {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
$builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
@@ -1028,6 +1044,10 @@ private function suggestPicture(array $members, array $seen = []): ?array
|
||||
|
||||
$nested = $version->composition;
|
||||
|
||||
if ($nested === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->cardUrl('komposition', $nested->id, $nested->thumbnail_path) !== null) {
|
||||
return [
|
||||
'kind' => 'komposition',
|
||||
@@ -1063,6 +1083,7 @@ public function create(string $designation, CompositionKind $kind): Composition
|
||||
$slug = match ($kind) {
|
||||
CompositionKind::Kurs => 'programm',
|
||||
CompositionKind::Uebung => 'modul',
|
||||
CompositionKind::Exercise => 'uebung',
|
||||
default => null,
|
||||
};
|
||||
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
|
||||
@@ -1084,6 +1105,7 @@ public static function editUrl(Composition $composition): string
|
||||
CompositionKind::Kurs => CourseResource::class,
|
||||
CompositionKind::Kombination => CombinationResource::class,
|
||||
CompositionKind::Uebung => ExerciseResource::class,
|
||||
CompositionKind::Exercise => PracticeResource::class,
|
||||
};
|
||||
|
||||
return $resource::getUrl('edit', ['record' => $composition]);
|
||||
|
||||
@@ -74,6 +74,7 @@ public function bestand(): array
|
||||
$einheit = match ($fixed) {
|
||||
CompositionKind::Kurs => ['Programm', 'Programme'],
|
||||
CompositionKind::Uebung => ['Modul', 'Module'],
|
||||
CompositionKind::Exercise => ['Übung', 'Übungen'],
|
||||
CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'],
|
||||
default => ['Programm oder Modul', 'Programme und Module'],
|
||||
};
|
||||
@@ -188,7 +189,7 @@ public function entries(): array
|
||||
$rows[] = [
|
||||
'schluessel' => 'c'.$composition->id,
|
||||
'titel' => $title,
|
||||
'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : ''),
|
||||
'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : '').($kind === CompositionKind::Exercise ? ' · Herkunft: lokal' : ''),
|
||||
'text' => $summary,
|
||||
'bild' => $cover['url'],
|
||||
'bildFehlt' => 'Kein Titelbild',
|
||||
@@ -219,11 +220,19 @@ public function entries(): array
|
||||
*/
|
||||
protected function createCompositionAction(CompositionKind $kind): Action
|
||||
{
|
||||
$label = $kind === CompositionKind::Kurs ? 'Programm' : 'Modul';
|
||||
$label = match ($kind) {
|
||||
CompositionKind::Kurs => 'Programm',
|
||||
CompositionKind::Exercise => 'Übung',
|
||||
default => 'Modul',
|
||||
};
|
||||
|
||||
return Action::make($kind === CompositionKind::Kurs ? 'createProgram' : 'createModule')
|
||||
return Action::make(match ($kind) {
|
||||
CompositionKind::Kurs => 'createProgram',
|
||||
CompositionKind::Exercise => 'createExercise',
|
||||
default => 'createModule',
|
||||
})
|
||||
->label($label.' anlegen')
|
||||
->modalHeading('Neues '.$label)
|
||||
->modalHeading(($kind === CompositionKind::Exercise ? 'Neue ' : 'Neues ').$label)
|
||||
->modalDescription('Der Name genügt. Danach öffnet sich der Aufbau; Texte, Bilder und Einordnung folgen dort und in der Redaktion.')
|
||||
->modalSubmitActionLabel($label.' anlegen')
|
||||
->modalWidth('lg')
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
@@ -501,8 +502,10 @@ private function maySeeThumbnail(Request $request, string $kind, int $subject):
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ein gesperrtes Medium zeigt auch kein Vorschaubild mehr (Sperre gilt für Ausgaben und Ableitungen).
|
||||
if ($kind === 'element' && $release->contents->contains(
|
||||
fn ($content): bool => $content->elementVersion?->content_element_id === $subject,
|
||||
fn ($content): bool => $content->elementVersion?->content_element_id === $subject
|
||||
&& $content->elementVersion->status !== ContentVersionStatus::Gesperrt,
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Catalog\ExerciseGuide;
|
||||
use App\Domain\Catalog\ReleaseStatus;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
@@ -389,7 +391,7 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI
|
||||
'view_url' => $view,
|
||||
'poster_url' => $poster,
|
||||
'download_url' => $download,
|
||||
'program_url' => $this->programUrl($node),
|
||||
'program_url' => $this->exerciseUrl($user, $rootId, $node) ?? $this->programUrl($node),
|
||||
'composition_id' => $node->compositionId,
|
||||
'element_id' => $node->contentElementId,
|
||||
'version_id' => $node->contentElementVersionId,
|
||||
@@ -491,6 +493,46 @@ private function element(int $id): ?ContentElement
|
||||
return $this->elements[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Übung im Zusammenhang des erworbenen Moduls oder Programms: die im Stand gebundene Fassung und ihre Varianten,
|
||||
* nicht die jeweils neueste Fassung der Übung. Gefunden wird der jüngste auslieferbare Stand des Kontos, dessen
|
||||
* festgeschriebene Wurzel diese Fassung an einer Stelle einbindet.
|
||||
*/
|
||||
private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?string
|
||||
{
|
||||
if ($node->compositionVersionId === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nested = CompositionVersion::query()->with('composition')->find($node->compositionVersionId);
|
||||
|
||||
if ($nested?->composition?->kind !== CompositionKind::Exercise) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$guide = app(ExerciseGuide::class);
|
||||
|
||||
foreach ($this->grants($user) as $grant) {
|
||||
$releases = ArticleRelease::query()
|
||||
->where('license_article_id', $grant->license_article_id)
|
||||
->whereIn('status', [ReleaseStatus::Veroeffentlicht, ReleaseStatus::AbgeloestVerfuegbar])
|
||||
->whereHas('rootCompositionVersion', fn ($query) => $query->where('composition_id', $rootId))
|
||||
->with('rootCompositionVersion')
|
||||
->orderByDesc('number')
|
||||
->get();
|
||||
|
||||
foreach ($releases as $release) {
|
||||
$path = $guide->pathTo($release->rootCompositionVersion, $nested->id);
|
||||
|
||||
if ($path !== null) {
|
||||
return route('member.exercise', ['article' => $grant->license_article_id, 'release' => $release->id, 'path' => $path]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function programUrl(StructureNode $node): ?string
|
||||
{
|
||||
if ($node->compositionId === null || $node->compositionVersionId === null) {
|
||||
|
||||
@@ -42,6 +42,12 @@
|
||||
'api_base' => env('STRIPE_API_BASE', 'https://api.stripe.com'),
|
||||
],
|
||||
|
||||
// Übernahme von Übungen aus dem Shinkan-Katalog. Adresse und Schlüssel stehen nur in der Umgebungsdatei des Servers.
|
||||
'shinkan' => [
|
||||
'url' => env('SHINKAN_DISTRIBUTION_URL'),
|
||||
'key' => env('SHINKAN_DISTRIBUTION_KEY'),
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'notifications' => [
|
||||
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Übungsverwaltung, rein additiv. Alle neuen Spalten sind nullable oder haben einen Vorgabewert. Der Rückfall auf den
|
||||
* vorherigen Programmstand setzt nur den Code zurück: Dieser kennt die Spalten nicht, liest Übungen wegen des
|
||||
* Bereichsfilters am Modell (SupportedKindScope) nicht und verweigert das Veröffentlichen von Aufbauten mit Übungen.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('composition_versions', function (Blueprint $table) {
|
||||
$table->unsignedInteger('duration_max')->nullable();
|
||||
$table->text('prerequisites')->nullable();
|
||||
// Änderungsnachweis über Felder, Varianten und Verwendungen; resolved_hash deckt nur die Medienmenge ab.
|
||||
$table->string('structure_hash')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('compatibility_attestations', function (Blueprint $table) {
|
||||
$table->string('structure_hash')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('composition_version_variants', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('composition_version_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('key');
|
||||
$table->unsignedInteger('position');
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['composition_version_id', 'key']);
|
||||
$table->unique(['composition_version_id', 'position']);
|
||||
});
|
||||
|
||||
Schema::table('composition_members', function (Blueprint $table) {
|
||||
$table->foreignId('variant_id')->nullable()->constrained('composition_version_variants')->restrictOnDelete();
|
||||
$table->string('requirement')->default('erforderlich');
|
||||
$table->json('variant_selection')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('release_contents', function (Blueprint $table) {
|
||||
$table->string('requirement')->nullable();
|
||||
$table->string('variant_key')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('media_deliveries', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('composition_version_id')->nullable();
|
||||
});
|
||||
|
||||
$now = now();
|
||||
DB::table('editorial_content_kinds')->insertOrIgnore([
|
||||
'slug' => 'uebung',
|
||||
'label' => 'Übung',
|
||||
'sort_order' => 25,
|
||||
'is_active' => true,
|
||||
'contexts' => json_encode(['uebung', 'lizenzartikel']),
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('editorial_content_kinds')->where('slug', 'uebung')->delete();
|
||||
|
||||
Schema::table('media_deliveries', function (Blueprint $table) {
|
||||
$table->dropColumn('composition_version_id');
|
||||
});
|
||||
Schema::table('release_contents', function (Blueprint $table) {
|
||||
$table->dropColumn(['requirement', 'variant_key']);
|
||||
});
|
||||
Schema::table('composition_members', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('variant_id');
|
||||
$table->dropColumn(['requirement', 'variant_selection']);
|
||||
});
|
||||
Schema::dropIfExists('composition_version_variants');
|
||||
Schema::table('compatibility_attestations', function (Blueprint $table) {
|
||||
$table->dropColumn('structure_hash');
|
||||
});
|
||||
Schema::table('composition_versions', function (Blueprint $table) {
|
||||
$table->dropColumn(['duration_max', 'prerequisites', 'structure_hash']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Übernahme aus einer Quelle (Shinkan), rein additiv. Die Quelle ist an ihre stabile Kennung gebunden; jeder Inhaltsstand
|
||||
* (Prüfsumme) wird genau einmal festgehalten. Eine lokale Fassung entsteht erst mit der bewussten Übernahme.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('exercise_sources', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('source_system')->default('shinkan');
|
||||
$table->string('source_id');
|
||||
$table->foreignId('composition_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('title')->nullable();
|
||||
// bereitgestellt | nicht_mehr_bereitgestellt: nur die Verfügbarkeit an der Quelle, kein Rechtsvorgang.
|
||||
$table->string('availability')->default('bereitgestellt');
|
||||
$table->string('last_hash')->nullable();
|
||||
$table->timestamp('last_seen_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['source_system', 'source_id']);
|
||||
});
|
||||
|
||||
Schema::create('exercise_source_snapshots', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('exercise_source_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('content_hash');
|
||||
$table->json('payload');
|
||||
$table->unsignedBigInteger('adopted_version_id')->nullable();
|
||||
$table->timestamp('fetched_at');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['exercise_source_id', 'content_hash']);
|
||||
});
|
||||
|
||||
Schema::create('exercise_import_runs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('source_system')->default('shinkan');
|
||||
$table->string('status');
|
||||
$table->string('cursor')->nullable();
|
||||
$table->unsignedInteger('added')->default(0);
|
||||
$table->unsignedInteger('updated')->default(0);
|
||||
$table->unsignedInteger('removed')->default(0);
|
||||
$table->text('error')->nullable();
|
||||
$table->timestamp('started_at');
|
||||
$table->timestamp('finished_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->string('source_ref')->nullable()->index();
|
||||
});
|
||||
|
||||
Schema::table('composition_versions', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('source_snapshot_id')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('composition_members', function (Blueprint $table) {
|
||||
// quelle | lokal: Was stammt aus der Quelle, was hat die Redaktion lokal ergänzt?
|
||||
$table->string('origin')->default('lokal');
|
||||
});
|
||||
|
||||
Schema::table('composition_version_variants', function (Blueprint $table) {
|
||||
$table->string('origin')->default('lokal');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('composition_version_variants', function (Blueprint $table) {
|
||||
$table->dropColumn('origin');
|
||||
});
|
||||
Schema::table('composition_members', function (Blueprint $table) {
|
||||
$table->dropColumn('origin');
|
||||
});
|
||||
Schema::table('composition_versions', function (Blueprint $table) {
|
||||
$table->dropColumn('source_snapshot_id');
|
||||
});
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->dropColumn('source_ref');
|
||||
});
|
||||
Schema::dropIfExists('exercise_import_runs');
|
||||
Schema::dropIfExists('exercise_source_snapshots');
|
||||
Schema::dropIfExists('exercise_sources');
|
||||
}
|
||||
};
|
||||
@@ -173,6 +173,7 @@ ## 6. Rückzug (VER-007, SC-19)
|
||||
|
||||
- **Rückzug eines Artikel-Stands:** Status „zurückgezogen“; die Entscheidung lehnt jede Aktion auf diesem Stand ab.
|
||||
- **Sperre einer Inhaltsfassung:** Alle Stände, deren fixierter Inhalt (`RELEASE_CONTENT`) sie enthält, werden in derselben Transaktion zurückgezogen – gleichgültig, ob die Fassung direktes Mitglied ist oder über verschachtelte Kompositionen hineinkommt, und gleichgültig, ob der Stand aktuell oder abgelöst ist. Das ist der Weg für „dieses eine Video ist gefährlich“, auch wenn es in mehreren Artikeln und Altfassungen steckt. Zusätzlich lehnt die Entscheidung jede Aktion auf einer gesperrten Inhaltsfassung unmittelbar ab (`05`, Abschnitt 4, Schritt 0); die Sperre wirkt also auch dann, wenn ein Stand übersehen würde.
|
||||
**Abweichung seit ADR-49 (23.11.2026) für Medien innerhalb einer Übung:** Die Sperre einer Medienfassung verweigert deren Ausgabe in jedem Stand (Player, Direktabruf, Vorschau, Ableitungen), zieht aber **nicht** die Stände zurück. Anleitung und übrige berechtigte Inhalte bleiben im selben Stand erreichbar; die Festschreibung bleibt unverändert. Ein ausdrücklicher Rückzug eines Stands oder einer Übungsfassung bleibt ein eigener Vorgang. Der Auswirkungsbericht nennt die betroffenen Stände, Varianten und Verwendungen.
|
||||
- **Rückfall:** Der Betreiber wählt je Artikel einen früheren, weiterhin vertretbaren Stand als Ersatz oder keinen. Ohne Ersatz zeigt die Bibliothek den Artikel mit einem Hinweis; Berechtigungen bleiben bestehen.
|
||||
- **Betroffene:** (a) Inhaber aktiver Berechtigungen mit Zugriff auf den Stand, (b) Konten mit Ausgabenachweis für Dateien aus diesem Stand. Gruppe (b) ist die wichtigere, weil heruntergeladene Kopien nicht zurückgeholt werden können.
|
||||
- **Historie:** Stand, Fassungen, Berechtigungen, Bestellungen und Ausgabenachweise bleiben vollständig erhalten. Die zurückgezogenen Dateien bleiben im privaten Speicher für Nachweiszwecke, sind aber nicht mehr auslieferbar.
|
||||
|
||||
@@ -685,3 +685,22 @@ ## ADR-48 – Zahlungsjournal als unveränderlicher Nachweis der Einnahmen und E
|
||||
- **Kauf auf Rechnung im Frontend aus** (siehe oben, `SHOP_INVOICE`).
|
||||
- **Ansicht je Umgebung.** Das Journal zeigt ohne Angabe auf Prod die echten Zahlungen (`betrieb=echt`), auf jeder anderen Instanz (Test, lokal) die Testzahlungen (`betrieb=test`), damit sich das Journal dort vollständig ausprobieren lässt. Die Markierung der Buchung (`live`) bleibt unverändert: Sie folgt dem Modus des Zahlungsanbieters (Stripe `livemode`), nicht der Umgebung. Testbuchungen zählen deshalb auch auf Prod nie als Umsatz, falls dort einmal mit Sandbox-Schlüsseln bezahlt wird. Sie bleiben, wie jede Buchung, unlöschbar.
|
||||
**Quelle.** Anfrage von Lars vom 23.11.2026 (Nachweis der Einnahmen und Erstattungen für das Finanzamt); OPEN-06, E-11, E-16; ADR-47.
|
||||
|
||||
## ADR-49 – Übungsverwaltung: Übung als Komposition mit Varianten, Mediensperre bei der Ausgabe, Rückfallschutz
|
||||
|
||||
**Status:** umgesetzt, fachlich zu bestätigen. **Datum:** 23.11.2026. **Auftrag:** Fachlicher Auftrag Übungsverwaltung, Fassung 1.4.
|
||||
|
||||
**Entscheidung.**
|
||||
- **Modell.** Eine Übung ist eine `Composition` mit der neuen Art `exercise`, eine Übungsfassung eine `CompositionVersion`. Der ältere Wert `uebung` bezeichnet weiter das Modul und wird nicht umbenannt. Ergänzt werden nur additive Felder: Fassungsfelder (`duration_max`, `prerequisites`, `structure_hash`), Varianten je Fassung (`composition_version_variants`), je Mitglied Variante, Verwendung (`erforderlich` oder `ergaenzend`) und Herkunft (`quelle` oder `lokal`), am einbindenden Mitglied die Variantenauswahl, im Stand je Zeile Verwendung und Variante.
|
||||
- **Festschreibung.** `ContentResolver::expand` löst eine Übung nur mit ihren gemeinsamen Mitgliedern und den gewählten Varianten auf. Der Artikel-Stand schreibt damit nur die tatsächlich enthaltenen Medienfassungen fest. Pinning, Auflösung und Ausgabeentscheidung laufen über die vorhandene Kette (`ArticleService`, `release_contents`, `DecideAccess`).
|
||||
- **Änderungsnachweis.** `resolved_hash` deckt nur die Menge der Medienfassungen ab und bleibt unverändert. Der neue `structure_hash` deckt Felder, Varianten, Reihenfolge, Verwendung und Auswahl ab.
|
||||
- **Geschützter Lehrinhalt.** Vorbereitung, Durchführung und Trainerhinweise sind Text-Inhaltsfassungen (Muster der Lehrtexte). Die Mitgliederansicht und das PDF lesen die im Stand gebundene Fassung; jeder Abschnitt wird über `DecideAccess` entschieden (`ansehen`, PDF = `laden`, Film = `streamen`).
|
||||
- **Mediensperre (Abweichung von Dokument 06, Abschnitt 6).** Eine gesperrte Medienfassung wird bei der Ausgabe verweigert (Player, Direktabruf, Ableitungen, Vorschaubild). Es werden **nicht** alle Stände zurückgezogen, die sie enthalten. Anleitung und übrige berechtigte Inhalte bleiben im selben Stand erreichbar. Ein ergänzendes Medium entfällt mit einem Hinweis, bei einem erforderlichen gilt die Variante als nicht vollständig durchführbar. Die Festschreibung und der Verwendungsnachweis behalten die ursprüngliche Auswahl; es wird kein Ersatz gewählt. Der Rückzug einer Übungsfassung oder eines Stands bleibt ein eigener Vorgang. Der Auswirkungsbericht (`ExerciseUsage::blockImpact`) nennt Stand, Variante, Verwendung und Folge.
|
||||
- **Angebote.** Die Abdeckungsprüfung lehnt die Aktivierung ab, solange der Umfang gesperrte Bestandteile enthält, und nennt sie.
|
||||
- **PDF.** Die Datei wird bei jedem Abruf neu erzeugt und nie gespeichert (Abweichung von der Zwischenspeicherung in Dokument 08, 4), damit eine Sperre keine ältere Kopie ausliefern kann. Kennzeichnung K2 (Fußzeile je Seite) und K1 (Kennung in den Metadaten), Ausgabenachweis je enthaltener Fassung mit gemeinsamer Lizenzkopie-Kennung.
|
||||
- **Rückfallschutz.** Ein neuer `kind`-Wert würde den Enum-Zugriff des vorherigen Stands zum Absturz bringen. Deshalb gilt in diesem Stand eine Komposition unbekannter Art als nicht vorhanden (`SupportedKindScope`); Aufbauten mit solchen Bestandteilen werden weder veröffentlicht noch als Angebot aktiviert, ihre Editoren sind schreibgeschützt, die Mitgliederansicht zeigt den Bestandteil nicht. Der Rückfalltest (`scripts/rueckfall/`) prüft den vorherigen Stand gegen Daten des neuen.
|
||||
- **Übernahme aus Shinkan.** Die Quelle ist an ihre stabile Kennung gebunden, jeder Inhaltsstand (Prüfsumme) wird genau einmal festgehalten, eine lokale Fassung entsteht nur durch die bewusste Übernahme und lokale Ergänzungen bleiben erhalten. Das Ausblenden an der Quelle setzt nur die Verfügbarkeit. Medien des Katalogs sind Metadaten ohne Datei und nie Teil eines Stands. Feldzuordnung: `docs/fachkonzept/uebungen-shinkan-feldzuordnung.md`.
|
||||
|
||||
**Alternativen.** Eigene Übungstabellen (verworfen: dupliziert Fassung, Auflösung, Festschreibung und Ausgabe); Umbenennen des Werts `uebung` (verworfen: Datenmigration ohne Rückfall); Rückzug aller Stände bei einer Mediensperre (verworfen: widerspricht dem Auftrag, die Übung bleibt erreichbar).
|
||||
|
||||
**Folgen.** Alle Migrationen sind additiv; der Rückfall setzt nur den Code zurück. Nach einem Rückfall werden Übungen im vorherigen Stand nicht bearbeitet oder veröffentlicht. Der Rückfallschutz (Teil 0) muss auf `main` liegen, bevor auf Prod die erste Übung entsteht.
|
||||
@@ -0,0 +1,51 @@
|
||||
# Übungen aus Shinkan: Feldzuordnung
|
||||
|
||||
Stand: 23.11.2026. Grundlage: lokaler Shinkan-Checkout (`backend/migrations/005_exercises.sql`, `routers/exercises.py` `enrich_exercise_detail`, `distribution_contract.py` `catalog_document`). Spätere Shinkan-Migrationen (zum Beispiel 056 für kombinierte Übungen) habe ich nur punktuell geprüft; das Inventar ist daher **nicht abschließend**. Der bestätigte Testvertrag steht aus.
|
||||
|
||||
**Nachweis:** Die Übernahme ist für den heute gelieferten Umfang umgesetzt und getestet (Teilimport, Fixtures im Format der Katalogausgabe). Vollständige Übernahme ist erst nach einer Ergänzung in Shinkan abnehmbar.
|
||||
|
||||
## Heute im Katalog verfügbar
|
||||
|
||||
| Shinkan | Lara & Felix | Anzeige |
|
||||
|---|---|---|
|
||||
| `source_id` (`public_id`) | stabile Quellkennung (`exercise_sources.source_id`) | Importbereich |
|
||||
| `content_hash` | Inhaltswert je Stand (`exercise_source_snapshots`, eindeutig) | Importbereich |
|
||||
| `title` | Bezeichnung der Übung | Verwaltung, Kundenansicht |
|
||||
| `summary` | Kurzbeschreibung (`compositions.summary`, bei Neuanlage) | Verwaltung, Kundenansicht |
|
||||
| `goal` | `learning_goal` der Fassung | Kundenansicht |
|
||||
| `execution` | Textabschnitt „Durchführung“ (Text-Inhaltsfassung, Herkunft Quelle) | Kundenansicht, PDF |
|
||||
| `preparation` | Textabschnitt „Vorbereitung“ | Kundenansicht, PDF |
|
||||
| `trainer_notes` | Textabschnitt „Trainerhinweise“ | Kundenansicht, PDF |
|
||||
| `equipment` (im Katalog als Text) | `material_note` (Ausstattung) | Kundenansicht, PDF |
|
||||
| `duration_min`, `duration_max` | `duration_minutes`, `duration_max` | Kundenansicht, PDF |
|
||||
| Variante `id` | Variantenschlüssel (`composition_version_variants.key`) | Verwaltung, Kundenansicht |
|
||||
| Variante `name`, `description` | Name, Beschreibung der Variante | Kundenansicht |
|
||||
| Variante `execution_changes` | Abschnitt „Abweichung der Durchführung“ der Variante | Kundenansicht, PDF |
|
||||
| Variante `sequence_order` | Position der Variante | Kundenansicht |
|
||||
| Medien `id`, `media_type`, `title`, `sort_order` | nur Quellangabe im Importbereich, **nie** Medienausgabe oder Teil eines Stands | Importbereich |
|
||||
|
||||
## Im Katalog nicht verfügbar (Lücken im Übergabevertrag)
|
||||
|
||||
| Shinkan | Zuordnung, sobald geliefert |
|
||||
|---|---|
|
||||
| `group_size_min`, `group_size_max` | neues Fassungsfeld oder Einordnung, noch zu entscheiden |
|
||||
| `age_groups`, `target_groups` | redaktionelle Dimensionen (Altersbereich, Zielgruppe) |
|
||||
| `focus_areas`, `training_styles`, `training_types` | Einordnung (Dimensionen) oder Quellangabe |
|
||||
| `skills` (Intensität, Eingangs- und Ziel-Niveau) | Quellangabe, kein lokales Feld |
|
||||
| `method_profile`, Methoden | Quellangabe |
|
||||
| `exercise_kind`, `combination_slots` (kombinierte Übungen) | gesondert zu prüfen |
|
||||
| Variante: Dauer, `equipment_changes`, `difficulty_adjustment`, `progression_level`, `prerequisite_variant_id` | Variantenfelder, noch zu entscheiden |
|
||||
| Variante: `age_group_override`, `skill_focus_override` | Quellangabe |
|
||||
| Medien: `description`, `context`, `is_primary`, Einbettung, Urheberhinweis, Rechtsstand des Assets (`lifecycle_state`, `legal_hold_active`) | der Rechtsstand ist für die Sperrfrage wichtig und sollte geliefert werden |
|
||||
|
||||
## Bleibt in Shinkan (nicht übernommen)
|
||||
|
||||
Verein, Ersteller, Sichtbarkeit, Freigabestatus, Importquelle, Speicherpfade und Berechtigungsdaten.
|
||||
|
||||
## Verhalten
|
||||
|
||||
- Wiederholter Abruf desselben Inhaltsstands legt nichts Neues an. Ein neuer Inhaltswert erscheint zur bewussten Übernahme.
|
||||
- Die Übernahme legt eine neue, unveränderliche lokale Fassung an. Lokal ergänzte Bestandteile (Herkunft „lokal“) bleiben bei einer neuen Quellfassung erhalten. Eine lokale Zuordnung zu einer entfallenen Quellvariante wandert in den gemeinsamen Teil.
|
||||
- Ein fehlgeschlagener Abruf verändert den gespeicherten Stand und den Cursor nicht.
|
||||
- Das Ausblenden an der Quelle setzt nur die Verfügbarkeit („nicht mehr bereitgestellt“). Lokale Fassungen und Verwendungen bleiben unberührt. Eine rechtliche Sperre ist der lokale `block` am Medium und ein eigener Vorgang.
|
||||
- Shinkan liefert weder eine Medienausgabe noch eine kommerzielle Nutzungsberechtigung. Ob Quelltexte kommerziell eingesetzt werden dürfen, ist eine Entscheidung vor dem ersten Produktstand mit einer übernommenen Übung.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Abnahme Übungsverwaltung (Stand 23.11.2026)
|
||||
|
||||
Auftrag: Fachlicher Auftrag Übungsverwaltung, Fassung 1.4. Entscheidung: ADR-49. Dieser Stand belegt die **automatisierten
|
||||
Prüfungen**. Die Abnahme der Oberfläche auf `luf-test` mit Screenshots (breit und schmal) steht noch aus und ist unten als
|
||||
offen gekennzeichnet. Es wird keine ungeprüfte Abnahme behauptet.
|
||||
|
||||
## Geprüft (automatisierte Tests, lokal grün)
|
||||
|
||||
| Fall des Auftrags | Nachweis |
|
||||
|---|---|
|
||||
| Eigene Übung und Medien: anlegen, Varianten, Medien in Abfolge, Fassung bereitstellen | `UebungEditorTest` (Anlegen mit Art „Übung“, Varianten, gemeinsames und varianteigenes Material, dasselbe Medium in zwei Varianten, Entwurf bleibt beim erneuten Öffnen, Fassung mit Feldern, Varianten und Verwendung) |
|
||||
| Einbau und Kontextwechsel in Modul und Programm, Auswahl der Varianten | `UebungEditorTest` (Auswahl bleibt im Entwurf erhalten, wird mit der Fassung festgeschrieben) |
|
||||
| Festschreibung im Stand: nur gewählte Varianten, Mehrfachverwendung, Änderungsnachweis | `UebungFassungTest` |
|
||||
| Verkauf: Modul und Programm mit Übung, Berechtigung, Zugang | `UebungAusgabeTest` (Artikel-Stand, Angebot, Berechtigung über `GrantIssuer`) |
|
||||
| Zwei Stände mit unterschiedlichen Fassungen derselben Übung, gebundene Fassung bleibt | `UebungAusgabeTest`, `UebungSperreTest` |
|
||||
| Formatierte Ansicht: Lernziel, Varianten, Abfolge, Listen, Kennzeichnung | `UebungAusgabeTest` |
|
||||
| PDF: gleiche Fassung und Variante, mehrseitig, Fußzeile je Seite, Kennung, Ausgabenachweis, Sonderzeichen | `UebungAusgabeTest` |
|
||||
| Ohne Lizenz oder ohne PDF-Recht: Anleitung und direkter PDF-Abruf abgelehnt | `UebungAusgabeTest` |
|
||||
| Ergänzendes Medium gesperrt: Anleitung und PDF bleiben, Medium im Direktabruf gesperrt | `UebungAusgabeTest`, `UebungSperreTest` |
|
||||
| Erforderliches Medium gesperrt: Variante gekennzeichnet, Alternative bleibt | `UebungAusgabeTest` |
|
||||
| Vorschaubild eines gesperrten Mediums | `UebungSperreTest` |
|
||||
| Verwendungsnachweis über verschachtelte und ältere Stände, Auswirkungsbericht | `UebungSperreTest` |
|
||||
| Angebot mit gesperrtem Bestandteil nicht aktivierbar | `UebungSperreTest` |
|
||||
| Rückfall: vorheriger Stand gegen Daten des neuen | `RueckfallschutzTest` (in der Suite), `scripts/rueckfall/` (zwei Stände nebeneinander) |
|
||||
| Shinkan-Übernahme (Teilumfang): erkennen, keine Duplikate, geänderte Variante, lokale Ergänzung, Fehlerlauf, entfallene Auswahl, Medien ohne Ausgabe | `ShinkanUebernahmeTest` (Beispieldaten im Format der Katalogausgabe) |
|
||||
|
||||
## Abweichungen und offene Punkte
|
||||
|
||||
- **Oberflächenabnahme auf luf-test fehlt.** Die Screenserie (breit und schmal), die Tastaturbedienung und die Lade-, Leer- und
|
||||
Fehlerzustände sind noch nicht in der laufenden Testanwendung geprüft. Gemeinsam genutzt sind der Aufbauarbeitsplatz
|
||||
(`EditComposition`, `aufbau`, `aufbau-angaben`), der Picker, die Bestandsliste (`ListsCompositions`, `verwaltung/bestand`)
|
||||
und der Kopf (`verwaltung/kopf`). Die Seite „Übernahme (Shinkan)“ nutzt einfache `vw-`-Klassen und noch nicht die gemeinsame
|
||||
Bestandsliste.
|
||||
- **Testkauf auf luf-test blockiert.** Es ist kein Mitgliedskonto mit Lizenz auf luf-test bekannt. Der Verkaufsweg ist lokal
|
||||
über Berechtigungsvergabe und Mitgliederansicht geprüft, nicht über den Bezahlweg der Testinstanz.
|
||||
- **Rechteprofile.** Das PDF braucht `text: laden`, die Ansicht `text: ansehen`. Die bestehenden Profile habe ich nicht gelesen.
|
||||
Neue Rechte entstehen nur über neue Profilfassungen; bestehende Berechtigungen ändere ich nicht.
|
||||
- **Zeichen im PDF.** Zeichen außerhalb von Windows-1252 werden, wo möglich, lesbar ersetzt (Pfeil, Ungleichheitszeichen,
|
||||
andere lateinische Buchstaben), sonst erscheint „?“.
|
||||
- **Shinkan:** Teilimport. Lücken siehe `docs/fachkonzept/uebungen-shinkan-feldzuordnung.md`. Der echte Testabruf steht aus,
|
||||
weil Adresse, Schlüssel und der bestätigte Vertrag fehlen. Die kommerzielle Nutzung der Quelltexte ist nicht entschieden.
|
||||
- **Andere Dateidownloads** werden weiter mit Kennzeichnung `k0` protokolliert. Das widerspricht Dokument 08 und ist nicht
|
||||
Teil dieses Auftrags.
|
||||
@@ -30,10 +30,11 @@
|
||||
<div class="vw vw-aufbauseite" x-data x-on:keydown.window.ctrl.s.prevent="$wire.saveDraft()">
|
||||
@include('filament.verwaltung.kopf', [
|
||||
'zurueck' => ['label' => 'Zum Arbeitsplatz', 'href' => \App\Filament\Pages\EditorialDesk::getUrl()],
|
||||
'brot' => [['label' => $this->isProgram() ? 'Programme' : 'Module', 'href' => $this::getResource()::getUrl('index')], $titel],
|
||||
'brot' => [['label' => $this->hostKind()->plural() === 'Kurse' ? 'Programme' : $this->hostKind()->plural(), 'href' => $this::getResource()::getUrl('index')], $titel],
|
||||
'titel' => $titel,
|
||||
'typ' => $this->hostLabel().' · '.$typ,
|
||||
'status' => [
|
||||
($schutz = $this->schreibschutz()) !== null ? ['text' => $schutz, 'ton' => 'offen'] : null,
|
||||
['text' => $aufbauOffen ? 'Änderungen am Aufbau nicht gespeichert' : $statusSatz, 'ton' => $aufbauOffen ? 'offen' : ($bereit !== null ? 'gut' : 'neutral')],
|
||||
$redaktionOffen ? ['text' => 'Die Redaktion hat ungespeicherte Änderungen.', 'ton' => 'offen', 'aktion' => ['label' => 'Zur Redaktion', 'wire' => "openRedaktion('".$this->redaktionTab."')"]] : null,
|
||||
],
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
@php($daten = $this->daten())
|
||||
<div class="vw">
|
||||
<header class="vw-kopf">
|
||||
<h1 class="vw-titel">Übernahme aus Shinkan</h1>
|
||||
<p class="vw-feld-hilfe">Shinkan stellt für Lara & Felix ausgewählte Übungen bereit. „Abrufen“ aktualisiert nur den Quellenstand. Erst „Übernehmen“ legt eine unveränderliche lokale Fassung an. Produkte verwenden sie erst, wenn du sie dort einsetzt und das Produkt veröffentlichst.</p>
|
||||
<p>
|
||||
<button type="button" class="button button-primary" wire:click="fetch" wire:loading.attr="disabled" @disabled(! $daten['eingerichtet'])>Katalog abrufen</button>
|
||||
@unless ($daten['eingerichtet'])
|
||||
<span class="vw-feld-hilfe">Die Anbindung ist in dieser Umgebung nicht eingerichtet.</span>
|
||||
@endunless
|
||||
</p>
|
||||
@if ($this->feedback !== '')
|
||||
<p class="vw-band {{ $this->feedbackError ? 'is-fehler' : '' }}" role="status">{{ $this->feedback }}</p>
|
||||
@endif
|
||||
@if ($daten['letzterLauf'])
|
||||
<p class="vw-feld-hilfe">Letzter Abruf: {{ $daten['letzterLauf']->started_at?->format('d.m.Y H:i') }} · {{ $daten['letzterLauf']->status === 'ok' ? 'erfolgreich' : 'fehlgeschlagen' }}@if ($daten['letzterLauf']->error) · {{ $daten['letzterLauf']->error }}@endif</p>
|
||||
@endif
|
||||
</header>
|
||||
|
||||
@if ($daten['zeilen'] === [])
|
||||
<div class="vw-leer"><p>Noch keine Quellübung abgerufen.</p></div>
|
||||
@else
|
||||
<ul class="vw-liste">
|
||||
@foreach ($daten['zeilen'] as $zeile)
|
||||
<li class="vw-zeile">
|
||||
<div>
|
||||
<strong>{{ $zeile['titel'] }}</strong>
|
||||
<span class="vw-chip is-{{ $zeile['ton'] }}">{{ $zeile['zustand'] }}</span>
|
||||
<p class="vw-feld-hilfe">Herkunft: Shinkan · {{ $zeile['varianten'] }} {{ $zeile['varianten'] === 1 ? 'Variante' : 'Varianten' }}
|
||||
@if ($zeile['quellmedien'] !== [])· Quellmedien ohne Datei: {{ implode(', ', $zeile['quellmedien']) }}@endif</p>
|
||||
@if ($zeile['hinweis'])<p class="vw-feld-hilfe">{{ $zeile['hinweis'] }}</p>@endif
|
||||
</div>
|
||||
<div>
|
||||
@if ($zeile['snapshot'])
|
||||
<button type="button" class="button button-secondary" wire:click="adopt({{ $zeile['snapshot'] }})">Übernehmen</button>
|
||||
@endif
|
||||
@if ($zeile['lokal'])
|
||||
<a class="vw-link" href="{{ $zeile['lokal'] }}">Lokale Übung öffnen</a>
|
||||
@endif
|
||||
</div>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</div>
|
||||
@@ -2,7 +2,7 @@
|
||||
@php
|
||||
$cover = $this->coverPicture();
|
||||
$filme = $this->frameFilms();
|
||||
$ort = $this->isProgram() ? 'dieses Programms' : 'dieses Moduls';
|
||||
$ort = $this->isProgram() ? 'dieses Programms' : ($this->isExercise() ? 'dieser Übung' : 'dieses Moduls');
|
||||
@endphp
|
||||
<div class="vw-medien-raster">
|
||||
<section class="vw-medien-haupt" aria-labelledby="didaktik-titel">
|
||||
@@ -19,9 +19,40 @@
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="revisionNote">
|
||||
</label>
|
||||
</div>
|
||||
<label class="vw-feldlabel">Materialbedarf
|
||||
<label class="vw-feldlabel">{{ $this->isExercise() ? 'Ausstattung' : 'Materialbedarf' }}
|
||||
<textarea class="vw-eingabe" rows="3" wire:model.live.blur="materialNote"></textarea>
|
||||
</label>
|
||||
@if ($this->isExercise())
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Zeitbedarf bis (Minuten)
|
||||
<input class="vw-eingabe" type="text" inputmode="numeric" wire:model.live.blur="durationMax">
|
||||
</label>
|
||||
<label class="vw-feldlabel">Voraussetzungen
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="prerequisites">
|
||||
</label>
|
||||
</div>
|
||||
<h2 id="varianten-titel" class="vw-abschnitt-titel">Varianten</h2>
|
||||
<p class="vw-feld-hilfe">Eine Übung kann mehrere Durchführungsvarianten haben. Gemeinsame Bestandteile gelten für alle; jedem Bestandteil ordnest du im Aufbau eine Variante zu.</p>
|
||||
<ul class="vw-liste" aria-labelledby="varianten-titel">
|
||||
@foreach ($this->variants as $i => $variant)
|
||||
<li class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Name der Variante
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="variants.{{ $i }}.name">
|
||||
</label>
|
||||
<label class="vw-feldlabel">Beschreibung
|
||||
<input class="vw-eingabe" type="text" wire:model.live.blur="variants.{{ $i }}.description">
|
||||
</label>
|
||||
<button type="button" class="vw-link" wire:click="removeVariant('{{ $variant['key'] }}')">Variante entfernen</button>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<div class="vw-raster-2">
|
||||
<label class="vw-feldlabel">Neue Variante
|
||||
<input class="vw-eingabe" type="text" wire:model="newVariantName" wire:keydown.enter="addVariant" placeholder="z. B. Mit Film">
|
||||
</label>
|
||||
<button type="button" class="button button-secondary" wire:click="addVariant">Variante anlegen</button>
|
||||
</div>
|
||||
@endif
|
||||
<p class="vw-feld-hilfe">Name, Texte, Präsentationsmedien und Einordnung bearbeitest du in der Redaktion.
|
||||
<button type="button" class="vw-link" wire:click="openRedaktion('texte')">Redaktion öffnen</button></p>
|
||||
</section>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
$gewaehlt = $auswahl !== null ? $members[$auswahl] : null;
|
||||
$symbol = fn (?string $tone): string => match ($tone) { 'film' => 'film', 'audio' => 'audio', 'dokument' => 'dokument', 'modul', 'programm' => 'modul', default => 'dokument' };
|
||||
$istKomposition = fn (array $m): bool => (bool) preg_match('/^composition(-draft)?:/', (string) ($m['target'] ?? ''));
|
||||
$ort = ($this->isProgram() ? 'im Programm' : 'im Modul');
|
||||
$ort = ($this->isProgram() ? 'im Programm' : ($this->isExercise() ? 'in der Übung' : 'im Modul'));
|
||||
@endphp
|
||||
<div class="vw-aufbau">
|
||||
<section class="vw-struktur" aria-labelledby="struktur-titel">
|
||||
@@ -196,6 +196,38 @@
|
||||
<label class="vw-feldlabel">Hinweis an dieser Stelle
|
||||
<textarea class="vw-eingabe" rows="4" wire:model.live.blur="noteDraft" placeholder="Was Trainer an dieser Stelle beachten sollen"></textarea>
|
||||
</label>
|
||||
@if ($this->isExercise())
|
||||
<label class="vw-feldlabel">Variante
|
||||
<select class="vw-eingabe" wire:change="setMemberVariant({{ $auswahl }}, $event.target.value)">
|
||||
<option value="" @selected(($gewaehlt['variant'] ?? null) === null)>Gemeinsam (gilt für alle Varianten)</option>
|
||||
@foreach ($this->variants as $variant)
|
||||
<option value="{{ $variant['key'] }}" @selected(($gewaehlt['variant'] ?? null) === $variant['key'])>{{ $variant['name'] ?: $variant['key'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
<label class="vw-feldlabel">Verwendung
|
||||
<select class="vw-eingabe" wire:change="setMemberRequirement({{ $auswahl }}, $event.target.value)">
|
||||
<option value="erforderlich" @selected(($gewaehlt['requirement'] ?? 'erforderlich') === 'erforderlich')>Erforderlich</option>
|
||||
<option value="ergaenzend" @selected(($gewaehlt['requirement'] ?? 'erforderlich') === 'ergaenzend')>Ergänzend</option>
|
||||
</select>
|
||||
<span class="vw-feld-hilfe">Fehlt ein erforderlicher Bestandteil, gilt die Variante als nicht vollständig durchführbar. Ein ergänzender entfällt mit Hinweis.</span>
|
||||
</label>
|
||||
@endif
|
||||
@php($angeboten = $this->offeredVariants((string) ($gewaehlt['target'] ?? '')))
|
||||
@if ($angeboten !== [])
|
||||
<fieldset class="vw-chipgruppe">
|
||||
<legend>Angebotene Varianten</legend>
|
||||
<div class="vw-chips">
|
||||
@foreach ($angeboten as $variante)
|
||||
<label>
|
||||
<input type="checkbox" @checked(! is_array($gewaehlt['selection'] ?? null) || in_array($variante['key'], $gewaehlt['selection'], true)) wire:click="toggleVariantSelection({{ $auswahl }}, '{{ $variante['key'] }}')">
|
||||
<span>{{ $variante['name'] }}</span>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
<span class="vw-feld-hilfe">Gilt nur in diesem Aufbau. Nur die angebotenen Varianten werden im Stand festgeschrieben.</span>
|
||||
</fieldset>
|
||||
@endif
|
||||
@if (count($alternativen) > 1)
|
||||
<fieldset class="vw-chipgruppe">
|
||||
<legend>Verwendete Fassung</legend>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
@extends('layouts.member')
|
||||
|
||||
@section('title', $guide['title'])
|
||||
@section('nav', 'bibliothek')
|
||||
|
||||
{{--
|
||||
Übung als formatierte Anleitung im erworbenen Stand. Gezeigt wird die im Stand gebundene Fassung mit den dort
|
||||
angebotenen Varianten. Über jeden Abschnitt und jedes Medium entscheidet die zentrale Rechteprüfung: Was fehlt oder
|
||||
gesperrt ist, erscheint als Hinweis an seiner Stelle, die übrige Anleitung bleibt lesbar.
|
||||
--}}
|
||||
@section('content')
|
||||
<p class="mb-crumb"><a href="{{ route('member.library') }}"><x-heroicon-o-arrow-left aria-hidden="true" /> Zur Bibliothek</a></p>
|
||||
<article class="mb-reading mb-exercise">
|
||||
<header class="mb-content-head">
|
||||
<h1 class="mb-title">{{ $guide['title'] }}</h1>
|
||||
@if (filled($guide['summary']))
|
||||
<p class="mb-lead">{{ $guide['summary'] }}</p>
|
||||
@endif
|
||||
</header>
|
||||
|
||||
@if (filled($copy ?? null))
|
||||
<p class="state state-hinweis">Lizenziert für {{ $reader }} · Lizenzkopie {{ $copy }}</p>
|
||||
@endif
|
||||
|
||||
<dl class="mb-facts">
|
||||
@if (filled($guide['learning_goal']))
|
||||
<div><dt>Lernziel</dt><dd>{{ $guide['learning_goal'] }}</dd></div>
|
||||
@endif
|
||||
@if ($guide['duration_minutes'] !== null)
|
||||
<div><dt>Dauer</dt><dd>{{ $guide['duration_minutes'] }}@if ($guide['duration_max'] !== null) bis {{ $guide['duration_max'] }}@endif Minuten</dd></div>
|
||||
@endif
|
||||
@if (filled($guide['prerequisites']))
|
||||
<div><dt>Voraussetzungen</dt><dd>{{ $guide['prerequisites'] }}</dd></div>
|
||||
@endif
|
||||
@if (filled($guide['material_note']))
|
||||
<div><dt>Ausstattung</dt><dd>{{ $guide['material_note'] }}</dd></div>
|
||||
@endif
|
||||
</dl>
|
||||
|
||||
@if (count($guide['variants']) > 1)
|
||||
<nav class="mb-variants" aria-label="Varianten">
|
||||
<ul>
|
||||
@foreach ($guide['variants'] as $variant)
|
||||
<li>
|
||||
<a href="{{ $variantUrl($variant['key']) }}" @if ($guide['chosen'] === $variant['key']) aria-current="true" @endif>{{ $variant['name'] }}</a>
|
||||
@unless ($variant['complete'])
|
||||
<span class="state state-hinweis">derzeit nicht vollständig durchführbar</span>
|
||||
@endunless
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</nav>
|
||||
@endif
|
||||
|
||||
@foreach ($guide['variants'] as $variant)
|
||||
@if ($guide['chosen'] === $variant['key'])
|
||||
@if (filled($variant['description']))
|
||||
<p class="mb-prose">{{ $variant['description'] }}</p>
|
||||
@endif
|
||||
@unless ($variant['complete'])
|
||||
<p class="state state-hinweis" role="status">
|
||||
Diese Variante ist derzeit nicht vollständig durchführbar: {{ implode(', ', $variant['missing']) }} ist nicht verfügbar.
|
||||
@if (count($guide['variants']) > 1) Eine andere Variante steht weiter zur Verfügung. @endif
|
||||
</p>
|
||||
@endunless
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
@foreach ($guide['entries'] as $entry)
|
||||
<section class="mb-exercise-part" data-class="{{ $entry['class'] }}" data-state="{{ $entry['state'] }}">
|
||||
@if ($entry['allowed'] && $entry['class'] === 'text')
|
||||
<h2>{{ $entry['title'] }}</h2>
|
||||
<div class="mb-prose">
|
||||
@include('member.partials.guide-blocks', ['blocks' => $entry['blocks']])
|
||||
</div>
|
||||
@elseif ($entry['allowed'])
|
||||
<h2>{{ $entry['title'] }}</h2>
|
||||
<p>
|
||||
<a class="button button-secondary" href="{{ $entry['url'] }}">
|
||||
{{ in_array($entry['class'], ['film', 'audio'], true) ? 'Ansehen' : 'Öffnen' }}
|
||||
</a>
|
||||
@if ($entry['download_url'])
|
||||
<a class="button button-secondary" href="{{ $entry['download_url'] }}">Herunterladen</a>
|
||||
@endif
|
||||
</p>
|
||||
@elseif ($entry['requirement'] === 'ergaenzend')
|
||||
<p class="state state-hinweis" role="note">
|
||||
{{ $entry['title'] }}: Dieses ergänzende Material ist derzeit nicht verfügbar. Die Übung bleibt vollständig durchführbar.
|
||||
</p>
|
||||
@else
|
||||
<p class="state state-hinweis" role="note">
|
||||
{{ $entry['title'] }}: Dieser Bestandteil ist derzeit nicht verfügbar.
|
||||
</p>
|
||||
@endif
|
||||
</section>
|
||||
@endforeach
|
||||
|
||||
<p class="mb-actions">
|
||||
@if ($pdfUrl)
|
||||
<a class="button button-secondary" href="{{ $pdfUrl }}"><x-heroicon-o-arrow-down-tray aria-hidden="true" /> Als PDF herunterladen</a>
|
||||
@else
|
||||
<span class="state state-hinweis">Ein PDF ist für diese Lizenz oder derzeit nicht verfügbar.</span>
|
||||
@endif
|
||||
</p>
|
||||
</article>
|
||||
@endsection
|
||||
@@ -0,0 +1,23 @@
|
||||
@foreach ($blocks as $block)
|
||||
@switch ($block['type'])
|
||||
@case ('heading')
|
||||
<h3>{{ $block['text'] }}</h3>
|
||||
@break
|
||||
@case ('bullets')
|
||||
<ul>
|
||||
@foreach ($block['items'] as $item)
|
||||
<li>{{ $item }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@break
|
||||
@case ('numbered')
|
||||
<ol>
|
||||
@foreach ($block['items'] as $item)
|
||||
<li>{{ $item }}</li>
|
||||
@endforeach
|
||||
</ol>
|
||||
@break
|
||||
@default
|
||||
<p>{{ $block['text'] }}</p>
|
||||
@endswitch
|
||||
@endforeach
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
use App\Http\Controllers\EditorialPreviewController;
|
||||
use App\Http\Controllers\Member\CheckoutController;
|
||||
use App\Http\Controllers\Member\ExerciseController;
|
||||
use App\Http\Controllers\Member\LibraryController;
|
||||
use App\Http\Controllers\Member\MemberController;
|
||||
use App\Http\Controllers\Member\PaymentController;
|
||||
@@ -127,6 +128,13 @@
|
||||
Route::get('/ausgabe/{article}/{release}/{version}/{action}', [LibraryController::class, 'media'])
|
||||
->middleware('signed:relative')
|
||||
->name('media');
|
||||
Route::get('/stand/{article}/{release}/uebung/{path}', [ExerciseController::class, 'show'])
|
||||
->where('path', '[0-9]+(?:-[0-9]+)*')
|
||||
->name('exercise');
|
||||
Route::get('/stand/{article}/{release}/uebung/{path}/pdf', [ExerciseController::class, 'pdf'])
|
||||
->where('path', '[0-9]+(?:-[0-9]+)*')
|
||||
->middleware('signed:relative')
|
||||
->name('exercise.pdf');
|
||||
Route::get('/abschnitt/{article}/{release}/{version}/{datei}', [LibraryController::class, 'rendition'])
|
||||
->where('datei', '.*')
|
||||
->middleware('signed:relative')
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Rückfalltest: vorheriger Programmstand gegen Daten des neuen
|
||||
|
||||
Der Rückfall nach einem Deploy setzt nur den **Code** zurück, nicht die Datenbank. Dieser Test weist nach, dass der
|
||||
vorherige Programmstand (mit dem Rückfallschutz, Teil 0) gegen Daten des neuen Stands nicht abstürzt, keine ungewählte
|
||||
Variante und keine Übung offenlegt und beim Bearbeiten nichts verliert.
|
||||
|
||||
Er gehört **nicht** zur normalen Suite: Er braucht zwei Stände nebeneinander. Er ändert weder Test noch Prod.
|
||||
|
||||
1. Worktree des neuen Stands (dieser Branch) und Worktree des vorherigen Stands anlegen (Commit mit dem Rückfallschutz,
|
||||
`ef56bef` „Schütze den vorherigen Programmstand vor Kompositionen unbekannter Art“), in beiden `vendor` kopieren
|
||||
(nicht verlinken) und eine `.env` bereitstellen.
|
||||
2. Im neuen Stand die Daten erzeugen (SQLite-Datei und JSON mit den Kennungen):
|
||||
|
||||
```
|
||||
php scripts/rueckfall/build-daten.php <worktree-neu> <ordner>/rueckfall.sqlite <ordner>/rueckfall.json
|
||||
```
|
||||
|
||||
3. `RueckfallGegenNeueDatenTest.php` in `tests/Feature/` des **vorherigen** Stands kopieren (nicht committen) und dort
|
||||
ausführen:
|
||||
|
||||
```
|
||||
RUECKFALL_DB=<ordner>/rueckfall.sqlite RUECKFALL_JSON=<ordner>/rueckfall.json php artisan test --filter=RueckfallGegenNeueDatenTest
|
||||
```
|
||||
|
||||
Der Test arbeitet auf einer Kopie der Datei. Erwartet: alle Prüfungen grün.
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Filament\Resources\Courses\Pages\EditCourse;
|
||||
use App\Filament\Resources\Exercises\Pages\EditExercise;
|
||||
use App\Http\SignedLink;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Rückfalltest: Dieser Test läuft im VORHERIGEN Programmstand (Teil 0) gegen eine Datenbank, die der NEUE Stand erzeugt
|
||||
* hat (Übung mit zwei Varianten, Modul mit Variante A, Programm mit Variante B, verkauft). Der Rückfall setzt nur den
|
||||
* Code zurück; die Daten bleiben. Der alte Stand darf nicht abstürzen, keine ungewählte Variante und keine Übung
|
||||
* offenlegen und beim Bearbeiten nichts verlieren.
|
||||
*/
|
||||
class RueckfallGegenNeueDatenTest extends TestCase
|
||||
{
|
||||
/** @var array<string, int> */
|
||||
private array $ids;
|
||||
|
||||
private string $file;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->file = sys_get_temp_dir().'/rueckfall-'.uniqid().'.sqlite';
|
||||
copy((string) getenv('RUECKFALL_DB'), $this->file);
|
||||
config(['database.connections.sqlite.database' => $this->file]);
|
||||
DB::purge('sqlite');
|
||||
$this->ids = json_decode((string) file_get_contents((string) getenv('RUECKFALL_JSON')), true, 512, JSON_THROW_ON_ERROR);
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
DB::purge('sqlite');
|
||||
@unlink($this->file);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_the_stored_exercise_is_a_kind_the_previous_state_does_not_know(): void
|
||||
{
|
||||
$this->assertSame(1, DB::table('compositions')->where('kind', 'exercise')->count());
|
||||
$this->assertNull(Composition::query()->find($this->ids['exercise_composition']));
|
||||
}
|
||||
|
||||
public function test_the_member_area_neither_crashes_nor_leaks(): void
|
||||
{
|
||||
$member = User::query()->findOrFail($this->ids['member']);
|
||||
|
||||
$this->actingAs($member)->get(route('member.library'))->assertOk()->assertSee('Modul Stopp')->assertSee('Programm Stopp');
|
||||
|
||||
foreach (['module_composition', 'program_composition'] as $key) {
|
||||
$this->actingAs($member)
|
||||
->get(route('member.program', $this->ids[$key]))
|
||||
->assertOk()
|
||||
->assertDontSee('Stopp sagen')
|
||||
->assertDontSee('Variante')
|
||||
->assertDontSee('Film A')
|
||||
->assertDontSee('Durchführung');
|
||||
}
|
||||
|
||||
$this->actingAs($member)->get(route('member.program', $this->ids['exercise_composition']))->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_only_the_chosen_variant_of_each_stand_is_delivered(): void
|
||||
{
|
||||
$member = User::query()->findOrFail($this->ids['member']);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('member.article', $this->ids['module_article']))
|
||||
->assertOk()
|
||||
->assertSee('Film A')
|
||||
->assertSee('Durchführung A')
|
||||
->assertDontSee('Durchführung B')
|
||||
->assertDontSee('Arbeitsblatt B');
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('member.article', $this->ids['program_article']))
|
||||
->assertOk()
|
||||
->assertSee('Durchführung B')
|
||||
->assertDontSee('Film A')
|
||||
->assertDontSee('Durchführung A');
|
||||
|
||||
$unchosen = SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $this->ids['module_article'],
|
||||
'release' => $this->ids['module_release'],
|
||||
'version' => $this->ids['film_b_text'],
|
||||
'action' => 'ansehen',
|
||||
'reader' => $member->id,
|
||||
]);
|
||||
$this->actingAs($member)->get($unchosen)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_the_previous_editors_are_read_only_and_lose_nothing(): void
|
||||
{
|
||||
$staff = User::factory()->redakteur()->create();
|
||||
$staff->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$membersBefore = DB::table('composition_members')->count();
|
||||
$versionsBefore = DB::table('composition_versions')->count();
|
||||
|
||||
foreach ([[EditExercise::class, 'module_composition'], [EditCourse::class, 'program_composition']] as [$page, $key]) {
|
||||
$component = Livewire::actingAs($staff, 'staff')
|
||||
->test($page, ['record' => $this->ids[$key]])
|
||||
->assertOk()
|
||||
->assertSee('neueren Programmversion');
|
||||
|
||||
$this->assertNotNull($component->instance()->schreibschutz());
|
||||
$component->call('saveDraft')->call('armRelease')->call('discardDraft');
|
||||
$this->assertFalse($component->instance()->publishRevision());
|
||||
}
|
||||
|
||||
$this->assertSame($membersBefore, DB::table('composition_members')->count());
|
||||
$this->assertSame($versionsBefore, DB::table('composition_versions')->count());
|
||||
$this->assertSame(0, DB::table('compositions')->whereNotNull('working_draft')->count());
|
||||
}
|
||||
|
||||
public function test_the_previous_state_refuses_a_new_stand_that_would_drop_the_exercise(): void
|
||||
{
|
||||
$article = LicenseArticle::query()->findOrFail($this->ids['module_article']);
|
||||
$release = ArticleRelease::query()->findOrFail($this->ids['module_release']);
|
||||
$releases = $article->releases()->count();
|
||||
|
||||
try {
|
||||
app(ArticleService::class)->publishRelease($article, $release->rootCompositionVersion, 'Neuer Stand im alten Programmstand.');
|
||||
$this->fail('Der alte Stand darf keinen Stand mit Übung veröffentlichen.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString('Programmstand', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame($releases, $article->releases()->count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Tests\Support\BuildsExercises;
|
||||
|
||||
/**
|
||||
* Erzeugt mit dem NEUEN Programmstand eine SQLite-Datei mit Übungsdaten (Übung mit zwei Varianten, ein Modul mit Variante
|
||||
* A, ein Programm mit Variante B, verkauft und freigeschaltet) und schreibt die Kennungen als JSON. Der vorherige
|
||||
* Programmstand prüft anschließend gegen genau diese Datei (Rückfalltest).
|
||||
*
|
||||
* Aufruf: php build_rueckfall.php <worktree> <sqlite-datei> <json-datei>
|
||||
*/
|
||||
[$script, $root, $db, $out] = $argv;
|
||||
|
||||
chdir($root);
|
||||
require $root.'/vendor/autoload.php';
|
||||
|
||||
foreach (['DB_CONNECTION' => 'sqlite', 'DB_DATABASE' => $db, 'DB_URL' => '', 'APP_ENV' => 'testing', 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'QUEUE_CONNECTION' => 'sync'] as $key => $value) {
|
||||
putenv($key.'='.$value);
|
||||
$_ENV[$key] = $value;
|
||||
$_SERVER[$key] = $value;
|
||||
}
|
||||
|
||||
@unlink($db);
|
||||
touch($db);
|
||||
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
Artisan::call('migrate:fresh', ['--force' => true]);
|
||||
|
||||
$builder = new class
|
||||
{
|
||||
use BuildsExercises;
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function run(): array
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$module = $this->moduleWith('Modul Stopp', $exercise['version'], ['a']);
|
||||
$program = $this->moduleWith('Programm Stopp', $exercise['version'], ['b'], CompositionKind::Kurs);
|
||||
$articles = app(ArticleService::class);
|
||||
$moduleArticle = $articles->create('modul-stopp');
|
||||
$moduleRelease = $articles->publishRelease($moduleArticle, $module, 'Modul.');
|
||||
$programArticle = $articles->create('programm-stopp');
|
||||
$programRelease = $articles->publishRelease($programArticle, $program, 'Programm.');
|
||||
|
||||
$offers = app(OfferService::class);
|
||||
$rights = $offers->createRightsProfile('Voll', 'ehrenamtlich', ['film' => ['streamen', 'laden'], 'text' => ['ansehen', 'laden'], 'document' => ['ansehen', 'laden']]);
|
||||
$offer = $offers->create('Angebot');
|
||||
$offers->activate($offer, [
|
||||
['target' => $moduleArticle->fresh(), 'rights' => $rights],
|
||||
['target' => $programArticle->fresh(), 'rights' => $rights],
|
||||
], ['grant_kind' => 'auf_abruf']);
|
||||
$member = User::factory()->create(['name' => 'Kursleitung Probe']);
|
||||
app(GrantIssuer::class)->claim($member, $offer);
|
||||
$display = app(CompositionDisplayRelease::class);
|
||||
$display->release($module, $member);
|
||||
$display->release($program, $member);
|
||||
|
||||
return [
|
||||
'member' => $member->id,
|
||||
'module_composition' => $module->composition_id,
|
||||
'program_composition' => $program->composition_id,
|
||||
'exercise_composition' => $exercise['version']->composition_id,
|
||||
'module_article' => $moduleArticle->id,
|
||||
'module_release' => $moduleRelease->id,
|
||||
'program_article' => $programArticle->id,
|
||||
'program_release' => $programRelease->id,
|
||||
'film_a' => $exercise['filmA']->id,
|
||||
'film_b_text' => $exercise['textB']->id,
|
||||
'sheet_b' => $exercise['sheetB']->id,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
file_put_contents($out, json_encode($builder->run(), JSON_PRETTY_PRINT));
|
||||
echo "ok\n";
|
||||
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||
use App\Filament\Resources\Exercises\Pages\EditExercise;
|
||||
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
|
||||
use App\Http\SignedLink;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Rückfallschutz für den neuen Objekttyp „Übung“: Wird nach einem Deploy auf den vorherigen Programmstand zurückgesetzt,
|
||||
* kennt dieser den neuen `kind`-Wert nicht. Die Zeilen werden hier mit dem Wert „exercise“ nachgestellt, den der neue
|
||||
* Stand schreiben wird. Der vorherige Stand darf nicht abstürzen, nichts offenlegen, was er nicht darstellen kann, und
|
||||
* beim Bearbeiten nichts verlieren.
|
||||
*/
|
||||
class RueckfallschutzTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const FOREIGN = 'art_von_morgen';
|
||||
|
||||
private ContentElementVersion $filmA;
|
||||
|
||||
private ContentElementVersion $filmB;
|
||||
|
||||
private ContentElementVersion $text;
|
||||
|
||||
private CompositionVersion $exercise;
|
||||
|
||||
private CompositionVersion $module;
|
||||
|
||||
private LicenseArticle $article;
|
||||
|
||||
private ArticleRelease $release;
|
||||
|
||||
private User $member;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
$this->buildProduct();
|
||||
}
|
||||
|
||||
public function test_the_kind_values_are_the_ones_this_program_state_knows(): void
|
||||
{
|
||||
$this->assertSame(['kombination', 'uebung', 'kurs', 'exercise'], CompositionKind::values());
|
||||
$this->assertNotContains(self::FOREIGN, CompositionKind::values());
|
||||
}
|
||||
|
||||
public function test_a_composition_of_an_unknown_kind_does_not_crash_loading_and_stays_hidden(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['Modul mit Übung'],
|
||||
Composition::query()->orderBy('designation')->pluck('designation')->all(),
|
||||
);
|
||||
$this->assertNull(CompositionVersion::query()->with('composition')->findOrFail($this->exercise->id)->composition);
|
||||
$this->assertNull(Composition::query()->find($this->exercise->composition_id));
|
||||
$this->assertSame(1, DB::table('compositions')->where('kind', self::FOREIGN)->count(), 'Die Zeile bleibt unverändert erhalten.');
|
||||
}
|
||||
|
||||
public function test_the_member_area_neither_crashes_nor_shows_what_it_cannot_present(): void
|
||||
{
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.library'))
|
||||
->assertOk()
|
||||
->assertSee('Modul mit Übung');
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.program', $this->module->composition_id))
|
||||
->assertOk()
|
||||
->assertSee('Modul mit Übung')
|
||||
->assertDontSee('Übung neuerer Stand')
|
||||
->assertDontSee('Einstiegsfilm')
|
||||
->assertDontSee('Alternativfilm')
|
||||
->assertDontSee('Durchführungstext');
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.program', $this->exercise->composition_id))
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_only_the_selected_variant_is_delivered_from_the_frozen_stand(): void
|
||||
{
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.article', $this->article))
|
||||
->assertOk()
|
||||
->assertSee('Einstiegsfilm')
|
||||
->assertDontSee('Alternativfilm');
|
||||
|
||||
$link = fn (ContentElementVersion $version): string => SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $this->article->id,
|
||||
'release' => $this->release->id,
|
||||
'version' => $version->id,
|
||||
'action' => 'ansehen',
|
||||
'reader' => $this->member->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($this->member)->get($link($this->filmB))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_the_previous_state_refuses_to_publish_what_it_cannot_resolve(): void
|
||||
{
|
||||
try {
|
||||
app(ArticleService::class)->publishRelease($this->article->fresh(), $this->module, 'Neuer Stand im alten Programmstand.');
|
||||
$this->fail('Ein Stand mit unbekanntem Bestandteil darf hier nicht entstehen.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString('Programmstand', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame(1, $this->article->releases()->count());
|
||||
|
||||
$other = app(ContentService::class)->createComposition('Anderes Modul', CompositionKind::Uebung);
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
app(ContentService::class)->publishComposition($other, [['role' => 'Übung', 'target' => $this->exercise]]);
|
||||
}
|
||||
|
||||
public function test_an_offer_is_not_activated_for_a_structure_with_an_unknown_part(): void
|
||||
{
|
||||
$offers = app(OfferService::class);
|
||||
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]);
|
||||
$offer = $offers->create('Angebot mit Übung');
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
$this->expectExceptionMessage('Programmstand');
|
||||
$offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], [
|
||||
'grant_kind' => 'auf_abruf',
|
||||
'composition_version_id' => $this->module->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_the_editor_of_a_structure_with_an_unknown_part_is_read_only_and_loses_nothing(): void
|
||||
{
|
||||
$module = Composition::query()->findOrFail($this->module->composition_id);
|
||||
$versions = $module->versions()->count();
|
||||
$members = DB::table('composition_members')->where('composition_version_id', $this->module->id)->count();
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditExercise::class, ['record' => $module->getKey()])
|
||||
->assertOk()
|
||||
->assertSee('neueren Programmversion');
|
||||
|
||||
$this->assertNotNull($component->instance()->schreibschutz());
|
||||
|
||||
$component->call('saveDraft');
|
||||
$this->assertNull($module->fresh()->working_draft, 'Es wird kein Entwurf geschrieben, der den Bestandteil auslässt.');
|
||||
|
||||
$component->call('armRelease')->assertSet('releaseArmed', false);
|
||||
$this->assertFalse($component->instance()->publishRevision());
|
||||
$component->call('discardDraft');
|
||||
|
||||
$this->assertSame($versions, $module->versions()->count());
|
||||
$this->assertSame($members, DB::table('composition_members')->where('composition_version_id', $this->module->id)->count());
|
||||
}
|
||||
|
||||
public function test_an_editor_with_only_known_parts_still_saves(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Kurzfilm'), null, ['file' => 'inhalte/kurz.mp4']);
|
||||
$plain = $content->createComposition('Normales Modul', CompositionKind::Uebung);
|
||||
$content->publishComposition($plain, [['role' => 'Film', 'target' => $film]]);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditExercise::class, ['record' => $plain->getKey()])
|
||||
->assertOk();
|
||||
|
||||
$this->assertNull($component->instance()->schreibschutz());
|
||||
$component->call('saveDraft');
|
||||
$this->assertNotNull($plain->fresh()->working_draft);
|
||||
}
|
||||
|
||||
public function test_the_staff_pages_around_the_structure_render_without_naming_the_unknown_part(): void
|
||||
{
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $this->filmA->content_element_id])
|
||||
->assertOk()
|
||||
->assertDontSee('Übung neuerer Stand');
|
||||
|
||||
$keeper = User::factory()->katalogverwalter()->create();
|
||||
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
Livewire::actingAs($keeper, 'staff')
|
||||
->test(ViewLicenseArticle::class, ['record' => $this->article->getKey()])
|
||||
->assertOk()
|
||||
->assertDontSee('Übung neuerer Stand');
|
||||
}
|
||||
|
||||
public function test_the_public_site_does_not_know_the_unknown_composition(): void
|
||||
{
|
||||
$this->get(route('public.program', $this->exercise->composition_id))->assertNotFound();
|
||||
$this->get(route('public.programs'))->assertOk()->assertDontSee('Übung neuerer Stand');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Modul mit einer verschachtelten Übung, deren Fassung zwei Filmvarianten und einen Text enthält. Veröffentlicht
|
||||
* wird nur die Variante A samt Text. Danach bekommt die Übung den Wert, den erst der neue Stand schreibt.
|
||||
*/
|
||||
private function buildProduct(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$this->filmA = $content->publishElementVersion($content->createElement('film', 'film', 'Einstiegsfilm'), null, ['file' => 'inhalte/a.mp4']);
|
||||
$this->filmB = $content->publishElementVersion($content->createElement('film', 'film', 'Alternativfilm'), null, ['file' => 'inhalte/b.mp4']);
|
||||
$this->text = $content->publishElementVersion($content->createElement('text', 'text', 'Durchführungstext'), 'Erst aufwärmen, dann üben.');
|
||||
|
||||
$this->exercise = $content->publishComposition(
|
||||
$content->createComposition('Übung neuerer Stand', CompositionKind::Kombination),
|
||||
[
|
||||
['role' => 'Einstieg Variante A', 'target' => $this->filmA],
|
||||
['role' => 'Einstieg Variante B', 'target' => $this->filmB],
|
||||
['role' => 'Durchführung', 'target' => $this->text],
|
||||
],
|
||||
null,
|
||||
null,
|
||||
['learning_goal' => 'Nein sagen üben'],
|
||||
);
|
||||
|
||||
$kind = EditorialContentKind::query()->where('slug', 'modul')->firstOrFail();
|
||||
$module = $content->createComposition('Modul mit Übung', CompositionKind::Uebung);
|
||||
$module->editorial_content_kind_id = $kind->id;
|
||||
$module->save();
|
||||
$this->module = $content->publishComposition($module, [['role' => 'Übung', 'target' => $this->exercise]]);
|
||||
|
||||
$articles = app(ArticleService::class);
|
||||
$this->article = $articles->create('modul-mit-uebung');
|
||||
$this->release = $articles->publishRelease($this->article, $this->module, 'Modul mit Übung.');
|
||||
|
||||
// Gewählt ist nur Variante A: Der Stand schreibt Film B nicht fest.
|
||||
DB::table('release_contents')
|
||||
->where('article_release_id', $this->release->id)
|
||||
->where('content_element_version_id', $this->filmB->id)
|
||||
->delete();
|
||||
|
||||
$offers = app(OfferService::class);
|
||||
$rights = $offers->createRightsProfile('Film und Text', 'ehrenamtlich', ['film' => ['streamen', 'laden'], 'text' => ['ansehen']]);
|
||||
$offer = $offers->create('Zugang');
|
||||
$offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']);
|
||||
|
||||
$this->member = User::factory()->create();
|
||||
app(GrantIssuer::class)->claim($this->member, $offer);
|
||||
app(CompositionDisplayRelease::class)->release($this->module, $this->member);
|
||||
|
||||
DB::table('compositions')->where('id', $this->exercise->composition_id)->update(['kind' => self::FOREIGN]);
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ExerciseImportRun;
|
||||
use App\Domain\Catalog\ExerciseSource;
|
||||
use App\Domain\Catalog\ExerciseSourceSnapshot;
|
||||
use App\Domain\Catalog\ShinkanImport;
|
||||
use App\Filament\Pages\Uebernahme;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Client\Factory;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\Support\BuildsExercises;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Übernahme aus Shinkan in den Übungsbestand, mit Beispieldaten im Format der Katalogausgabe (`catalog_document`).
|
||||
* Der Nachweis gilt dem heute gelieferten Teilumfang: Texte, Dauer, Ausstattung, Varianten und Medienmetadaten.
|
||||
*/
|
||||
class ShinkanUebernahmeTest extends TestCase
|
||||
{
|
||||
use BuildsExercises;
|
||||
use RefreshDatabase;
|
||||
|
||||
private const ID = '6f1c1c52-0a53-4f6b-8e0e-3f0c2f6b9a11';
|
||||
|
||||
private const VARIANT_A = '11111111-1111-4111-8111-111111111111';
|
||||
|
||||
private const VARIANT_B = '22222222-2222-4222-8222-222222222222';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config(['services.shinkan.url' => 'https://shinkan.test', 'services.shinkan.key' => 'geheim-fuer-den-test']);
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_a_first_call_records_each_exercise_once_without_creating_a_local_version(): void
|
||||
{
|
||||
$this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'added', 'content_hash' => 'h1']], 'c1');
|
||||
|
||||
$run = app(ShinkanImport::class)->fetch();
|
||||
|
||||
$this->assertSame('ok', $run->status);
|
||||
$this->assertSame('c1', $run->cursor);
|
||||
$this->assertSame(1, $run->added);
|
||||
$this->assertSame(1, ExerciseSource::query()->count());
|
||||
$this->assertSame(1, ExerciseSourceSnapshot::query()->count());
|
||||
$this->assertSame(0, Composition::query()->count(), 'Abrufen legt keine lokale Übung an.');
|
||||
}
|
||||
|
||||
public function test_the_same_content_fetched_again_creates_nothing_new(): void
|
||||
{
|
||||
$this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'added', 'content_hash' => 'h1']], 'c1');
|
||||
app(ShinkanImport::class)->fetch();
|
||||
|
||||
$this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'updated', 'content_hash' => 'h1']], 'c2');
|
||||
app(ShinkanImport::class)->fetch();
|
||||
app(ShinkanImport::class)->record($this->document('h1'));
|
||||
|
||||
$this->assertSame(1, ExerciseSourceSnapshot::query()->count());
|
||||
$this->assertSame('c2', ExerciseImportRun::query()->orderByDesc('id')->value('cursor'));
|
||||
}
|
||||
|
||||
public function test_adopting_creates_one_immutable_local_version_with_the_source_fields_and_variants(): void
|
||||
{
|
||||
$snapshot = app(ShinkanImport::class)->record($this->document('h1'));
|
||||
|
||||
$version = app(ShinkanImport::class)->adopt($snapshot);
|
||||
$again = app(ShinkanImport::class)->adopt($snapshot->fresh());
|
||||
|
||||
$this->assertSame($version->id, $again->id);
|
||||
$this->assertSame(1, $version->composition->versions()->count());
|
||||
$this->assertSame(CompositionKind::Exercise, $version->composition->kind);
|
||||
$this->assertSame('uebung', $version->composition->editorialContentKind->slug);
|
||||
$this->assertSame('Sicher stehen und Stopp sagen', $version->composition->display_title ?? $version->composition->designation);
|
||||
$this->assertSame('Kurz erklärt.', $version->composition->summary);
|
||||
$this->assertSame('Nein sagen üben', $version->learning_goal);
|
||||
$this->assertSame(10, $version->duration_minutes);
|
||||
$this->assertSame(15, $version->duration_max);
|
||||
$this->assertSame('Matten, Pratzen', $version->material_note);
|
||||
$this->assertSame($snapshot->id, $version->source_snapshot_id);
|
||||
$this->assertSame([self::VARIANT_A, self::VARIANT_B], $version->variants->pluck('key')->all());
|
||||
$this->assertSame(['quelle', 'quelle'], $version->variants->pluck('origin')->all());
|
||||
$this->assertSame(['Vorbereitung', 'Durchführung', 'Trainerhinweise', 'Abweichung der Durchführung'], $version->members->pluck('role')->all());
|
||||
$this->assertSame(['quelle'], $version->members->pluck('origin')->unique()->all());
|
||||
$this->assertSame(self::VARIANT_A, $version->members->last()->variant->key);
|
||||
$this->assertSame($version->composition_id, ExerciseSource::query()->firstOrFail()->composition_id);
|
||||
}
|
||||
|
||||
public function test_a_changed_variant_is_recognised_and_a_new_version_keeps_the_local_addition(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$first = $import->adopt($import->record($this->document('h1')));
|
||||
$film = $this->film('Eigenes Lara-und-Felix-Video');
|
||||
$content = app(ContentService::class);
|
||||
|
||||
// Lokale Ergänzung als neue lokale Fassung: eigenes Video in der Variante A.
|
||||
$members = $first->members->map(fn ($member): array => [
|
||||
'role' => $member->role, 'target' => $member->contentElementVersion, 'variant' => $member->variant?->key, 'origin' => $member->origin,
|
||||
])->all();
|
||||
$members[] = ['role' => 'Eigenes Video', 'target' => $film, 'variant' => self::VARIANT_A, 'requirement' => 'ergaenzend', 'origin' => 'lokal'];
|
||||
$second = $content->publishComposition($first->composition, $members, null, 'Ergänzt', [], $first->variants->map(fn ($v): array => [
|
||||
'key' => $v->key, 'name' => $v->name, 'description' => $v->description, 'origin' => $v->origin,
|
||||
])->all());
|
||||
|
||||
$changed = $this->document('h2');
|
||||
$changed['variants'][0]['execution_changes'] = 'Mit Abstand von zwei Armlängen.';
|
||||
$source = ExerciseSource::query()->firstOrFail();
|
||||
$this->assertSame('uebernommen', $import->state($source->fresh()));
|
||||
|
||||
$snapshot = $import->record($changed);
|
||||
|
||||
$this->assertSame('geaendert', $import->state($source->fresh()));
|
||||
$third = $import->adopt($snapshot);
|
||||
|
||||
$this->assertSame(3, $third->number);
|
||||
$local = $third->members->where('origin', 'lokal');
|
||||
$this->assertSame(['Eigenes Video'], $local->pluck('role')->all());
|
||||
$this->assertSame(self::VARIANT_A, $local->first()->variant->key);
|
||||
$this->assertSame('ergaenzend', $local->first()->requirement);
|
||||
$this->assertStringContainsString('zwei Armlängen', $third->members->firstWhere('role', 'Abweichung der Durchführung')->contentElementVersion->body);
|
||||
$this->assertSame('uebernommen', $import->state($source->fresh()));
|
||||
// Die älteren Fassungen bleiben unverändert.
|
||||
$this->assertSame(4, $first->fresh()->members()->count());
|
||||
$this->assertSame(5, $second->fresh()->members()->count());
|
||||
}
|
||||
|
||||
public function test_the_unchanged_text_of_a_source_section_keeps_the_same_text_version(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$first = $import->adopt($import->record($this->document('h1')));
|
||||
$changed = $this->document('h2');
|
||||
$changed['variants'][0]['execution_changes'] = 'Anders.';
|
||||
$second = $import->adopt($import->record($changed));
|
||||
|
||||
$this->assertSame(
|
||||
$first->members->firstWhere('role', 'Durchführung')->content_element_version_id,
|
||||
$second->members->firstWhere('role', 'Durchführung')->content_element_version_id,
|
||||
);
|
||||
$this->assertNotSame(
|
||||
$first->members->firstWhere('role', 'Abweichung der Durchführung')->content_element_version_id,
|
||||
$second->members->firstWhere('role', 'Abweichung der Durchführung')->content_element_version_id,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_a_failed_call_keeps_the_stored_state_and_the_cursor_and_names_no_secret(): void
|
||||
{
|
||||
$this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'added', 'content_hash' => 'h1']], 'c1');
|
||||
app(ShinkanImport::class)->fetch();
|
||||
|
||||
$this->freshHttp();
|
||||
Http::fake([
|
||||
'shinkan.test/api/distribution/v1/catalog/*' => Http::response(['code' => 'boom'], 500),
|
||||
'shinkan.test/api/distribution/v1/catalog*' => Http::response([
|
||||
'exercises' => [['source_id' => self::ID, 'title' => 'x', 'content_hash' => 'h2']],
|
||||
'changes' => [['source_id' => self::ID, 'change' => 'updated', 'content_hash' => 'h2']],
|
||||
'next_cursor' => 'c2',
|
||||
]),
|
||||
]);
|
||||
|
||||
$run = app(ShinkanImport::class)->fetch();
|
||||
|
||||
$this->assertSame('fehler', $run->status);
|
||||
$this->assertStringContainsString('Status 500', $run->error);
|
||||
$this->assertStringNotContainsString('geheim-fuer-den-test', (string) $run->error);
|
||||
$this->assertStringNotContainsString('shinkan.test', (string) $run->error);
|
||||
$this->assertSame(1, ExerciseSourceSnapshot::query()->count());
|
||||
|
||||
// Der nächste Abruf beginnt wieder beim letzten erfolgreichen Cursor.
|
||||
$this->fake([$this->document('h2')], [['source_id' => self::ID, 'change' => 'updated', 'content_hash' => 'h2']], 'c2');
|
||||
$this->assertSame('ok', app(ShinkanImport::class)->fetch()->status);
|
||||
$this->assertSame(2, ExerciseSourceSnapshot::query()->count());
|
||||
Http::assertSent(fn ($request): bool => str_contains($request->url(), 'cursor=c1'));
|
||||
}
|
||||
|
||||
public function test_an_unconfigured_connection_is_reported_without_a_call(): void
|
||||
{
|
||||
config(['services.shinkan.url' => null, 'services.shinkan.key' => null]);
|
||||
Http::fake();
|
||||
|
||||
$run = app(ShinkanImport::class)->fetch();
|
||||
|
||||
$this->assertSame('fehler', $run->status);
|
||||
$this->assertStringContainsString('nicht eingerichtet', $run->error);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_hiding_at_the_source_marks_only_the_availability_and_leaves_local_use_alone(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$version = $import->adopt($import->record($this->document('h1')));
|
||||
$module = $this->moduleWith('Modul', $version, [self::VARIANT_A]);
|
||||
$articles = app(ArticleService::class);
|
||||
$release = $articles->publishRelease($articles->create('modul-shinkan'), $module, 'Mit Shinkan-Übung.');
|
||||
|
||||
$this->fake([], [['source_id' => self::ID, 'change' => 'removed']], 'c9', listed: []);
|
||||
$run = app(ShinkanImport::class)->fetch();
|
||||
|
||||
$source = ExerciseSource::query()->firstOrFail();
|
||||
$this->assertSame(1, $run->removed);
|
||||
$this->assertSame('nicht_mehr_bereitgestellt', $import->state($source));
|
||||
$this->assertSame('veroeffentlicht', $release->fresh()->status->value);
|
||||
$this->assertSame(1, $version->composition->fresh()->versions()->count());
|
||||
}
|
||||
|
||||
public function test_source_media_metadata_never_becomes_deliverable_content(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$version = $import->adopt($import->record($this->document('h1')));
|
||||
$module = $this->moduleWith('Modul', $version);
|
||||
$articles = app(ArticleService::class);
|
||||
$release = $articles->publishRelease($articles->create('modul-medien'), $module, 'Nur Texte.');
|
||||
|
||||
$this->assertNotEmpty($release->contents);
|
||||
$this->assertSame(['text'], $release->contents->map(fn ($c): string => $c->elementVersion->element->output_class)->unique()->all());
|
||||
$this->assertStringNotContainsString('Quellvideo', json_encode($release->contents->map->path->all()));
|
||||
}
|
||||
|
||||
public function test_the_page_lists_states_and_adopts_on_purpose(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$import->record($this->document('h1'));
|
||||
$user = User::factory()->redakteur()->create();
|
||||
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
$component = Livewire::actingAs($user, 'staff')
|
||||
->test(Uebernahme::class)
|
||||
->assertOk()
|
||||
->assertSee('Sicher stehen und Stopp sagen')
|
||||
->assertSee('Neu bei der Quelle')
|
||||
->assertSee('Quellvideo (video)')
|
||||
->assertSee('2 Varianten');
|
||||
|
||||
$snapshot = ExerciseSourceSnapshot::query()->firstOrFail();
|
||||
$component->call('adopt', $snapshot->id)->assertSee('Fassung 1 ist lokal angelegt')->assertSee('Übernommen')->assertSee('Lokale Übung öffnen');
|
||||
$this->assertNotNull($snapshot->fresh()->adopted_version_id);
|
||||
}
|
||||
|
||||
private function freshHttp(): void
|
||||
{
|
||||
Http::swap(new Factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $details
|
||||
* @param list<array<string, mixed>> $changes
|
||||
* @param list<array<string, mixed>>|null $listed
|
||||
*/
|
||||
private function fake(array $details, array $changes, string $cursor, ?array $listed = null): void
|
||||
{
|
||||
$listing = $listed ?? array_map(fn (array $d): array => ['source_id' => $d['source_id'], 'title' => $d['title'], 'content_hash' => $d['content_hash']], $details);
|
||||
$fakes = [];
|
||||
|
||||
foreach ($details as $detail) {
|
||||
$fakes['shinkan.test/api/distribution/v1/catalog/'.$detail['source_id']] = Http::response($detail);
|
||||
}
|
||||
|
||||
$fakes['shinkan.test/api/distribution/v1/catalog*'] = Http::response(['exercises' => $listing, 'changes' => $changes, 'next_cursor' => $cursor]);
|
||||
$this->freshHttp();
|
||||
Http::fake($fakes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function document(string $hash): array
|
||||
{
|
||||
return [
|
||||
'source_id' => self::ID,
|
||||
'title' => 'Sicher stehen und Stopp sagen',
|
||||
'summary' => 'Kurz erklärt.',
|
||||
'goal' => 'Nein sagen üben',
|
||||
'execution' => "Die Kinder stehen sicher.\n\n- Stimme einsetzen\n- Stopp sagen",
|
||||
'preparation' => 'Matten auslegen.',
|
||||
'trainer_notes' => 'Auf Abstand achten.',
|
||||
'equipment' => 'Matten, Pratzen',
|
||||
'duration_min' => 10,
|
||||
'duration_max' => 15,
|
||||
'variants' => [
|
||||
['id' => self::VARIANT_A, 'name' => 'Mit Partner', 'description' => 'Zu zweit', 'execution_changes' => 'Mit Partner üben.', 'sequence_order' => 1],
|
||||
['id' => self::VARIANT_B, 'name' => 'Allein', 'description' => 'Einzeln', 'execution_changes' => '', 'sequence_order' => 2],
|
||||
],
|
||||
'media' => [['id' => '33333333-3333-4333-8333-333333333333', 'media_type' => 'video', 'title' => 'Quellvideo', 'sort_order' => 1]],
|
||||
'content_hash' => $hash,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ExerciseGuide;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\RightsProfileVersion;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Domain\Entitlement\MediaDelivery;
|
||||
use App\Http\SignedLink;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\Support\BuildsExercises;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Durchstich der Ausgabe: Eine Übung steckt in einem verkauften Modul und in einem verkauften Programm. Die berechtigte
|
||||
* Kursleitung sieht die im Stand gebundene Fassung und lädt das PDF; eine Sperre trifft nur das Medium.
|
||||
*/
|
||||
class UebungAusgabeTest extends TestCase
|
||||
{
|
||||
use BuildsExercises;
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
private array $exercise;
|
||||
|
||||
private LicenseArticle $moduleArticle;
|
||||
|
||||
private ArticleRelease $moduleRelease;
|
||||
|
||||
private LicenseArticle $programArticle;
|
||||
|
||||
private ArticleRelease $programRelease;
|
||||
|
||||
private User $member;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->exercise = $this->exercise();
|
||||
$module = $this->moduleWith('Modul Stopp', $this->exercise['version'], ['a']);
|
||||
$program = $this->moduleWith('Programm Stopp', $this->exercise['version'], ['b'], CompositionKind::Kurs);
|
||||
$articles = app(ArticleService::class);
|
||||
$this->moduleArticle = $articles->create('modul-stopp');
|
||||
$this->moduleRelease = $articles->publishRelease($this->moduleArticle, $module, 'Modul.');
|
||||
$this->programArticle = $articles->create('programm-stopp');
|
||||
$this->programRelease = $articles->publishRelease($this->programArticle, $program, 'Programm.');
|
||||
$this->member = $this->grantTo($this->full(), [$this->moduleArticle, $this->programArticle]);
|
||||
}
|
||||
|
||||
public function test_the_trainer_reads_the_bound_version_with_the_offered_variant_only(): void
|
||||
{
|
||||
$this->actingAs($this->member)
|
||||
->get($this->page($this->moduleArticle, $this->moduleRelease))
|
||||
->assertOk()
|
||||
->assertSee('Stopp sagen')
|
||||
->assertSee('Nein sagen und Abstand halten')
|
||||
->assertSee('Sicher stehen')
|
||||
->assertSee('Variante A: Der Film zeigt die Situation.')
|
||||
->assertSee('Lizenzkopie LK-')
|
||||
->assertDontSee('Variante B: Ohne Film mit dem Arbeitsblatt.')
|
||||
->assertSee('Als PDF herunterladen');
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get($this->page($this->programArticle, $this->programRelease))
|
||||
->assertOk()
|
||||
->assertSee('Variante B: Ohne Film mit dem Arbeitsblatt.')
|
||||
->assertDontSee('Variante A: Der Film zeigt die Situation.');
|
||||
}
|
||||
|
||||
public function test_the_module_page_leads_to_the_bound_exercise_not_to_the_newest_one(): void
|
||||
{
|
||||
$display = app(CompositionDisplayRelease::class);
|
||||
$display->release($this->moduleRelease->rootCompositionVersion, $this->member);
|
||||
$display->release($this->programRelease->rootCompositionVersion, $this->member);
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.program', $this->moduleRelease->rootCompositionVersion->composition_id))
|
||||
->assertOk()
|
||||
->assertSee(route('member.exercise', ['article' => $this->moduleArticle, 'release' => $this->moduleRelease, 'path' => '1']), false);
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get(route('member.program', $this->programRelease->rootCompositionVersion->composition_id))
|
||||
->assertOk()
|
||||
->assertSee(route('member.exercise', ['article' => $this->programArticle, 'release' => $this->programRelease, 'path' => '1']), false);
|
||||
}
|
||||
|
||||
public function test_the_pdf_carries_the_same_version_the_marking_and_the_delivery_record(): void
|
||||
{
|
||||
$response = $this->actingAs($this->member)->get($this->pdf($this->moduleArticle, $this->moduleRelease, 'a'));
|
||||
|
||||
$response->assertOk()->assertHeader('Content-Type', 'application/pdf');
|
||||
$this->assertStringContainsString('no-store', (string) $response->headers->get('Cache-Control'));
|
||||
$text = $this->pdfText($response->getContent());
|
||||
|
||||
$this->assertStringContainsString('Stopp sagen', $text);
|
||||
$this->assertStringContainsString('Variante A: Der Film zeigt die Situation.', $text);
|
||||
$this->assertStringContainsString('Sicher stehen', $text);
|
||||
$this->assertStringNotContainsString('Variante B:', $text);
|
||||
$this->assertStringContainsString('Lizenziert für '.$this->member->name.' · Lizenzkopie LK-', $text);
|
||||
$this->assertStringContainsString('Seite 1', $text);
|
||||
$this->assertStringContainsString('Lizenzkopie '.$response->headers->get('X-License-Copy'), $response->getContent(), 'Die Kennung steht auch in den Metadaten.');
|
||||
|
||||
$rows = MediaDelivery::query()->where('format', 'pdf')->get();
|
||||
$this->assertNotEmpty($rows);
|
||||
$this->assertSame(['k2'], $rows->pluck('marking')->unique()->all());
|
||||
$this->assertSame(['laden'], $rows->pluck('action')->unique()->all());
|
||||
$this->assertSame($this->exercise['version']->id, $rows->first()->composition_version_id);
|
||||
$this->assertSame(hash('sha256', $response->getContent()), $rows->first()->checksum);
|
||||
}
|
||||
|
||||
public function test_the_pdf_runs_over_several_pages_and_keeps_special_characters_readable(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$long = implode("\n\n", array_map(fn (int $n): string => "Absatz $n: ".str_repeat('Abstand halten und Stopp sagen. ', 12), range(1, 30)));
|
||||
$text = $this->section('Lang', "Gewaltprävention → Stopp ≥ 2 m Abstand; Łódź, naïve «Café».\n\n## Ablauf\n\n1. Erst aufwärmen\n2. Dann üben\n\n- Matten\n- Pratzen\n\n".$long);
|
||||
$composition = $this->exerciseComposition('Lange Übung');
|
||||
$version = $content->publishComposition($composition, [['role' => 'Durchführung', 'target' => $text]], null, null, ['learning_goal' => 'Lang']);
|
||||
$module = $this->moduleWith('Modul lang', $version);
|
||||
$articles = app(ArticleService::class);
|
||||
$article = $articles->create('lang');
|
||||
$release = $articles->publishRelease($article, $module, 'Lang.');
|
||||
$member = $this->grantTo($this->full(), [$article]);
|
||||
|
||||
$response = $this->actingAs($member)->get($this->pdf($article, $release, null, $member));
|
||||
$response->assertOk();
|
||||
$pdf = $this->pdfText($response->getContent());
|
||||
|
||||
$this->assertGreaterThan(2, substr_count($response->getContent(), '/Type /Page /Parent'));
|
||||
$this->assertStringContainsString('Seite 1', $pdf);
|
||||
$this->assertStringContainsString('Seite 3', $pdf);
|
||||
$this->assertStringContainsString('Gewaltprävention -> Stopp >= 2 m Abstand', $pdf);
|
||||
$this->assertStringContainsString('Lódz', $pdf);
|
||||
$this->assertStringContainsString('Ablauf', $pdf);
|
||||
$this->assertStringContainsString('1.
|
||||
Erst aufwärmen', $pdf);
|
||||
$this->assertStringContainsString('•', $pdf);
|
||||
$this->assertSame(substr_count($response->getContent(), '/Type /Page /Parent'), preg_match_all('/Lizenzkopie LK-[0-9A-F]{12}/', $pdf), 'Jede Seite trägt die Fußzeile.');
|
||||
}
|
||||
|
||||
public function test_an_account_without_a_license_gets_neither_the_guide_nor_the_pdf(): void
|
||||
{
|
||||
$stranger = User::factory()->create();
|
||||
|
||||
$this->actingAs($stranger)->get($this->page($this->moduleArticle, $this->moduleRelease))->assertForbidden();
|
||||
$this->actingAs($stranger)->get($this->pdf($this->moduleArticle, $this->moduleRelease, 'a', $stranger))->assertForbidden();
|
||||
$this->actingAs($this->member)->get(route('member.exercise.pdf', ['article' => $this->moduleArticle, 'release' => $this->moduleRelease, 'path' => '1']))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_without_the_download_right_the_guide_is_readable_but_the_pdf_is_refused(): void
|
||||
{
|
||||
$readOnly = $this->grantTo($this->profile(['film' => ['streamen'], 'text' => ['ansehen'], 'document' => ['ansehen']]), [$this->moduleArticle]);
|
||||
|
||||
$this->actingAs($readOnly)
|
||||
->get($this->page($this->moduleArticle, $this->moduleRelease))
|
||||
->assertOk()
|
||||
->assertSee('Variante A: Der Film zeigt die Situation.')
|
||||
->assertDontSee('Als PDF herunterladen');
|
||||
$this->actingAs($readOnly)->get($this->pdf($this->moduleArticle, $this->moduleRelease, 'a', $readOnly))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_a_supplementary_medium_that_is_blocked_leaves_the_guide_and_the_pdf_usable(): void
|
||||
{
|
||||
app(ContentService::class)->block($this->exercise['sheetB'], 'Rechte zurückgezogen.');
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get($this->page($this->programArticle, $this->programRelease))
|
||||
->assertOk()
|
||||
->assertSee('Variante B: Ohne Film mit dem Arbeitsblatt.')
|
||||
->assertSee('Dieses ergänzende Material ist derzeit nicht verfügbar')
|
||||
->assertDontSee('derzeit nicht vollständig durchführbar');
|
||||
|
||||
$pdf = $this->pdfText($this->actingAs($this->member)->get($this->pdf($this->programArticle, $this->programRelease, 'b'))->assertOk()->getContent());
|
||||
$this->assertStringContainsString('Variante B: Ohne Film mit dem Arbeitsblatt.', $pdf);
|
||||
$this->assertStringNotContainsString('Arbeitsblatt B', $pdf);
|
||||
|
||||
$direct = SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $this->programArticle->id,
|
||||
'release' => $this->programRelease->id,
|
||||
'version' => $this->exercise['sheetB']->id,
|
||||
'action' => 'ansehen',
|
||||
'reader' => $this->member->id,
|
||||
]);
|
||||
$this->actingAs($this->member)->get($direct)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_a_required_medium_that_is_blocked_marks_only_its_variant_and_keeps_the_instructions(): void
|
||||
{
|
||||
$everything = $this->moduleWith('Modul alle', $this->exercise['version']);
|
||||
$articles = app(ArticleService::class);
|
||||
$article = $articles->create('alle');
|
||||
$release = $articles->publishRelease($article, $everything, 'Alle Varianten.');
|
||||
$member = $this->grantTo($this->full(), [$article]);
|
||||
|
||||
app(ContentService::class)->block($this->exercise['filmA'], 'Rechte zurückgezogen.');
|
||||
|
||||
$this->actingAs($member)
|
||||
->get($this->page($article, $release))
|
||||
->assertOk()
|
||||
->assertSee('Variante A: Der Film zeigt die Situation.')
|
||||
->assertSee('Diese Variante ist derzeit nicht vollständig durchführbar')
|
||||
->assertSee('Stopp sagen · Film A ist nicht verfügbar');
|
||||
|
||||
$this->actingAs($member)
|
||||
->get($this->page($article, $release).'?variante=b')
|
||||
->assertOk()
|
||||
->assertSee('Variante B: Ohne Film mit dem Arbeitsblatt.')
|
||||
->assertDontSee('Diese Variante ist derzeit nicht vollständig durchführbar');
|
||||
|
||||
$this->actingAs($member)->get($this->pdf($article, $release, 'a', $member))->assertOk();
|
||||
$direct = SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'version' => $this->exercise['filmA']->id,
|
||||
'action' => 'streamen',
|
||||
'reader' => $member->id,
|
||||
]);
|
||||
$this->actingAs($member)->get($direct)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_the_stand_keeps_what_was_chosen_when_a_newer_exercise_version_appears(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$revised = $content->publishElementVersion($this->exercise['textA']->element, 'Variante A, später überarbeitet.');
|
||||
$content->publishComposition($this->exercise['version']->composition, [
|
||||
['role' => 'Durchführung A', 'target' => $revised, 'variant' => 'a'],
|
||||
], null, null, ['learning_goal' => 'Neu'], [['key' => 'a', 'name' => 'Mit Film']]);
|
||||
|
||||
$this->actingAs($this->member)
|
||||
->get($this->page($this->moduleArticle, $this->moduleRelease))
|
||||
->assertOk()
|
||||
->assertSee('Variante A: Der Film zeigt die Situation.')
|
||||
->assertDontSee('später überarbeitet')
|
||||
->assertSee('Nein sagen und Abstand halten');
|
||||
}
|
||||
|
||||
public function test_a_wrong_path_is_not_found(): void
|
||||
{
|
||||
$this->actingAs($this->member)->get(route('member.exercise', ['article' => $this->moduleArticle, 'release' => $this->moduleRelease, 'path' => '7']))->assertNotFound();
|
||||
$this->actingAs($this->member)->get(route('member.exercise', ['article' => $this->moduleArticle, 'release' => $this->programRelease, 'path' => '1']))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_the_path_finds_the_place_even_when_the_exercise_sits_deeper(): void
|
||||
{
|
||||
$inner = $this->moduleWith('Innen', $this->exercise['version'], ['a']);
|
||||
$outer = $this->moduleWith('Außen', $inner, null, CompositionKind::Kurs);
|
||||
$guide = app(ExerciseGuide::class);
|
||||
|
||||
$this->assertSame('1-1', $guide->pathTo($outer, $this->exercise['version']->id));
|
||||
$this->assertNull($guide->pathTo($outer, 999999));
|
||||
}
|
||||
|
||||
private function page(LicenseArticle $article, ArticleRelease $release): string
|
||||
{
|
||||
return route('member.exercise', ['article' => $article, 'release' => $release, 'path' => '1']);
|
||||
}
|
||||
|
||||
private function pdf(LicenseArticle $article, ArticleRelease $release, ?string $variant, ?User $reader = null): string
|
||||
{
|
||||
return SignedLink::temporary('member.exercise.pdf', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'path' => '1',
|
||||
'variante' => $variant,
|
||||
'reader' => ($reader ?? $this->member)->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function full(): RightsProfileVersion
|
||||
{
|
||||
return $this->profile(['film' => ['streamen', 'laden'], 'text' => ['ansehen', 'laden'], 'document' => ['ansehen', 'laden']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, list<string>> $capabilities
|
||||
*/
|
||||
private function profile(array $capabilities): RightsProfileVersion
|
||||
{
|
||||
return app(OfferService::class)->createRightsProfile('Profil '.md5(json_encode($capabilities)), 'ehrenamtlich', $capabilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<LicenseArticle> $articles
|
||||
*/
|
||||
private function grantTo(RightsProfileVersion $rights, array $articles): User
|
||||
{
|
||||
$offers = app(OfferService::class);
|
||||
$offer = $offers->create('Angebot '.uniqid());
|
||||
$offers->activate($offer, array_map(fn (LicenseArticle $article): array => ['target' => $article->fresh(), 'rights' => $rights], $articles), ['grant_kind' => 'auf_abruf']);
|
||||
$user = User::factory()->create();
|
||||
app(GrantIssuer::class)->claim($user, $offer);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/** Text der Seiten aus dem unkomprimierten Inhalt; Windows-1252 wird nach UTF-8 gewandelt. */
|
||||
private function pdfText(string $pdf): string
|
||||
{
|
||||
preg_match_all('/Td \((.*)\) Tj ET$/m', $pdf, $matches);
|
||||
|
||||
return implode("\n", array_map(
|
||||
fn (string $line): string => mb_convert_encoding(str_replace(['\\(', '\\)', '\\\\'], ['(', ')', '\\'], $line), 'UTF-8', 'Windows-1252'),
|
||||
$matches[1],
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Filament\Resources\Courses\Pages\EditCourse;
|
||||
use App\Filament\Resources\Exercises\Pages\EditExercise;
|
||||
use App\Filament\Resources\Practices\Pages\EditPractice;
|
||||
use App\Filament\Resources\Practices\Pages\ListPractices;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\Support\BuildsExercises;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Die Redaktion legt eine Übung im gemeinsamen Aufbauarbeitsplatz an, pflegt Varianten und Verwendung und baut sie in
|
||||
* ein Modul und ein Programm ein.
|
||||
*/
|
||||
class UebungEditorTest extends TestCase
|
||||
{
|
||||
use BuildsExercises;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_the_exercise_list_offers_creating_an_exercise_with_its_editorial_kind(): void
|
||||
{
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(ListPractices::class)
|
||||
->assertOk()
|
||||
->assertSee('Übung anlegen')
|
||||
->mountAction('createExercise')
|
||||
->setActionData(['designation' => 'Stopp sagen'])
|
||||
->callMountedAction();
|
||||
|
||||
$practice = Composition::query()->where('designation', 'Stopp sagen')->firstOrFail();
|
||||
$this->assertSame(CompositionKind::Exercise, $practice->kind);
|
||||
$this->assertSame('uebung', $practice->editorialContentKind->slug);
|
||||
}
|
||||
|
||||
public function test_an_exercise_with_variants_is_built_released_and_kept_in_the_draft_across_a_context_switch(): void
|
||||
{
|
||||
$practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise);
|
||||
$film = $this->film('Demonstration');
|
||||
$sheet = $this->sheet('Arbeitsblatt');
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPractice::class, ['record' => $practice->getKey()])
|
||||
->assertOk()
|
||||
->set('learningGoal', 'Nein sagen üben')
|
||||
->set('durationMinutes', '10')
|
||||
->set('durationMax', '15')
|
||||
->set('prerequisites', 'Keine')
|
||||
->set('newVariantName', 'Mit Film')
|
||||
->call('addVariant')
|
||||
->set('newVariantName', 'Ohne Film')
|
||||
->call('addVariant')
|
||||
->set('newTextTitle', 'Einstieg')
|
||||
->set('newTextBody', "Gemeinsamer Einstieg.\n\n- Sicher stehen")
|
||||
->call('addText')
|
||||
->call('addPart', 'element:'.$film->id)
|
||||
->call('addPart', 'element:'.$film->id)
|
||||
->call('addPart', 'element:'.$sheet->id);
|
||||
|
||||
$this->assertSame(['mit-film', 'ohne-film'], array_column($component->get('variants'), 'key'));
|
||||
$this->assertCount(4, $component->get('members'), 'Dasselbe Medium darf in zwei Varianten vorkommen.');
|
||||
|
||||
$component
|
||||
->call('setMemberVariant', 1, 'mit-film')
|
||||
->call('setMemberVariant', 2, 'ohne-film')
|
||||
->call('setMemberVariant', 3, 'ohne-film')
|
||||
->call('setMemberRequirement', 3, 'ergaenzend')
|
||||
->call('saveDraft')
|
||||
->assertSee('Mit Film');
|
||||
|
||||
// Kontextwechsel: Der Entwurf lädt die Zuordnungen wieder.
|
||||
$again = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPractice::class, ['record' => $practice->getKey()]);
|
||||
$this->assertSame(['mit-film', 'ohne-film'], array_column($again->get('variants'), 'key'));
|
||||
$this->assertSame([null, 'mit-film', 'ohne-film', 'ohne-film'], array_column($again->get('members'), 'variant'));
|
||||
$this->assertSame('ergaenzend', $again->get('members')[3]['requirement']);
|
||||
|
||||
$again->call('armRelease')->set('releaseConsent', true)->call('publishRevision');
|
||||
|
||||
$version = $practice->fresh()->versions()->firstOrFail()->load('variants', 'members.variant');
|
||||
$this->assertSame(['mit-film', 'ohne-film'], $version->variants->pluck('key')->all());
|
||||
$this->assertSame(15, $version->duration_max);
|
||||
$this->assertSame('Keine', $version->prerequisites);
|
||||
$this->assertSame([null, 'mit-film', 'ohne-film', 'ohne-film'], $version->members->map(fn ($m) => $m->variant?->key)->all());
|
||||
$this->assertSame('ergaenzend', $version->members[3]->requirement);
|
||||
$this->assertNotNull($version->structure_hash);
|
||||
}
|
||||
|
||||
public function test_a_changed_variant_or_usage_counts_as_a_change_even_when_the_media_stay_the_same(): void
|
||||
{
|
||||
$exercise = $this->exercise('Wechsel');
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPractice::class, ['record' => $exercise['version']->composition_id]);
|
||||
|
||||
$this->assertSame('Die freigegebene Fassung ist unverändert. Es entsteht keine neue Fassung.', $component->call('publishRevision')->get('feedback'));
|
||||
|
||||
$component->call('setMemberRequirement', 2, 'ergaenzend')->call('armRelease')->assertSet('releaseArmed', true);
|
||||
$component->call('publishRevision');
|
||||
$this->assertSame(2, $exercise['version']->composition->versions()->count());
|
||||
$this->assertNotSame($exercise['version']->fresh()->structure_hash, $exercise['version']->composition->versions()->orderByDesc('number')->first()->structure_hash);
|
||||
}
|
||||
|
||||
public function test_a_module_and_a_program_take_the_exercise_with_a_chosen_variant_and_remember_it(): void
|
||||
{
|
||||
$exercise = $this->exercise('Einbau');
|
||||
|
||||
foreach ([[CompositionKind::Uebung, EditExercise::class], [CompositionKind::Kurs, EditCourse::class]] as [$kind, $page]) {
|
||||
$host = app(EditorialCatalog::class)->create('Produkt '.$kind->value, $kind);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test($page, ['record' => $host->getKey()])
|
||||
->call('addPart', 'composition:'.$exercise['version']->id);
|
||||
|
||||
$this->assertSame([['key' => 'a', 'name' => 'Mit Film'], ['key' => 'b', 'name' => 'Ohne Film']], $component->instance()->offeredVariants('composition:'.$exercise['version']->id));
|
||||
|
||||
$component
|
||||
->call('toggleVariantSelection', 0, 'a')
|
||||
->call('saveDraft');
|
||||
|
||||
$reloaded = Livewire::actingAs($this->editor(), 'staff')->test($page, ['record' => $host->getKey()]);
|
||||
$this->assertSame(['b'], $reloaded->get('members')[0]['selection'], 'Die Auswahl bleibt beim erneuten Öffnen erhalten.');
|
||||
|
||||
$reloaded->call('armRelease')->call('publishRevision');
|
||||
$member = $host->fresh()->versions()->firstOrFail()->members()->firstOrFail();
|
||||
$this->assertSame(['b'], $member->variant_selection);
|
||||
$this->assertInstanceOf(CompositionVersion::class, $member->nestedCompositionVersion);
|
||||
}
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentResolver;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\Support\BuildsExercises;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UebungFassungTest extends TestCase
|
||||
{
|
||||
use BuildsExercises;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_an_exercise_version_keeps_its_fields_variants_and_placement(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$version = $exercise['version']->fresh(['variants', 'members.variant']);
|
||||
|
||||
$this->assertSame(CompositionKind::Exercise, $version->composition->kind);
|
||||
$this->assertSame(['a', 'b'], $version->variants->pluck('key')->all());
|
||||
$this->assertSame(20, $version->duration_max);
|
||||
$this->assertSame('Keine', $version->prerequisites);
|
||||
$this->assertNull($version->members[0]->variant, 'Der Einstieg ist gemeinsam.');
|
||||
$this->assertSame('a', $version->members[2]->variant->key);
|
||||
$this->assertSame('ergaenzend', $version->members[4]->requirement);
|
||||
$this->assertNotNull($version->structure_hash);
|
||||
$this->assertSame($version->structure_hash, $version->attestations()->first()->structure_hash);
|
||||
}
|
||||
|
||||
public function test_the_selection_decides_which_media_a_stand_freezes(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$withFilm = $this->moduleWith('Modul mit Film', $exercise['version'], ['a']);
|
||||
$withoutFilm = $this->moduleWith('Modul ohne Film', $exercise['version'], ['b']);
|
||||
$articles = app(ArticleService::class);
|
||||
$first = $articles->publishRelease($articles->create('mit-film'), $withFilm, 'Filmvariante.');
|
||||
$second = $articles->publishRelease($articles->create('ohne-film'), $withoutFilm, 'Variante ohne Film.');
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[$exercise['intro']->id, $exercise['textA']->id, $exercise['filmA']->id],
|
||||
$first->contents->pluck('content_element_version_id')->all(),
|
||||
);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[$exercise['intro']->id, $exercise['textB']->id, $exercise['sheetB']->id],
|
||||
$second->contents->pluck('content_element_version_id')->all(),
|
||||
);
|
||||
$this->assertSame(
|
||||
['erforderlich', 'ergaenzend'],
|
||||
$second->contents->whereIn('content_element_version_id', [$exercise['textB']->id, $exercise['sheetB']->id])->sortBy('position')->pluck('requirement')->map(fn ($r, $i) => $i === 0 ? 'erforderlich' : $r)->values()->all(),
|
||||
);
|
||||
$this->assertSame('ergaenzend', $second->contents->firstWhere('content_element_version_id', $exercise['sheetB']->id)->requirement);
|
||||
$this->assertSame('b', $second->contents->firstWhere('content_element_version_id', $exercise['sheetB']->id)->variant_key);
|
||||
$this->assertNull($second->contents->firstWhere('content_element_version_id', $exercise['intro']->id)->variant_key);
|
||||
}
|
||||
|
||||
public function test_without_a_selection_all_variants_are_offered(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$all = $this->moduleWith('Modul mit allen', $exercise['version']);
|
||||
|
||||
$this->assertCount(5, app(ContentResolver::class)->expand($all));
|
||||
}
|
||||
|
||||
public function test_the_same_medium_in_the_common_part_and_a_variant_and_directly_in_the_product_is_frozen_each_time(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $this->film('Demonstration');
|
||||
$composition = $this->exerciseComposition('Doppelt');
|
||||
$exercise = $content->publishComposition($composition, [
|
||||
['role' => 'Einstieg', 'target' => $film],
|
||||
['role' => 'Film in A', 'target' => $film, 'variant' => 'a'],
|
||||
['role' => 'Film in B', 'target' => $film, 'variant' => 'b'],
|
||||
], null, null, [], [['key' => 'a', 'name' => 'A'], ['key' => 'b', 'name' => 'B']]);
|
||||
$module = $this->moduleWith('Modul', $exercise, ['a'], CompositionKind::Uebung, $film);
|
||||
$articles = app(ArticleService::class);
|
||||
$release = $articles->publishRelease($articles->create('doppelt'), $module, 'Mehrfach.');
|
||||
|
||||
$this->assertSame([$film->id, $film->id, $film->id], $release->contents->pluck('content_element_version_id')->all());
|
||||
$this->assertSame([null, 'a', null], $release->contents->pluck('variant_key')->all());
|
||||
}
|
||||
|
||||
public function test_the_structure_hash_notices_what_the_media_set_does_not(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $this->film('Gleicher Film');
|
||||
$composition = $this->exerciseComposition('Hash');
|
||||
$variants = [['key' => 'a', 'name' => 'A']];
|
||||
$first = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film, 'variant' => 'a', 'requirement' => 'erforderlich']], null, null, [], $variants);
|
||||
$second = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film, 'variant' => 'a', 'requirement' => 'ergaenzend']], null, null, [], $variants);
|
||||
$third = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film]], null, null, [], $variants);
|
||||
|
||||
$this->assertSame($first->resolved_hash, $second->resolved_hash);
|
||||
$this->assertSame($first->resolved_hash, $third->resolved_hash);
|
||||
$this->assertCount(3, array_unique([$first->structure_hash, $second->structure_hash, $third->structure_hash]));
|
||||
}
|
||||
|
||||
public function test_two_stands_keep_different_versions_of_the_same_exercise(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$exercise = $this->exercise();
|
||||
$moduleV1 = $this->moduleWith('Modul eins', $exercise['version'], ['a']);
|
||||
$revisedText = $content->publishElementVersion($exercise['textA']->element, 'Variante A, überarbeitet.');
|
||||
$secondVersion = $content->publishComposition($exercise['version']->composition, [
|
||||
['role' => 'Einstieg', 'target' => $exercise['intro']],
|
||||
['role' => 'Durchführung A', 'target' => $revisedText, 'variant' => 'a'],
|
||||
['role' => 'Film A', 'target' => $exercise['filmA'], 'variant' => 'a'],
|
||||
], null, null, ['learning_goal' => 'Neu gefasst'], [['key' => 'a', 'name' => 'Mit Film']]);
|
||||
$moduleV2 = $this->moduleWith('Modul zwei', $secondVersion, ['a']);
|
||||
|
||||
$articles = app(ArticleService::class);
|
||||
$one = $articles->publishRelease($articles->create('eins'), $moduleV1, 'Alte Übung.');
|
||||
$two = $articles->publishRelease($articles->create('zwei'), $moduleV2, 'Neue Übung.');
|
||||
|
||||
$this->assertContains($exercise['textA']->id, $one->contents->pluck('content_element_version_id')->all());
|
||||
$this->assertNotContains($revisedText->id, $one->contents->pluck('content_element_version_id')->all());
|
||||
$this->assertContains($revisedText->id, $two->contents->pluck('content_element_version_id')->all());
|
||||
$this->assertSame('Nein sagen und Abstand halten', $exercise['version']->fresh()->learning_goal);
|
||||
$this->assertSame(2, $exercise['version']->composition->versions()->count());
|
||||
}
|
||||
|
||||
public function test_a_published_exercise_version_and_its_variants_stay_unchanged(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
$exercise['version']->variants()->first()->update(['name' => 'Anders']);
|
||||
}
|
||||
|
||||
public function test_invalid_placements_are_refused(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $this->film('Film');
|
||||
$composition = $this->exerciseComposition('Prüfung');
|
||||
$variants = [['key' => 'a', 'name' => 'A']];
|
||||
|
||||
foreach ([
|
||||
[['role' => 'x', 'target' => $film, 'variant' => 'zzz'], $variants],
|
||||
[['role' => 'x', 'target' => $film, 'requirement' => 'vielleicht'], $variants],
|
||||
[['role' => 'x', 'target' => $film, 'selection' => ['a']], $variants],
|
||||
] as [$member, $declared]) {
|
||||
try {
|
||||
$content->publishComposition($composition, [$member], null, null, [], $declared);
|
||||
$this->fail('Eine ungültige Zuordnung wurde angenommen.');
|
||||
} catch (DomainRuleException) {
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
}
|
||||
|
||||
$exercise = $this->exercise('Andere');
|
||||
$module = $this->exerciseComposition('Wirt');
|
||||
|
||||
foreach ([['zzz'], []] as $selection) {
|
||||
try {
|
||||
$content->publishComposition($module, [['role' => 'Übung', 'target' => $exercise['version'], 'selection' => $selection]]);
|
||||
$this->fail('Eine ungültige Variantenauswahl wurde angenommen.');
|
||||
} catch (DomainRuleException) {
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\ExerciseUsage;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\Support\BuildsExercises;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Parallele Fassungen und gezielte Mediensperre: Der Verwendungsnachweis steigt bis zu den Ständen auf (auch älteren und
|
||||
* verschachtelten), die Sperre wirkt bei der Ausgabe, und der Auswirkungsbericht benennt Variante und Verwendung.
|
||||
*/
|
||||
class UebungSperreTest extends TestCase
|
||||
{
|
||||
use BuildsExercises;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_the_usage_reaches_nested_and_older_stands(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$inner = $this->moduleWith('Modul innen', $exercise['version'], ['a']);
|
||||
$outer = $this->moduleWith('Programm außen', $inner, null, CompositionKind::Kurs);
|
||||
$articles = app(ArticleService::class);
|
||||
$article = $articles->create('programm-aussen');
|
||||
$first = $articles->publishRelease($article, $outer, 'Erster Stand.');
|
||||
$second = $articles->publishRelease($article->fresh(), $outer, 'Zweiter Stand.');
|
||||
$direct = $articles->publishRelease($articles->create('modul-innen'), $inner, 'Modul allein.');
|
||||
|
||||
$usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition);
|
||||
|
||||
$this->assertCount(1, $usage);
|
||||
$this->assertSame(['Modul innen', 'Programm außen'], array_map(fn (array $host): string => $host['composition']->designation, $usage[0]['hosts']));
|
||||
$this->assertSame([['a'], null], array_map(fn (array $host) => $host['selection'], $usage[0]['hosts']));
|
||||
|
||||
$stands = collect($usage[0]['releases']);
|
||||
$this->assertEqualsCanonicalizing([$first->id, $second->id, $direct->id], $stands->map(fn (array $row): int => $row['release']->id)->all());
|
||||
$this->assertSame('1-1', $stands->first(fn (array $row): bool => $row['release']->id === $first->id)['path'], 'Zwei Ebenen tief.');
|
||||
$this->assertSame('1', $stands->first(fn (array $row): bool => $row['release']->id === $direct->id)['path']);
|
||||
$this->assertSame('abgeloest_verfuegbar', $first->fresh()->status->value);
|
||||
}
|
||||
|
||||
public function test_the_impact_of_a_block_names_stand_variant_and_usage(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$withFilm = $this->moduleWith('Mit Film', $exercise['version'], ['a']);
|
||||
$withoutFilm = $this->moduleWith('Ohne Film', $exercise['version'], ['b']);
|
||||
$articles = app(ArticleService::class);
|
||||
$articles->publishRelease($articles->create('mit-film'), $withFilm, 'Film.');
|
||||
$articles->publishRelease($articles->create('ohne-film'), $withoutFilm, 'Ohne Film.');
|
||||
|
||||
$film = app(ExerciseUsage::class)->blockImpact($exercise['filmA']);
|
||||
$this->assertCount(1, $film);
|
||||
$this->assertSame('mit-film', $film[0]['article']->code);
|
||||
$this->assertSame('a', $film[0]['variant']);
|
||||
$this->assertStringContainsString('nicht mehr vollständig durchführbar', $film[0]['effect']);
|
||||
|
||||
$sheet = app(ExerciseUsage::class)->blockImpact($exercise['sheetB']);
|
||||
$this->assertSame('ergaenzend', $sheet[0]['requirement']);
|
||||
$this->assertStringContainsString('Nur dieses ergänzende Medium entfällt', $sheet[0]['effect']);
|
||||
$this->assertSame([], app(ExerciseUsage::class)->blockImpact($this->film('Unbenutzt')));
|
||||
}
|
||||
|
||||
public function test_a_block_changes_neither_the_frozen_stand_nor_the_usage(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
||||
$articles = app(ArticleService::class);
|
||||
$release = $articles->publishRelease($articles->create('modul'), $module, 'Modul.');
|
||||
$before = $release->contents->pluck('content_element_version_id')->all();
|
||||
|
||||
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
||||
|
||||
$this->assertSame($before, $release->fresh()->contents->pluck('content_element_version_id')->all());
|
||||
$this->assertSame('veroeffentlicht', $release->fresh()->status->value);
|
||||
$this->assertCount(1, app(ExerciseUsage::class)->blockImpact($exercise['filmA']));
|
||||
}
|
||||
|
||||
public function test_an_offer_with_a_blocked_part_is_not_activated_and_names_it(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
||||
$articles = app(ArticleService::class);
|
||||
$article = $articles->create('modul-angebot');
|
||||
$articles->publishRelease($article, $module, 'Modul.');
|
||||
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
||||
|
||||
$offers = app(OfferService::class);
|
||||
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen'], 'text' => ['ansehen']]);
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
$this->expectExceptionMessage('gesperrte Bestandteile');
|
||||
$offers->activate($offers->create('Angebot'), [['target' => $article->fresh(), 'rights' => $rights]], [
|
||||
'grant_kind' => 'auf_abruf',
|
||||
'composition_version_id' => $module->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_the_preview_picture_of_a_blocked_medium_is_not_served_any_more(): void
|
||||
{
|
||||
$exercise = $this->exercise();
|
||||
$element = $exercise['filmA']->element;
|
||||
$element->thumbnail_path = 'vorschau/film-a.jpg';
|
||||
$element->save();
|
||||
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
||||
$articles = app(ArticleService::class);
|
||||
$article = $articles->create('modul-bild');
|
||||
$articles->publishRelease($article, $module, 'Modul.');
|
||||
$offers = app(OfferService::class);
|
||||
$offer = $offers->create('Bild');
|
||||
$offers->activate($offer, [['target' => $article->fresh(), 'rights' => $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']])]], ['grant_kind' => 'auf_abruf']);
|
||||
$member = User::factory()->create();
|
||||
app(GrantIssuer::class)->claim($member, $offer);
|
||||
|
||||
$url = route('member.thumbnail', ['kind' => 'element', 'subject' => $element->id]);
|
||||
// Erlaubt, aber die Datei fehlt in diesem Test.
|
||||
$this->actingAs($member)->get($url)->assertNotFound();
|
||||
|
||||
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
||||
|
||||
$this->actingAs($member)->get($url)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_two_versions_of_an_exercise_run_in_parallel_stands(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$exercise = $this->exercise();
|
||||
$first = $this->moduleWith('Modul alt', $exercise['version'], ['a']);
|
||||
$revised = $content->publishElementVersion($exercise['textA']->element, 'Neuer Wortlaut.');
|
||||
$second = $content->publishComposition($exercise['version']->composition, [
|
||||
['role' => 'Durchführung A', 'target' => $revised, 'variant' => 'a'],
|
||||
['role' => 'Film A', 'target' => $exercise['filmA'], 'variant' => 'a'],
|
||||
], null, null, [], [['key' => 'a', 'name' => 'Mit Film']]);
|
||||
$newer = $this->moduleWith('Modul neu', $second, ['a']);
|
||||
$articles = app(ArticleService::class);
|
||||
$articles->publishRelease($articles->create('alt'), $first, 'Alt.');
|
||||
$articles->publishRelease($articles->create('neu'), $newer, 'Neu.');
|
||||
|
||||
$usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition);
|
||||
|
||||
$this->assertCount(2, $usage);
|
||||
$this->assertSame(['alt'], collect($usage[0]['releases'])->map(fn (array $row) => $row['article']->code)->all());
|
||||
$this->assertSame(['neu'], collect($usage[1]['releases'])->map(fn (array $row) => $row['article']->code)->all());
|
||||
$this->assertInstanceOf(ArticleRelease::class, $usage[0]['releases'][0]['release']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
|
||||
/**
|
||||
* Baut Übungen für Tests: Medien- und Textfassungen, die Übung mit Varianten und Module, die sie einbinden.
|
||||
*/
|
||||
trait BuildsExercises
|
||||
{
|
||||
protected function film(string $title, string $file = 'inhalte/film.mp4'): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
|
||||
return $content->publishElementVersion($content->createElement('film', 'film', $title), null, ['file' => $file]);
|
||||
}
|
||||
|
||||
protected function sheet(string $title): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
|
||||
return $content->publishElementVersion($content->createElement('document', 'document', $title), null, ['file' => 'inhalte/'.str($title)->slug().'.pdf']);
|
||||
}
|
||||
|
||||
protected function section(string $title, string $body): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
|
||||
return $content->publishElementVersion($content->createElement('text', 'text', $title), $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Übung mit gemeinsamem Einstieg und zwei Varianten: A mit Film, B ohne Film (nur Arbeitsblatt).
|
||||
*
|
||||
* @return array{version: CompositionVersion, intro: ContentElementVersion, filmA: ContentElementVersion, sheetB: ContentElementVersion, textA: ContentElementVersion, textB: ContentElementVersion}
|
||||
*/
|
||||
protected function exercise(string $title = 'Stopp sagen', ?Composition $composition = null): array
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$intro = $this->section($title.' · Einstieg', "Gemeinsamer Einstieg.\n\n- Sicher stehen\n- Deutlich sprechen");
|
||||
$filmA = $this->film($title.' · Film A');
|
||||
$sheetB = $this->sheet($title.' · Arbeitsblatt B');
|
||||
$textA = $this->section($title.' · Durchführung A', 'Variante A: Der Film zeigt die Situation.');
|
||||
$textB = $this->section($title.' · Durchführung B', 'Variante B: Ohne Film mit dem Arbeitsblatt.');
|
||||
$composition ??= $this->exerciseComposition($title);
|
||||
|
||||
$version = $content->publishComposition($composition, [
|
||||
['role' => 'Einstieg', 'target' => $intro],
|
||||
['role' => 'Durchführung A', 'target' => $textA, 'variant' => 'a'],
|
||||
['role' => 'Film A', 'target' => $filmA, 'variant' => 'a', 'requirement' => 'erforderlich'],
|
||||
['role' => 'Durchführung B', 'target' => $textB, 'variant' => 'b'],
|
||||
['role' => 'Arbeitsblatt B', 'target' => $sheetB, 'variant' => 'b', 'requirement' => 'ergaenzend'],
|
||||
], null, null, ['learning_goal' => 'Nein sagen und Abstand halten', 'duration_minutes' => 15, 'duration_max' => 20, 'prerequisites' => 'Keine'], [
|
||||
['key' => 'a', 'name' => 'Mit Film', 'description' => 'Einstieg über den Film'],
|
||||
['key' => 'b', 'name' => 'Ohne Film', 'description' => 'Nur mit Arbeitsblatt'],
|
||||
]);
|
||||
|
||||
return compact('version', 'intro', 'filmA', 'sheetB', 'textA', 'textB');
|
||||
}
|
||||
|
||||
protected function exerciseComposition(string $title): Composition
|
||||
{
|
||||
$composition = app(ContentService::class)->createComposition($title, CompositionKind::Exercise);
|
||||
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'uebung')->value('id');
|
||||
$composition->save();
|
||||
|
||||
return $composition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string>|null $selection
|
||||
*/
|
||||
protected function moduleWith(string $title, CompositionVersion $exercise, ?array $selection = null, CompositionKind $kind = CompositionKind::Uebung, ?ContentElementVersion $extra = null): CompositionVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$composition = $content->createComposition($title, $kind);
|
||||
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', $kind === CompositionKind::Kurs ? 'programm' : 'modul')->value('id');
|
||||
$composition->save();
|
||||
$members = [['role' => 'Übung', 'target' => $exercise, 'selection' => $selection]];
|
||||
|
||||
if ($extra !== null) {
|
||||
$members[] = ['role' => 'Zusatz', 'target' => $extra];
|
||||
}
|
||||
|
||||
return $content->publishComposition($composition, $members);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user