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
@@ -10,6 +10,8 @@ class Composition extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'designation',
|
||||
'display_title',
|
||||
'summary',
|
||||
'kind',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
|
||||
@@ -13,7 +13,9 @@ class ContentElement extends Model
|
||||
'kind',
|
||||
'output_class',
|
||||
'working_title',
|
||||
'display_title',
|
||||
'description',
|
||||
'summary',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
];
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Entitlement;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaDelivery extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'grant_id',
|
||||
'license_article_id',
|
||||
'article_release_id',
|
||||
'content_element_version_id',
|
||||
'action',
|
||||
'format',
|
||||
'delivered_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'delivered_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
@@ -22,6 +23,7 @@
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
@@ -44,6 +46,9 @@ public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->columns(1)->components([
|
||||
TextInput::make('designation')->label('Bezeichnung')->required(),
|
||||
TextInput::make('display_title')->label('Anzeigetitel')
|
||||
->helperText('Erscheint in der Bibliothek. Leer lässt die Bezeichnung stehen.'),
|
||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||
Select::make('kind')->label('Art')->options(CompositionKind::options())->required()
|
||||
->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'),
|
||||
Select::make('editorial_content_kind_id')
|
||||
@@ -153,6 +158,8 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
|
||||
return [
|
||||
'designation' => $composition->designation,
|
||||
'display_title' => $composition->display_title,
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $kind instanceof CompositionKind ? $kind->value : $kind,
|
||||
'editorial_content_kind_id' => $composition->editorial_content_kind_id,
|
||||
'members' => $members,
|
||||
@@ -169,6 +176,10 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
try {
|
||||
$kind = CompositionKind::from($data['kind']);
|
||||
$record->designation = trim((string) $data['designation']);
|
||||
app(IdentityProfile::class)->fill($record, [
|
||||
'display_title' => $data['display_title'] ?? null,
|
||||
'summary' => $data['summary'] ?? null,
|
||||
], auth()->user());
|
||||
$record->kind = $kind;
|
||||
$record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null)
|
||||
? (int) $data['editorial_content_kind_id']
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
@@ -47,6 +48,9 @@ public function form(Schema $schema): Schema
|
||||
return new HtmlString('<a href="'.e($url).'">Medium und Fassungen ansehen</a>');
|
||||
}),
|
||||
TextInput::make('working_title')->label('Arbeitstitel')->required(),
|
||||
TextInput::make('display_title')->label('Anzeigetitel')
|
||||
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
|
||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||
Textarea::make('description')->label('Beschreibung')->rows(4)
|
||||
->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'),
|
||||
Select::make('editorial_content_kind_id')
|
||||
@@ -121,7 +125,9 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
return [
|
||||
'working_title' => $this->getRecord()->working_title,
|
||||
'display_title' => $this->getRecord()->display_title,
|
||||
'description' => $this->getRecord()->description,
|
||||
'summary' => $this->getRecord()->summary,
|
||||
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
|
||||
];
|
||||
}
|
||||
@@ -134,6 +140,10 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
/** @var ContentElement $record */
|
||||
try {
|
||||
app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null);
|
||||
app(IdentityProfile::class)->fill($record, [
|
||||
'display_title' => $data['display_title'] ?? null,
|
||||
'summary' => $data['summary'] ?? null,
|
||||
], auth()->user());
|
||||
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Entitlement\MediaDelivery;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\CourseOutline;
|
||||
use App\Http\LibraryCatalog;
|
||||
@@ -22,7 +24,42 @@ class LibraryController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
return view('member.library', app(LibraryCatalog::class)->index($request->user()));
|
||||
$catalog = app(LibraryCatalog::class)->index($request->user());
|
||||
$query = trim((string) $request->query('q', ''));
|
||||
|
||||
$dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', []))));
|
||||
$dimensions = app(IdentityDimension::class);
|
||||
|
||||
if ($query !== '') {
|
||||
$catalog['programs'] = array_values(array_filter(
|
||||
$catalog['programs'],
|
||||
fn (array $card): bool => $this->matches($card, $query),
|
||||
));
|
||||
$catalog['materials'] = array_values(array_filter(
|
||||
$catalog['materials'],
|
||||
fn (array $card): bool => $this->matches($card, $query),
|
||||
));
|
||||
}
|
||||
|
||||
if ($dimensionIds !== []) {
|
||||
$catalog['programs'] = array_values(array_filter(
|
||||
$catalog['programs'],
|
||||
fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds),
|
||||
));
|
||||
$catalog['materials'] = array_values(array_filter(
|
||||
$catalog['materials'],
|
||||
function (array $card) use ($dimensions, $dimensionIds): bool {
|
||||
$release = $card['article']->currentRelease;
|
||||
$subject = $release?->rootCompositionVersion?->composition
|
||||
?? $release?->rootElementVersion?->element
|
||||
?? $card['article'];
|
||||
|
||||
return $dimensions->matches($subject, $dimensionIds);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
return view('member.library', [...$catalog, 'query' => $query]);
|
||||
}
|
||||
|
||||
public function program(Request $request, Composition $composition): View
|
||||
@@ -104,6 +141,18 @@ public function media(
|
||||
$decision = app(DecideAccess::class)($request->user(), $article, $release, $version, $action);
|
||||
abort_unless($decision->allowed, 403, $decision->reason);
|
||||
|
||||
if ($decision->grant !== null) {
|
||||
MediaDelivery::query()->create([
|
||||
'grant_id' => $decision->grant->id,
|
||||
'license_article_id' => $article->id,
|
||||
'article_release_id' => $release->id,
|
||||
'content_element_version_id' => $version->id,
|
||||
'action' => $action,
|
||||
'format' => 'bestand',
|
||||
'delivered_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
$version->loadMissing('element');
|
||||
$file = $version->metadata['file'] ?? null;
|
||||
|
||||
@@ -122,6 +171,16 @@ public function media(
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $card
|
||||
*/
|
||||
private function matches(array $card, string $query): bool
|
||||
{
|
||||
$haystack = mb_strtolower(($card['title'] ?? '').' '.($card['summary'] ?? ''));
|
||||
|
||||
return str_contains($haystack, mb_strtolower($query));
|
||||
}
|
||||
|
||||
private function grantQuery(Request $request)
|
||||
{
|
||||
return Grant::query()
|
||||
|
||||
@@ -20,8 +20,13 @@ public function title(LicenseArticle $article): string
|
||||
'rootElementVersion.element',
|
||||
]);
|
||||
|
||||
return $release->rootCompositionVersion?->composition?->designation
|
||||
?? $release->rootElementVersion?->element?->working_title
|
||||
$composition = $release->rootCompositionVersion?->composition;
|
||||
$element = $release->rootElementVersion?->element;
|
||||
|
||||
return (filled($composition?->display_title) ? $composition->display_title : null)
|
||||
?? $composition?->designation
|
||||
?? (filled($element?->display_title) ? $element->display_title : null)
|
||||
?? $element?->working_title
|
||||
?? $release->classification_note
|
||||
?? $article->code;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ public function index(User $user): array
|
||||
$programs[$composition->id] = [
|
||||
'composition' => $composition,
|
||||
'version' => $version,
|
||||
'title' => $composition->designation,
|
||||
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
];
|
||||
@@ -72,7 +73,8 @@ public function program(User $user, Composition $composition): array
|
||||
|
||||
return [
|
||||
'composition' => $composition,
|
||||
'title' => $composition->designation,
|
||||
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
'nodes' => array_map(
|
||||
|
||||
Reference in new issue
Block a user