Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 08:24:23 +01:00
1 parent 7b54c38623
commit 5e763d15ec
23 files changed
+661 -5

No files matched your search

+2
View File
@@ -10,6 +10,8 @@ class Composition extends Model
{
protected $fillable = [
'designation',
'display_title',
'summary',
'kind',
'editorial_content_kind_id',
'archived_at',
+2
View File
@@ -13,7 +13,9 @@ class ContentElement extends Model
'kind',
'output_class',
'working_title',
'display_title',
'description',
'summary',
'editorial_content_kind_id',
'archived_at',
];
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class EditorialDimension extends Model
{
protected $fillable = ['slug', 'label'];
public function values(): HasMany
{
return $this->hasMany(EditorialDimensionValue::class);
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EditorialDimensionValue extends Model
{
protected $fillable = ['editorial_dimension_id', 'slug', 'label'];
public function dimension(): BelongsTo
{
return $this->belongsTo(EditorialDimension::class, 'editorial_dimension_id');
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class IdentityChange extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'field',
'before',
'after',
'actor_id',
'occurred_at',
];
protected function casts(): array
{
return [
'occurred_at' => 'datetime',
];
}
public function actor(): BelongsTo
{
return $this->belongsTo(User::class, 'actor_id');
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
class IdentityDimension
{
public function assign(Model $subject, EditorialDimensionValue $value, string $origin = 'direkt'): void
{
if (! in_array($origin, ['direkt', 'abgeleitet'], true)) {
throw new DomainRuleException('Die Herkunft einer Zuordnung ist direkt oder abgeleitet.');
}
IdentityDimensionValue::query()->updateOrCreate(
[
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'editorial_dimension_value_id' => $value->id,
],
['origin' => $origin],
);
}
/**
* @param list<int> $valueIds
*/
public function matches(Model $subject, array $valueIds): bool
{
if ($valueIds === []) {
return true;
}
$assigned = IdentityDimensionValue::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->pluck('editorial_dimension_value_id')
->all();
$wanted = EditorialDimensionValue::query()->whereIn('id', $valueIds)->get()->groupBy('editorial_dimension_id');
if ($wanted->isEmpty()) {
return false;
}
foreach ($wanted as $group) {
$ids = $group->pluck('id')->all();
if (array_intersect($ids, $assigned) === []) {
return false;
}
}
return true;
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
class IdentityDimensionValue extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'editorial_dimension_value_id',
'origin',
];
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class IdentityProfile
{
/**
* @param array<string, mixed> $fields
*/
public function fill(Model $subject, array $fields, ?User $actor = null): void
{
foreach ($fields as $field => $value) {
$next = is_string($value) ? trim($value) : $value;
$next = $next === '' ? null : $next;
$before = $subject->getAttribute($field);
$before = $before === '' ? null : $before;
if ($before === $next) {
continue;
}
$subject->setAttribute($field, $next);
IdentityChange::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => $field,
'before' => $before,
'after' => $next,
'actor_id' => $actor?->id,
'occurred_at' => now(),
]);
}
$subject->save();
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Domain\Catalog;
class OfferCoverage
{
public function __construct(private readonly ContentResolver $resolver) {}
/**
* @param list<LicenseArticle> $articles
* @return list<string>
*/
public function missingLeaves(CompositionVersion $version, array $articles): array
{
$covered = [];
foreach ($articles as $article) {
$release = $article->currentRelease;
if ($release === null) {
continue;
}
foreach ($release->contents()->pluck('content_element_version_id') as $id) {
$covered[(int) $id] = true;
}
}
$missing = [];
foreach ($this->resolver->expand($version) as $row) {
if (! isset($covered[$row['version_id']])) {
$missing[] = $row['path'];
}
}
return $missing;
}
}
+29
View File
@@ -89,6 +89,7 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of
$this->assertAttributes($attributes);
$scope = $this->scopeFor($lines);
$this->assertCoverage($lines, $attributes);
return DB::transaction(function () use ($offer, $lines, $attributes, $scope): OfferVersion {
$offer = Offer::query()->lockForUpdate()->findOrFail($offer->id);
@@ -171,6 +172,34 @@ private function assertAttributes(array $attributes): void
* @param list<array{target: LicenseArticle|BundleVersion, rights: RightsProfileVersion}> $lines
* @return list<array{license_article_id: int, rights_profile_version_id: int}>
*/
/**
* @param list<array{target: LicenseArticle|BundleVersion, rights: RightsProfileVersion}> $lines
* @param array<string, mixed> $attributes
*/
private function assertCoverage(array $lines, array $attributes): void
{
$versionId = $attributes['composition_version_id'] ?? null;
if ($versionId === null) {
return;
}
$version = CompositionVersion::query()->findOrFail($versionId);
$articles = [];
foreach ($lines as $line) {
if ($line['target'] instanceof LicenseArticle) {
$articles[] = $line['target'];
}
}
$missing = app(OfferCoverage::class)->missingLeaves($version, $articles);
if ($missing !== []) {
throw new DomainRuleException('Das Angebot deckt nicht alle Blätter: '.implode(', ', $missing));
}
}
private function scopeFor(array $lines): array
{
$scope = [];