Ergänze das U1-Fachmodell für Inhalt, Paket und Angebot.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
2035c46edd
commit
2ded4b7fad
35 files changed
+2115
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?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.');
|
||||
}
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user