Gestalte den Mitgliederbereich fuer den Kursraum
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
abcdc6908e
commit
1d8315c9a4
21 files changed
+1064
-169
No files matched your search
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
@@ -22,19 +23,37 @@
|
||||
|
||||
class LibraryController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
public function index(Request $request, ?string $sicht = null): View
|
||||
{
|
||||
$catalog = app(LibraryCatalog::class)->index($request->user());
|
||||
$untouched = $catalog['programs'] === [] && $catalog['modules'] === [] && $catalog['materials'] === [];
|
||||
$query = trim((string) $request->query('q', ''));
|
||||
|
||||
$nutzung = (string) $request->query('nutzung', '');
|
||||
$dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', []))));
|
||||
$dimensions = app(IdentityDimension::class);
|
||||
|
||||
foreach (['programs', 'modules'] as $shelf) {
|
||||
if ($query !== '') {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => $this->matches($card, $query),
|
||||
));
|
||||
}
|
||||
if ($dimensionIds !== []) {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds),
|
||||
));
|
||||
}
|
||||
if (in_array($nutzung, ['nutzbar', 'teilweise', 'nicht enthalten'], true)) {
|
||||
$catalog[$shelf] = array_values(array_filter(
|
||||
$catalog[$shelf],
|
||||
fn (array $card): bool => ($card['coverage'] ?? '') === $nutzung,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
@@ -42,10 +61,6 @@ public function index(Request $request): View
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -59,7 +74,29 @@ function (array $card) use ($dimensions, $dimensionIds): bool {
|
||||
));
|
||||
}
|
||||
|
||||
return view('member.library', [...$catalog, 'query' => $query]);
|
||||
if ($nutzung === 'teilweise' || $nutzung === 'nicht enthalten') {
|
||||
$catalog['materials'] = [];
|
||||
}
|
||||
|
||||
return view('member.library', [
|
||||
...$catalog,
|
||||
'query' => $query,
|
||||
'sicht' => $sicht,
|
||||
'nutzung' => $nutzung,
|
||||
'dimensionIds' => $dimensionIds,
|
||||
'filterDimensions' => EditorialDimension::query()->with('values')->orderBy('label')->get(),
|
||||
'libraryEmpty' => $untouched,
|
||||
]);
|
||||
}
|
||||
|
||||
public function programs(Request $request): View
|
||||
{
|
||||
return $this->index($request, 'programme');
|
||||
}
|
||||
|
||||
public function modules(Request $request): View
|
||||
{
|
||||
return $this->index($request, 'module');
|
||||
}
|
||||
|
||||
public function program(Request $request, Composition $composition): View
|
||||
|
||||
@@ -4,15 +4,22 @@
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\LibraryCatalog;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class MemberController extends Controller
|
||||
{
|
||||
public function dashboard(): View
|
||||
public function dashboard(Request $request): View
|
||||
{
|
||||
return view('member.dashboard');
|
||||
$catalog = app(LibraryCatalog::class)->index($request->user());
|
||||
|
||||
return view('member.dashboard', [
|
||||
'programCount' => count($catalog['programs']),
|
||||
'moduleCount' => count($catalog['modules']),
|
||||
'materialCount' => count($catalog['materials']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function profile(): View
|
||||
|
||||
@@ -25,11 +25,12 @@ public function __construct(
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array{programs: list<array<string, mixed>>, materials: list<array<string, mixed>>}
|
||||
* @return array{programs: list<array<string, mixed>>, modules: list<array<string, mixed>>, materials: list<array<string, mixed>>}
|
||||
*/
|
||||
public function index(User $user): array
|
||||
{
|
||||
$programs = [];
|
||||
$modules = [];
|
||||
$materials = [];
|
||||
|
||||
foreach ($this->grants($user) as $grant) {
|
||||
@@ -39,31 +40,42 @@ public function index(User $user): array
|
||||
$version = $release?->rootCompositionVersion;
|
||||
|
||||
if ($composition !== null && $version !== null && $this->display->isReleased($version)) {
|
||||
$programs[$composition->id] = [
|
||||
$card = [
|
||||
'composition' => $composition,
|
||||
'version' => $version,
|
||||
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $composition->editorialContentKind?->label
|
||||
?? ($composition->kind?->label()),
|
||||
'coverage' => $this->coverageLabel($user, $composition),
|
||||
];
|
||||
$shelf = $composition->editorialContentKind?->slug === 'modul' ? 'modules' : 'programs';
|
||||
if ($shelf === 'modules') {
|
||||
$modules[$composition->id] = $card;
|
||||
} else {
|
||||
$programs[$composition->id] = $card;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$elementId = $release?->rootElementVersion?->element_id;
|
||||
$element = $release?->rootElementVersion?->element;
|
||||
$elementId = $element?->id;
|
||||
$key = $composition !== null
|
||||
? 'komposition-'.$composition->id
|
||||
: ($elementId !== null ? 'element-'.$elementId : 'artikel-'.$article->id);
|
||||
$materials[$key] = [
|
||||
'article' => $article,
|
||||
'title' => app(CourseOutline::class)->title($article),
|
||||
'summary' => $element?->summary ?? $composition?->summary,
|
||||
'kind' => app(CourseOutline::class)->kindLabel($article),
|
||||
'coverage' => 'nutzbar',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'programs' => array_values($programs),
|
||||
'modules' => array_values($modules),
|
||||
'materials' => array_values($materials),
|
||||
];
|
||||
}
|
||||
@@ -92,7 +104,7 @@ public function program(User $user, Composition $composition): array
|
||||
'learning_goal' => $version->learning_goal,
|
||||
'duration_minutes' => $version->duration_minutes,
|
||||
'material_note' => $version->material_note,
|
||||
'coverage' => $leaves === [] ? 'nicht nutzbar' : ($open === count($leaves) ? 'vollständig' : ($open === 0 ? 'nicht nutzbar' : 'teilweise')),
|
||||
'coverage' => $leaves === [] ? 'nicht enthalten' : ($open === count($leaves) ? 'nutzbar' : ($open === 0 ? 'nicht enthalten' : 'teilweise')),
|
||||
'nodes' => $nodes,
|
||||
];
|
||||
}
|
||||
@@ -146,6 +158,28 @@ private function leaves(array $nodes): array
|
||||
return $leaves;
|
||||
}
|
||||
|
||||
private function coverageLabel(User $user, Composition $composition): string
|
||||
{
|
||||
$version = $this->display->highestReleasedVersion($composition);
|
||||
|
||||
if ($version === null) {
|
||||
return 'nicht enthalten';
|
||||
}
|
||||
|
||||
$nodes = array_map(
|
||||
fn (StructureNode $node): array => $this->present($user, $node),
|
||||
$this->structure->tree($version),
|
||||
);
|
||||
$leaves = $this->leaves($nodes);
|
||||
$open = count(array_filter($leaves, fn (array $leaf): bool => $leaf['view_url'] !== null));
|
||||
|
||||
if ($leaves === [] || $open === 0) {
|
||||
return 'nicht enthalten';
|
||||
}
|
||||
|
||||
return $open === count($leaves) ? 'nutzbar' : 'teilweise';
|
||||
}
|
||||
|
||||
private function programUrl(StructureNode $node): ?string
|
||||
{
|
||||
if ($node->compositionId === null || $node->compositionVersionId === null) {
|
||||
|
||||
Reference in new issue
Block a user