Files
laraundfelix/app/Domain/Catalog/IdentityDimension.php
LarsandCursor 5e763d15ec
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s
Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:24:23 +01:00

56 lines
1.5 KiB
PHP

<?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;
}
}