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
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user