Minigrafiken im CMS #8
No files matched your search
@@ -33,6 +33,17 @@ class ShinkanImport
|
||||
'trainer_notes' => 'Trainerhinweise',
|
||||
];
|
||||
|
||||
/** Änderungshinweis der Textfassungen, die die Übernahme angelegt hat. Alles andere ist eine lokale Bearbeitung. */
|
||||
private const IMPORT_NOTE = 'Übernahme aus Shinkan';
|
||||
|
||||
/** Fassungsfelder der Quelle: Katalogfeld => [Feld der lokalen Fassung, Bezeichnung]. */
|
||||
private const FIELDS = [
|
||||
'goal' => ['learning_goal', 'Lernziel'],
|
||||
'duration_min' => ['duration_minutes', 'Dauer (von)'],
|
||||
'duration_max' => ['duration_max', 'Dauer (bis)'],
|
||||
'equipment' => ['material_note', 'Ausstattung'],
|
||||
];
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return app(ShinkanConnection::class)->configured();
|
||||
@@ -226,6 +237,8 @@ public function preview(ExerciseSource $source): array
|
||||
'media' => array_map(fn (array $media): string => ($media['title'] ?? 'Medium').' ('.($media['media_type'] ?? '').')', array_values(array_filter((array) ($document['media'] ?? []), 'is_array'))),
|
||||
'changes' => $previous === null ? [] : $this->changes($previous->payload, $document, $source),
|
||||
'conflicts' => $snapshot === null ? [] : $this->conflicts($source, $document),
|
||||
'text_conflicts' => $snapshot === null ? [] : $this->textDecisions($source, $document, 'conflict'),
|
||||
'kept_local' => $snapshot === null ? [] : array_column($this->textDecisions($source, $document, 'keep_local'), 'label'),
|
||||
'identical' => $snapshot !== null && $snapshot->adopted_version_id !== null,
|
||||
'excluded' => $source->availability === ExerciseSource::WITHDRAWN,
|
||||
];
|
||||
@@ -327,14 +340,50 @@ public function conflicts(ExerciseSource $source, array $document): array
|
||||
return array_values($open);
|
||||
}
|
||||
|
||||
/**
|
||||
* Texte und Felder, die lokal bearbeitet wurden: `keep_local` bleiben erhalten, bei `conflict` hat auch die Quelle
|
||||
* geändert und die Redaktion entscheidet.
|
||||
*
|
||||
* @param array<string, mixed> $document
|
||||
* @return list<array{key: string, label: string}>
|
||||
*/
|
||||
public function textDecisions(ExerciseSource $source, array $document, string $wanted): array
|
||||
{
|
||||
$previousSnapshot = $this->lastAdopted($source);
|
||||
|
||||
if ($previousSnapshot === null || $source->composition === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$previousSource = $previousSnapshot->payload;
|
||||
$result = [];
|
||||
|
||||
foreach ($this->plan($source, $document, $previousSource) as $item) {
|
||||
if ($item['kind'] === 'text' && $item['decision'] === $wanted) {
|
||||
$result[] = ['key' => $item['key'], 'label' => $item['label']];
|
||||
}
|
||||
}
|
||||
|
||||
$latest = $source->composition->versions()->orderByDesc('number')->first();
|
||||
|
||||
foreach (self::FIELDS as $field => [$column, $label]) {
|
||||
if ($latest !== null && $this->classifyField($latest->{$column}, $previousSource[$field] ?? null, $document[$field] ?? null) === $wanted) {
|
||||
$result[] = ['key' => $field, 'label' => $label];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Übernimmt genau den Stand, den die Redaktion in der Vorschau gesehen hat. Hat sich der Stand seither geändert oder
|
||||
* wurde die Quelle ausgeblendet, wird nichts übernommen. Identische bereits übernommene Stände ergeben keine Fassung.
|
||||
*
|
||||
* @param array<string, string> $reassign neue Zuordnung entfallener Quellvarianten: alter Schlüssel => neuer Schlüssel oder ''
|
||||
* @param array<string, string> $choices bei lokal und in der Quelle geänderten Angaben: Schlüssel => `lokal` oder `quelle`
|
||||
* @return array{status: string, message: string, version?: CompositionVersion}
|
||||
*/
|
||||
public function adoptPreviewed(ExerciseSource $source, int $previewedSnapshot, array $reassign = [], ?User $actor = null): array
|
||||
public function adoptPreviewed(ExerciseSource $source, int $previewedSnapshot, array $reassign = [], ?User $actor = null, array $choices = []): array
|
||||
{
|
||||
$source->refresh();
|
||||
$latest = $source->latestSnapshot();
|
||||
@@ -352,7 +401,7 @@ public function adoptPreviewed(ExerciseSource $source, int $previewedSnapshot, a
|
||||
}
|
||||
|
||||
try {
|
||||
$version = $this->adopt($latest, $actor, $reassign);
|
||||
$version = $this->adopt($latest, $actor, $reassign, $choices);
|
||||
} catch (DomainRuleException $exception) {
|
||||
return ['status' => 'fehler', 'message' => $exception->getMessage()];
|
||||
}
|
||||
@@ -362,11 +411,17 @@ public function adoptPreviewed(ExerciseSource $source, int $previewedSnapshot, a
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* entsteht keine zweite Fassung.
|
||||
*
|
||||
* Eine importierte Übung ist eine Übung wie jede andere und lässt sich bearbeiten. Lokal bearbeitete Texte und Felder
|
||||
* bleiben deshalb erhalten, solange die Quelle sie nicht ebenfalls geändert hat. Haben beide Seiten geändert, legt die
|
||||
* Redaktion fest, welcher Stand gilt (`$choices`). Lokale Ergänzungen bleiben erhalten; entfällt ihre Quellvariante,
|
||||
* legt die Redaktion die neue Zuordnung fest (`$reassign`).
|
||||
*
|
||||
* @param array<string, string> $reassign
|
||||
* @param array<string, string> $choices Schlüssel => `lokal` oder `quelle`
|
||||
*/
|
||||
public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null, array $reassign = []): CompositionVersion
|
||||
public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null, array $reassign = [], array $choices = []): CompositionVersion
|
||||
{
|
||||
$snapshot->refresh();
|
||||
|
||||
@@ -374,57 +429,73 @@ public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null, arr
|
||||
return $snapshot->adoptedVersion;
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($snapshot, $actor, $reassign): CompositionVersion {
|
||||
return DB::transaction(function () use ($snapshot, $actor, $reassign, $choices): CompositionVersion {
|
||||
$source = $snapshot->source;
|
||||
$document = $snapshot->payload;
|
||||
$content = app(ContentService::class);
|
||||
$title = trim((string) ($document['title'] ?? '')) ?: 'Übung aus Shinkan';
|
||||
$previousSnapshot = $this->lastAdopted($source);
|
||||
$previousSource = $previousSnapshot?->payload ?? [];
|
||||
$composition = $source->composition ?? $this->createComposition($title, (string) ($document['summary'] ?? ''));
|
||||
|
||||
if ($source->composition !== null && $previousSnapshot !== null) {
|
||||
$this->carryOverTexts($composition, $previousSnapshot->payload, $document);
|
||||
$this->carryOverTexts($composition, $previousSource, $document);
|
||||
}
|
||||
|
||||
$previous = $composition->versions()->orderByDesc('number')->with('members.variant', 'variants')->first();
|
||||
$variants = [];
|
||||
$members = [];
|
||||
|
||||
foreach (self::SECTIONS as $field => $label) {
|
||||
$text = trim((string) ($document[$field] ?? ''));
|
||||
foreach ($this->plan($source, $document, $previousSource) as $item) {
|
||||
if ($item['kind'] === 'variant') {
|
||||
$variants[] = $item['variant'];
|
||||
|
||||
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'] ?? ''));
|
||||
$latest = $item['latest'];
|
||||
$decision = $item['decision'];
|
||||
|
||||
if ($changes !== '') {
|
||||
$members[] = [
|
||||
'role' => 'Abweichung der Durchführung',
|
||||
'target' => $this->section($source, 'variant:'.$key, $title.' · '.($variant['name'] ?? 'Variante').' · Abweichung', $changes),
|
||||
'variant' => $key,
|
||||
'origin' => 'quelle',
|
||||
];
|
||||
if ($decision === 'conflict') {
|
||||
$decision = ($choices[$item['key']] ?? null) === 'lokal' ? 'keep_local'
|
||||
: (($choices[$item['key']] ?? null) === 'quelle' ? 'source' : 'conflict');
|
||||
}
|
||||
|
||||
if ($decision === 'conflict') {
|
||||
throw new DomainRuleException('„'.$item['label'].'“ wurde lokal und in der Quelle geändert. Lege fest, welcher Stand gilt.');
|
||||
}
|
||||
|
||||
$keepLocal = $decision === 'keep_local' && $latest !== null;
|
||||
$target = $keepLocal ? $latest : $this->sectionVersion($source, $item['field'], $item['title'], $item['text'], $latest);
|
||||
$members[] = array_filter([
|
||||
'role' => $item['role'],
|
||||
'target' => $target,
|
||||
'variant' => $item['variant_key'],
|
||||
'origin' => $keepLocal || ($latest !== null && $latest->id === $target->id && $latest->change_note !== self::IMPORT_NOTE) ? 'lokal' : 'quelle',
|
||||
], fn ($value): bool => $value !== null);
|
||||
}
|
||||
|
||||
// Fassungsfelder: lokal geändert bleibt erhalten, solange die Quelle den Wert nicht ebenfalls geändert hat.
|
||||
$fields = [];
|
||||
|
||||
foreach (self::FIELDS as $field => [$column, $label]) {
|
||||
$value = $document[$field] ?? null;
|
||||
|
||||
if ($previous !== null && $previousSnapshot !== null) {
|
||||
$decision = $this->classifyField($previous->{$column}, $previousSource[$field] ?? null, $value);
|
||||
|
||||
if ($decision === 'conflict') {
|
||||
$decision = ($choices[$field] ?? null) === 'lokal' ? 'keep_local' : (($choices[$field] ?? null) === 'quelle' ? 'source' : 'conflict');
|
||||
}
|
||||
|
||||
if ($decision === 'conflict') {
|
||||
throw new DomainRuleException('„'.$label.'“ wurde lokal und in der Quelle geändert. Lege fest, welcher Stand gilt.');
|
||||
}
|
||||
|
||||
$value = $decision === 'keep_local' ? $previous->{$column} : $value;
|
||||
}
|
||||
|
||||
$fields[$column] = $value;
|
||||
}
|
||||
|
||||
[$localMembers, $localVariants] = $this->localAdditions($previous, array_column($variants, 'key'), $reassign);
|
||||
@@ -432,12 +503,12 @@ public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null, arr
|
||||
$composition,
|
||||
[...$members, ...$localMembers],
|
||||
$actor,
|
||||
'Übernahme aus Shinkan',
|
||||
self::IMPORT_NOTE,
|
||||
[
|
||||
'learning_goal' => $document['goal'] ?? null,
|
||||
'duration_minutes' => $document['duration_min'] ?? null,
|
||||
'duration_max' => $document['duration_max'] ?? null,
|
||||
'material_note' => $document['equipment'] ?? null,
|
||||
'learning_goal' => $fields['learning_goal'],
|
||||
'duration_minutes' => $fields['duration_minutes'],
|
||||
'duration_max' => $fields['duration_max'],
|
||||
'material_note' => $fields['material_note'],
|
||||
'source_snapshot_id' => $snapshot->id,
|
||||
],
|
||||
[...$variants, ...$localVariants],
|
||||
@@ -450,6 +521,102 @@ public function adopt(ExerciseSourceSnapshot $snapshot, ?User $actor = null, arr
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Was die Übernahme aus dem Quellstand anlegen würde, mit der Entscheidung je Text: `source` (Quelltext gilt),
|
||||
* `keep_local` (lokal bearbeitet, die Quelle hat sich nicht geändert) oder `conflict` (beide haben geändert).
|
||||
*
|
||||
* @param array<string, mixed> $document
|
||||
* @param array<string, mixed> $previousSource
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function plan(ExerciseSource $source, array $document, array $previousSource): array
|
||||
{
|
||||
$plan = [];
|
||||
$title = trim((string) ($document['title'] ?? '')) ?: 'Übung aus Shinkan';
|
||||
|
||||
foreach (self::SECTIONS as $field => $label) {
|
||||
$text = trim((string) ($document[$field] ?? ''));
|
||||
|
||||
if ($text !== '') {
|
||||
$plan[] = $this->textItem($source, $field, $label, $title.' · '.$label, $label, $text, null, $previousSource[$field] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) ($document['variants'] ?? []) as $variant) {
|
||||
$key = (string) ($variant['id'] ?? '');
|
||||
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = (string) ($variant['name'] ?? '') ?: 'Variante';
|
||||
$plan[] = [
|
||||
'kind' => 'variant',
|
||||
'variant' => ['key' => $key, 'name' => $name, 'description' => (string) ($variant['description'] ?? ''), 'origin' => 'quelle'],
|
||||
];
|
||||
$changes = trim((string) ($variant['execution_changes'] ?? ''));
|
||||
|
||||
if ($changes !== '') {
|
||||
$before = collect((array) ($previousSource['variants'] ?? []))->firstWhere('id', $key);
|
||||
$plan[] = $this->textItem(
|
||||
$source,
|
||||
'variant:'.$key,
|
||||
'Abweichung der Durchführung ('.$name.')',
|
||||
$title.' · '.$name.' · Abweichung',
|
||||
'Abweichung der Durchführung',
|
||||
$changes,
|
||||
$key,
|
||||
is_array($before) ? ($before['execution_changes'] ?? null) : null,
|
||||
'variant_'.$key,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function textItem(ExerciseSource $source, string $field, string $label, string $title, string $role, string $text, ?string $variantKey, ?string $previousText, ?string $key = null): array
|
||||
{
|
||||
$element = ContentElement::query()->where('source_ref', 'shinkan:'.$source->source_id.':'.$field)->first();
|
||||
$latest = $element?->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->first();
|
||||
|
||||
return [
|
||||
'kind' => 'text',
|
||||
'key' => $key ?? $field,
|
||||
'field' => $field,
|
||||
'label' => $label,
|
||||
'title' => $title,
|
||||
'role' => $role,
|
||||
'text' => $text,
|
||||
'variant_key' => $variantKey,
|
||||
'latest' => $latest,
|
||||
'decision' => $this->classifyText($latest, $text, $previousText),
|
||||
];
|
||||
}
|
||||
|
||||
private function classifyText(?ContentElementVersion $latest, string $text, ?string $previousText): string
|
||||
{
|
||||
if ($latest === null || trim((string) $latest->body) === $text || $latest->change_note === self::IMPORT_NOTE) {
|
||||
return 'source';
|
||||
}
|
||||
|
||||
return $previousText === null || trim($previousText) !== $text ? 'conflict' : 'keep_local';
|
||||
}
|
||||
|
||||
private function classifyField(mixed $local, mixed $previousSource, mixed $new): string
|
||||
{
|
||||
$plain = fn (mixed $value): string => $value === null ? '' : trim((string) $value);
|
||||
|
||||
if ($plain($local) === $plain($new) || $plain($local) === $plain($previousSource)) {
|
||||
return 'source';
|
||||
}
|
||||
|
||||
return $plain($previousSource) !== $plain($new) ? 'conflict' : 'keep_local';
|
||||
}
|
||||
|
||||
/**
|
||||
* Titel und Kurzbeschreibung gehören zur Übung und nicht zur Fassung. Sie folgen der Quelle, solange die Redaktion sie
|
||||
* nicht lokal geändert hat; ein lokal geänderter Wert bleibt.
|
||||
@@ -529,7 +696,7 @@ private function localAdditions(?CompositionVersion $previous, array $sourceVari
|
||||
/**
|
||||
* Die Textfassung eines Abschnitts der Quelle. Unveränderter Text bleibt dieselbe Fassung.
|
||||
*/
|
||||
private function section(ExerciseSource $source, string $field, string $title, string $text): ContentElementVersion
|
||||
private function sectionVersion(ExerciseSource $source, string $field, string $title, string $text, ?ContentElementVersion $latest): ContentElementVersion
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$ref = 'shinkan:'.$source->source_id.':'.$field;
|
||||
@@ -541,11 +708,9 @@ private function section(ExerciseSource $source, string $field, string $title, s
|
||||
$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');
|
||||
: $content->publishElementVersion($element, $text, [], self::IMPORT_NOTE);
|
||||
}
|
||||
|
||||
private function createComposition(string $title, string $summary): Composition
|
||||
|
||||
@@ -52,11 +52,11 @@ class RedaktionelleStammdaten extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Stammdaten';
|
||||
|
||||
protected static ?string $navigationLabel = 'Redaktionelle Stammdaten';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $slug = 'stammdaten';
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ class Uebernahme extends Page
|
||||
/** @var array<int|string, array<string, string>> Quellübung => (entfallene Quellvariante => neue Zuordnung) */
|
||||
public array $reassign = [];
|
||||
|
||||
/** @var array<int|string, array<string, string>> Quellübung => (Text oder Feld => `lokal` oder `quelle`) */
|
||||
public array $textChoice = [];
|
||||
|
||||
/** @var list<array<string, mixed>> */
|
||||
public array $results = [];
|
||||
|
||||
@@ -63,6 +66,15 @@ class Uebernahme extends Page
|
||||
|
||||
public bool $feedbackError = false;
|
||||
|
||||
/**
|
||||
* Die Übernahme ist ein Weg im Übungsbestand („Aus Shinkan übernehmen“) und kein eigener Einstieg. Nur wer die
|
||||
* Anbindung pflegen darf, aber den Übungsbestand nicht sieht, bekommt den Eintrag in der Navigation.
|
||||
*/
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return static::canConfigure() && ! ContentElementResource::editor();
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return ContentElementResource::editor() || static::canConfigure();
|
||||
@@ -180,6 +192,12 @@ public function confirm(): void
|
||||
$changed[] = $entry['title'];
|
||||
}
|
||||
|
||||
foreach ($entry['text_conflicts'] as $conflict) {
|
||||
if (! in_array($this->textChoice[$entry['source']][$conflict['key']] ?? 'offen', ['lokal', 'quelle'], true)) {
|
||||
$open[] = $entry['title'].': '.$conflict['label'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entry['conflicts'] as $conflict) {
|
||||
if (! isset($this->reassign[$entry['source']][$conflict['key']]) || $this->reassign[$entry['source']][$conflict['key']] === 'offen') {
|
||||
$open[] = $entry['title'].': '.implode(', ', $conflict['members']);
|
||||
@@ -195,7 +213,7 @@ public function confirm(): void
|
||||
}
|
||||
|
||||
if ($open !== []) {
|
||||
$this->say('Lege zuerst die neue Zuordnung der lokalen Ergänzungen fest: '.implode('; ', $open).'.', true);
|
||||
$this->say('Lege zuerst fest, was gilt: '.implode('; ', $open).'.', true);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -205,7 +223,7 @@ public function confirm(): void
|
||||
foreach ($this->preview as $entry) {
|
||||
$source = ExerciseSource::query()->findOrFail($entry['source']);
|
||||
$reassign = array_map(fn (string $value): string => $value === 'gemeinsam' ? '' : $value, $this->reassign[$entry['source']] ?? []);
|
||||
$result = $import->adoptPreviewed($source, (int) $entry['snapshot'], $reassign, $this->actor());
|
||||
$result = $import->adoptPreviewed($source, (int) $entry['snapshot'], $reassign, $this->actor(), $this->textChoice[$entry['source']] ?? []);
|
||||
$source->refresh();
|
||||
$this->results[] = [
|
||||
'title' => $entry['title'],
|
||||
|
||||
@@ -17,7 +17,7 @@ class CombinationResource extends CompositionKindResource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Fachliche Kombinationen';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function kind(): CompositionKind
|
||||
{
|
||||
|
||||
@@ -1956,7 +1956,7 @@ 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,
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||
])->all());
|
||||
$this->durationMax = $version->duration_max === null ? '' : (string) $version->duration_max;
|
||||
$this->prerequisites = (string) ($version->prerequisites ?? '');
|
||||
@@ -2076,7 +2076,7 @@ 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,
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||
])->all());
|
||||
|
||||
return $version->learning_goal !== $this->blank($this->learningGoal)
|
||||
|
||||
@@ -20,7 +20,7 @@ class PillarResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Pillar::class;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Stammdaten';
|
||||
|
||||
protected static ?string $navigationLabel = 'Fachliche Säulen';
|
||||
|
||||
@@ -32,7 +32,7 @@ class PillarResource extends Resource
|
||||
|
||||
protected static ?string $slug = 'saeulen';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ class PracticeResource extends CompositionKindResource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Übungen';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function kind(): CompositionKind
|
||||
{
|
||||
|
||||
@@ -235,7 +235,7 @@ private function exerciseOrigin(Composition $composition, array $shinkan): strin
|
||||
$latest = $composition->versions->sortByDesc('number')->first();
|
||||
$local = $latest !== null && CompositionMember::query()->where('composition_version_id', $latest->id)->where('origin', 'lokal')->exists();
|
||||
|
||||
return $local ? 'Shinkan, lokal ergänzt' : 'Shinkan';
|
||||
return $local ? 'Shinkan, lokal bearbeitet' : 'Shinkan';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ ## 2. Verhalten beim Fassungswechsel
|
||||
| Titel | Gehört zur Übung, nicht zur Fassung. Er folgt der Quelle, **solange er lokal nicht geändert wurde**. Ein lokal geänderter Titel bleibt; die Vorschau nennt das. |
|
||||
| Kurzbeschreibung | Wie der Titel. |
|
||||
| Varianten | Neu hinzugekommene und entfallene Varianten sowie Umbenennungen und Änderungen werden in der Vorschau genannt. Die **Reihenfolge** der neuen Fassung folgt der Quelle. Eine Änderung der Reihenfolge wird in der Vorschau genannt. |
|
||||
| Lokale Bearbeitung | Lokal bearbeitete Texte und Felder bleiben erhalten, solange die Quelle sie nicht ebenfalls geändert hat. Bei einer Änderung auf beiden Seiten entscheidet die Redaktion je Text oder Feld (lokale Fassung behalten oder Quellfassung übernehmen). Die bisherigen Fassungen bleiben immer unverändert. Lokal entfernte Quellabschnitte erscheinen mit der nächsten Übernahme wieder. |
|
||||
| Lokale Ergänzung | Bleibt bei der neuen Fassung erhalten. Entfällt die Quellvariante, der sie zugeordnet ist, legt die Redaktion die neue Zuordnung ausdrücklich fest (gemeinsamer Teil oder eine Variante). Ohne diese Festlegung wird nichts übernommen. |
|
||||
| Medienhinweise | Bleiben Quellenangabe. Ein geänderter Hinweis ändert keine lokale Fassung. |
|
||||
|
||||
@@ -77,7 +78,7 @@ ## 4. Lücken bei der Übernahme verfügbarer Felder
|
||||
| `sequence_order` der Varianten | nicht als eigener Wert gespeichert, die Position folgt der Reihenfolge der Antwort | gleichwertig, solange der Katalog nach `sequence_order` sortiert liefert (`catalog_document` tut das) |
|
||||
| Variante ohne `execution_changes` | erzeugt keinen Abschnitt | gewollt; die Variante bleibt mit Name und Beschreibung sichtbar |
|
||||
| Titel und Kurzbeschreibung | folgen der Quelle nur, solange sie lokal nicht geändert wurden | siehe Abschnitt 2 |
|
||||
| Abgleich mit lokalen Änderungen am Quelltext | Ein lokal bearbeiteter Quellabschnitt wird nicht erkannt, weil lokale Änderungen eine neue lokale Fassung mit eigenem Text sind und die Quellabschnitte unverändert bleiben | Bei der nächsten Übernahme gilt wieder der Quelltext, die Redaktion ergänzt lokal über eigene Bestandteile |
|
||||
| Lokal bearbeitete Quellangaben | Eine importierte Übung ist eine Übung wie jede andere und wird im selben Editor bearbeitet und als neue Fassung gespeichert. Bei der nächsten Übernahme bleiben lokal bearbeitete Texte und Felder (Lernziel, Dauer, Ausstattung) erhalten, solange die Quelle sie nicht ebenfalls geändert hat. Haben beide geändert, legt die Redaktion fest, ob die lokale oder die Quellfassung gilt. | Die Vorschau nennt „Lokal bearbeitet, bleibt erhalten“ und fragt bei einem Konflikt nach. |
|
||||
|
||||
## 5. Offene Entscheidungen
|
||||
|
||||
|
||||
@@ -129,6 +129,19 @@
|
||||
<h4 class="vw-abschnitt-titel">Medienhinweise der Quelle</h4>
|
||||
<p class="vw-feld-hilfe">Quellenangaben ohne Datei. Sie werden nicht ausgeliefert und begründen keine Nutzungsberechtigung: {{ implode(', ', $eintrag['media']) }}</p>
|
||||
@endif
|
||||
@if ($eintrag['kept_local'] !== [])
|
||||
<p class="vw-band"><span><strong>Lokal bearbeitet, bleibt erhalten:</strong> {{ implode(', ', $eintrag['kept_local']) }}. Die Quelle hat diese Angaben nicht geändert.</span></p>
|
||||
@endif
|
||||
@foreach ($eintrag['text_conflicts'] as $konflikt)
|
||||
<label class="vw-feldlabel">{{ $konflikt['label'] }}: lokal und in der Quelle geändert
|
||||
<select class="vw-eingabe" wire:model.live="textChoice.{{ $eintrag['source'] }}.{{ $konflikt['key'] }}">
|
||||
<option value="offen">Bitte festlegen …</option>
|
||||
<option value="lokal">Lokale Fassung behalten</option>
|
||||
<option value="quelle">Quellfassung übernehmen (die lokale Änderung entfällt in der neuen Fassung)</option>
|
||||
</select>
|
||||
<span class="vw-feld-hilfe">Die bisherigen Fassungen bleiben unverändert erhalten.</span>
|
||||
</label>
|
||||
@endforeach
|
||||
@foreach ($eintrag['conflicts'] as $konflikt)
|
||||
<label class="vw-feldlabel">Neue Zuordnung für lokale Ergänzung ({{ implode(', ', $konflikt['members']) }})
|
||||
<select class="vw-eingabe" wire:model.live="reassign.{{ $eintrag['source'] }}.{{ $konflikt['key'] }}">
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\ExerciseImportRun;
|
||||
@@ -14,6 +15,7 @@
|
||||
use App\Domain\Catalog\ShinkanImport;
|
||||
use App\Domain\Design\SiteSetting;
|
||||
use App\Filament\Pages\Uebernahme;
|
||||
use App\Filament\Resources\Practices\Pages\EditPractice;
|
||||
use App\Filament\Resources\Practices\Pages\ListPractices;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
@@ -632,7 +634,7 @@ public function test_the_ui_requires_the_reassignment_before_confirming_and_then
|
||||
->call('review')
|
||||
->assertSee('Neue Zuordnung für lokale Ergänzung (Eigenes Video)')
|
||||
->call('confirm')
|
||||
->assertSee('Lege zuerst die neue Zuordnung der lokalen Ergänzungen fest')
|
||||
->assertSee('Lege zuerst fest, was gilt')
|
||||
->assertSet('step', 'vorschau');
|
||||
|
||||
$this->assertSame(2, $first->composition->versions()->count());
|
||||
@@ -654,13 +656,122 @@ public function test_the_exercise_list_names_the_origin_of_each_exercise(): void
|
||||
$page = Livewire::actingAs($this->staff('redakteur'), 'staff')->test(ListPractices::class)
|
||||
->assertSee('Herkunft: Shinkan')
|
||||
->assertSee('Herkunft: lokal')
|
||||
->assertDontSee('lokal ergänzt');
|
||||
->assertDontSee('lokal bearbeitet');
|
||||
|
||||
$members = $first->members->map(fn ($m): array => ['role' => $m->role, 'target' => $m->contentElementVersion, 'variant' => $m->variant?->key, 'origin' => $m->origin])->all();
|
||||
$members[] = ['role' => 'Eigenes Video', 'target' => $this->film('Eigenes Video'), 'origin' => 'lokal'];
|
||||
app(ContentService::class)->publishComposition($first->composition, $members, null, null, [], $first->variants->map(fn ($v): array => ['key' => $v->key, 'name' => $v->name, 'description' => $v->description, 'origin' => $v->origin])->all());
|
||||
|
||||
Livewire::actingAs($this->staff('redakteur'), 'staff')->test(ListPractices::class)->assertSee('Herkunft: Shinkan, lokal ergänzt');
|
||||
Livewire::actingAs($this->staff('redakteur'), 'staff')->test(ListPractices::class)->assertSee('Herkunft: Shinkan, lokal bearbeitet');
|
||||
}
|
||||
|
||||
public function test_an_imported_exercise_is_edited_like_any_other_and_the_local_edit_survives_an_unrelated_source_change(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$first = $import->adopt($import->record($this->document('h1')));
|
||||
$composition = $first->composition;
|
||||
|
||||
// Bearbeitung in der Verwaltung: Text der Durchführung und Lernziel, als neue Fassung gespeichert.
|
||||
Livewire::actingAs($this->staff('redakteur'), 'staff')
|
||||
->test(EditPractice::class, ['record' => $composition->getKey()])
|
||||
->call('selectPart', 1)
|
||||
->set('partBody', 'Unsere eigene Durchführung.')
|
||||
->call('saveSourceText')
|
||||
->set('learningGoal', 'Unser Lernziel')
|
||||
->call('saveDraft')
|
||||
->call('armRelease')
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision');
|
||||
|
||||
$second = $composition->versions()->orderByDesc('number')->firstOrFail();
|
||||
$this->assertSame(2, $second->number);
|
||||
$this->assertSame('Unsere eigene Durchführung.', $second->members->firstWhere('role', 'Durchführung')->contentElementVersion->body);
|
||||
$this->assertSame('Unser Lernziel', $second->learning_goal);
|
||||
$this->assertSame('Nein sagen üben', $first->fresh()->learning_goal, 'Die frühere Fassung bleibt unverändert.');
|
||||
|
||||
// Die Quelle ändert nur die Trainerhinweise.
|
||||
$changed = $this->document('h2');
|
||||
$changed['trainer_notes'] = 'Neue Hinweise der Quelle.';
|
||||
$snapshot = $import->record($changed);
|
||||
$source = ExerciseSource::query()->firstOrFail();
|
||||
|
||||
$preview = $import->preview($source);
|
||||
$this->assertSame([], $preview['text_conflicts']);
|
||||
$this->assertEqualsCanonicalizing(['Durchführung', 'Lernziel'], $preview['kept_local']);
|
||||
|
||||
$third = $import->adopt($snapshot);
|
||||
|
||||
$this->assertSame('Unsere eigene Durchführung.', $third->members->firstWhere('role', 'Durchführung')->contentElementVersion->body);
|
||||
$this->assertSame('lokal', $third->members->firstWhere('role', 'Durchführung')->origin);
|
||||
$this->assertSame('Neue Hinweise der Quelle.', $third->members->firstWhere('role', 'Trainerhinweise')->contentElementVersion->body);
|
||||
$this->assertSame('quelle', $third->members->firstWhere('role', 'Trainerhinweise')->origin);
|
||||
$this->assertSame('Unser Lernziel', $third->learning_goal);
|
||||
}
|
||||
|
||||
public function test_a_text_changed_locally_and_in_the_source_needs_a_deliberate_choice(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$first = $this->withLocalExecution($import, 'Lokale Durchführung.');
|
||||
|
||||
$changed = $this->document('h2');
|
||||
$changed['execution'] = 'Neue Durchführung der Quelle.';
|
||||
$snapshot = $import->record($changed);
|
||||
$source = ExerciseSource::query()->firstOrFail();
|
||||
|
||||
$this->assertSame([['key' => 'execution', 'label' => 'Durchführung']], $import->preview($source)['text_conflicts']);
|
||||
|
||||
try {
|
||||
$import->adopt($snapshot);
|
||||
$this->fail('Ohne Entscheidung darf nichts übernommen werden.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString('Lege fest, welcher Stand gilt', $exception->getMessage());
|
||||
}
|
||||
|
||||
$kept = $import->adoptPreviewed($source, $snapshot->id, [], null, ['execution' => 'lokal']);
|
||||
$this->assertSame('uebernommen', $kept['status']);
|
||||
$this->assertSame('Lokale Durchführung.', $kept['version']->members->firstWhere('role', 'Durchführung')->contentElementVersion->body);
|
||||
|
||||
$again = $this->document('h3');
|
||||
$again['execution'] = 'Noch eine Durchführung der Quelle.';
|
||||
$next = $import->record($again);
|
||||
$taken = $import->adoptPreviewed($source->fresh(), $next->id, [], null, ['execution' => 'quelle']);
|
||||
$this->assertSame('Noch eine Durchführung der Quelle.', $taken['version']->members->firstWhere('role', 'Durchführung')->contentElementVersion->body);
|
||||
$this->assertSame('quelle', $taken['version']->members->firstWhere('role', 'Durchführung')->origin);
|
||||
$this->assertSame(4, $first->composition->versions()->count(), 'Übernahme, lokale Bearbeitung und zwei weitere Übernahmen.');
|
||||
}
|
||||
|
||||
public function test_the_ui_asks_for_the_choice_on_a_double_change(): void
|
||||
{
|
||||
$import = app(ShinkanImport::class);
|
||||
$first = $this->withLocalExecution($import, 'Lokale Durchführung.');
|
||||
$changed = $this->document('h2');
|
||||
$changed['execution'] = 'Neue Durchführung der Quelle.';
|
||||
$import->record($changed);
|
||||
$sourceId = (string) ExerciseSource::query()->value('id');
|
||||
|
||||
$page = Livewire::actingAs($this->staff('redakteur'), 'staff')->test(Uebernahme::class)
|
||||
->set('selected', [$sourceId])
|
||||
->call('review')
|
||||
->assertSee('Durchführung: lokal und in der Quelle geändert')
|
||||
->call('confirm')
|
||||
->assertSee('Lege zuerst fest, was gilt')
|
||||
->assertSet('step', 'vorschau');
|
||||
|
||||
$page->set('textChoice.'.$sourceId.'.execution', 'lokal')->call('confirm')->assertSet('step', 'ergebnis');
|
||||
$this->assertSame('Lokale Durchführung.', $first->composition->versions()->orderByDesc('number')->firstOrFail()->members->firstWhere('role', 'Durchführung')->contentElementVersion->body);
|
||||
}
|
||||
|
||||
/** Übernommene Übung, deren Durchführung lokal als neue Fassung bearbeitet wurde. */
|
||||
private function withLocalExecution(ShinkanImport $import, string $text): CompositionVersion
|
||||
{
|
||||
$first = $import->adopt($import->record($this->document('h1')));
|
||||
$content = app(ContentService::class);
|
||||
$local = $content->publishElementVersion($first->members->firstWhere('role', 'Durchführung')->contentElementVersion->element, $text);
|
||||
$content->publishComposition($first->composition, $first->members->map(fn ($m): array => [
|
||||
'role' => $m->role, 'target' => $m->role === 'Durchführung' ? $local : $m->contentElementVersion, 'variant' => $m->variant?->key, 'origin' => $m->origin,
|
||||
])->all(), null, null, ['learning_goal' => 'Nein sagen üben', 'duration_minutes' => 10, 'duration_max' => 15, 'material_note' => 'Matten, Pratzen'], $first->variants->map(fn ($v): array => ['key' => $v->key, 'name' => $v->name, 'description' => $v->description, 'origin' => $v->origin])->all());
|
||||
|
||||
return $first;
|
||||
}
|
||||
|
||||
private function staff(string $role): User
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Pages\RedaktionelleStammdaten;
|
||||
use App\Filament\Pages\Uebernahme;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Resources\Practices\PracticeResource;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Navigation der Verwaltung: Übungen haben einen Einstieg im Bereich Inhalte, Säulen und redaktionelle Stammdaten stehen
|
||||
* in einer eigenen Gruppe Stammdaten, und die Übernahme aus Shinkan ist ein Weg im Übungsbestand.
|
||||
*/
|
||||
class UebungNavigationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_exercises_have_one_entry_in_the_content_group_next_to_media_modules_and_programs(): void
|
||||
{
|
||||
$this->assertSame('Inhalte', PracticeResource::getNavigationGroup());
|
||||
$this->assertSame('Übungen', PracticeResource::getNavigationLabel());
|
||||
|
||||
$order = collect([PracticeResource::class, ExerciseResource::class, CourseResource::class, CombinationResource::class])
|
||||
->sortBy(fn (string $resource): int => $resource::getNavigationSort())
|
||||
->map(fn (string $resource): string => $resource::getNavigationLabel())
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$this->assertSame(['Übungen', 'Module', 'Programme', 'Fachliche Kombinationen'], $order);
|
||||
}
|
||||
|
||||
public function test_pillars_and_editorial_master_data_share_the_master_data_group(): void
|
||||
{
|
||||
$this->assertSame('Stammdaten', PillarResource::getNavigationGroup());
|
||||
$this->assertSame('Stammdaten', RedaktionelleStammdaten::getNavigationGroup());
|
||||
$this->assertNotSame('Inhalte', PillarResource::getNavigationGroup());
|
||||
}
|
||||
|
||||
public function test_the_takeover_page_is_no_second_entry_for_the_editorial_staff(): void
|
||||
{
|
||||
$this->actingAs($this->staff('redakteur'), 'staff');
|
||||
$this->assertFalse(Uebernahme::shouldRegisterNavigation());
|
||||
$this->assertTrue(Uebernahme::canAccess());
|
||||
|
||||
// Wer nur die Anbindung pflegt und den Übungsbestand nicht sieht, findet die Seite in der Navigation.
|
||||
$this->actingAs($this->staff('katalogverwalter'), 'staff');
|
||||
$this->assertTrue(Uebernahme::shouldRegisterNavigation());
|
||||
}
|
||||
|
||||
private function staff(string $role): User
|
||||
{
|
||||
$user = User::factory()->{$role}()->create();
|
||||
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user