Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7b54c38623
commit
5e763d15ec
23 files changed
+661
-5
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user