Eine Komposition mit einem kind-Wert, den erst ein neuerer Stand schreibt, gilt als nicht vorhanden (globaler Bereichsfilter statt Absturz im Enum-Cast). Aufbauten mit solchen Bestandteilen werden hier weder veröffentlicht noch als Angebot aktiviert, der Editor bleibt schreibgeschützt, die Mitgliederansicht zeigt den Bestandteil nicht. Grundlage für die Übungsverwaltung, damit ein Rückfall nichts verliert oder offenlegt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Catalog;
|
|
|
|
class ContentResolver
|
|
{
|
|
/**
|
|
* @return list<array{version_id: int, role: string, path: string}>
|
|
*/
|
|
public function expand(ContentElementVersion|CompositionVersion $node, string $path = '', array $stack = []): array
|
|
{
|
|
if ($node instanceof ContentElementVersion) {
|
|
$node->loadMissing('element');
|
|
|
|
return [[
|
|
'version_id' => $node->id,
|
|
'role' => $path,
|
|
'path' => $path !== '' ? $path : $node->element->working_title,
|
|
]];
|
|
}
|
|
|
|
if (in_array($node->composition_id, $stack, true)) {
|
|
throw new DomainRuleException('Kompositionen dürfen keinen Zyklus bilden.');
|
|
}
|
|
|
|
$stack[] = $node->composition_id;
|
|
$rows = [];
|
|
|
|
foreach ($node->members()->orderBy('position')->get() as $member) {
|
|
$segment = $path === '' ? $member->role : $path.' / '.$member->role;
|
|
|
|
if ($member->content_element_version_id !== null) {
|
|
$rows[] = [
|
|
'version_id' => $member->content_element_version_id,
|
|
'role' => $member->role,
|
|
'path' => $segment,
|
|
];
|
|
|
|
continue;
|
|
}
|
|
|
|
$nested = $member->nestedCompositionVersion;
|
|
|
|
if ($nested === null) {
|
|
throw new DomainRuleException('Ein Kompositionsmitglied braucht genau ein Ziel.');
|
|
}
|
|
|
|
// 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));
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
public function resolvedHash(ContentElementVersion|CompositionVersion $node): string
|
|
{
|
|
$ids = array_values(array_unique(array_column($this->expand($node), 'version_id')));
|
|
sort($ids);
|
|
|
|
return hash('sha256', json_encode($ids, JSON_THROW_ON_ERROR));
|
|
}
|
|
}
|