Paket 3: Strukturleser und Anzeigefreigabe (G1, G2)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1a2b1298b5
commit
5ed01b9d04
7 files changed
+372
No files matched your search
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
class CompositionStructureReader
|
||||
{
|
||||
/**
|
||||
* @return list<StructureNode>
|
||||
*/
|
||||
public function tree(CompositionVersion $version): array
|
||||
{
|
||||
$version->loadMissing([
|
||||
'members.contentElementVersion.element.editorialContentKind',
|
||||
'members.nestedCompositionVersion.composition.editorialContentKind',
|
||||
]);
|
||||
|
||||
return $this->members($version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<StructureNode>
|
||||
*/
|
||||
private function members(CompositionVersion $version, array $stack = []): array
|
||||
{
|
||||
if (in_array($version->composition_id, $stack, true)) {
|
||||
throw new DomainRuleException('Kompositionen dürfen keinen Zyklus bilden.');
|
||||
}
|
||||
|
||||
$stack[] = $version->composition_id;
|
||||
$nodes = [];
|
||||
|
||||
foreach ($version->members as $member) {
|
||||
if ($member->content_element_version_id !== null) {
|
||||
$elementVersion = $member->contentElementVersion;
|
||||
$elementVersion?->loadMissing('element.editorialContentKind');
|
||||
$element = $elementVersion?->element;
|
||||
|
||||
$nodes[] = new StructureNode(
|
||||
role: $member->role,
|
||||
position: $member->position,
|
||||
compositionVersionId: null,
|
||||
compositionId: null,
|
||||
contentElementVersionId: $elementVersion?->id,
|
||||
contentElementId: $element?->id,
|
||||
editorialKindLabel: $element?->editorialContentKind?->label,
|
||||
technicalKindLabel: $element?->output_class,
|
||||
outputClass: $element?->output_class,
|
||||
title: $element?->working_title ?? $member->role,
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$nested = $member->nestedCompositionVersion;
|
||||
|
||||
if ($nested === null) {
|
||||
throw new DomainRuleException('Ein Kompositionsmitglied braucht genau ein Ziel.');
|
||||
}
|
||||
|
||||
$nested->loadMissing('composition.editorialContentKind', 'composition');
|
||||
$composition = $nested->composition;
|
||||
|
||||
$nodes[] = new StructureNode(
|
||||
role: $member->role,
|
||||
position: $member->position,
|
||||
compositionVersionId: $nested->id,
|
||||
compositionId: $composition->id,
|
||||
contentElementVersionId: null,
|
||||
contentElementId: null,
|
||||
editorialKindLabel: $composition->editorialContentKind?->label,
|
||||
technicalKindLabel: $composition->kind instanceof CompositionKind
|
||||
? $composition->kind->label()
|
||||
: null,
|
||||
outputClass: null,
|
||||
title: $composition->designation,
|
||||
children: $this->members($nested, $stack),
|
||||
);
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user