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
@@ -7,9 +7,12 @@
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class SeedLibraryReview extends Command
|
||||
{
|
||||
@@ -25,12 +28,31 @@ public function handle(
|
||||
): int {
|
||||
$existing = Composition::query()->where('designation', 'Prüfprogramm Abstand')->first();
|
||||
|
||||
if ($existing !== null) {
|
||||
$this->info('Prüfbestand ist bereits vorhanden.');
|
||||
if ($existing === null) {
|
||||
$created = $this->createFixture($content, $articles, $offers, $display);
|
||||
|
||||
return self::SUCCESS;
|
||||
if ($created !== self::SUCCESS) {
|
||||
return $created;
|
||||
}
|
||||
} else {
|
||||
$existing->display_title = 'Prüfprogramm Abstand und ein bewusst langer Titel für die Kursraumansicht';
|
||||
$existing->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz. Der Titel ist lang, damit die Karte im Kursraum prüfbar bleibt.';
|
||||
$existing->save();
|
||||
}
|
||||
|
||||
$this->ensureTrainer();
|
||||
$this->info('Prüfbestand und Trainingskonto sind bereit.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function createFixture(
|
||||
ContentService $content,
|
||||
ArticleService $articles,
|
||||
OfferService $offers,
|
||||
CompositionDisplayRelease $display,
|
||||
): int {
|
||||
|
||||
$actor = User::query()->find($this->option('actor')) ?? User::query()->orderBy('id')->first();
|
||||
|
||||
if ($actor === null) {
|
||||
@@ -53,8 +75,8 @@ public function handle(
|
||||
);
|
||||
$composition = $content->createComposition('Prüfprogramm Abstand');
|
||||
$composition->editorial_content_kind_id = $kind->id;
|
||||
$composition->display_title = 'Prüfprogramm Abstand';
|
||||
$composition->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz.';
|
||||
$composition->display_title = 'Prüfprogramm Abstand und ein bewusst langer Titel für die Kursraumansicht';
|
||||
$composition->summary = 'Gekennzeichneter Prüfbestand für die Testinstanz. Der Titel ist lang, damit die Karte im Kursraum prüfbar bleibt.';
|
||||
$composition->thumbnail_error = 'Prüfhinweis: kein Vorschaubild.';
|
||||
$composition->save();
|
||||
$version = $content->publishComposition($composition, [
|
||||
@@ -74,8 +96,26 @@ public function handle(
|
||||
['target' => $article->fresh(), 'rights' => $rights],
|
||||
], ['grant_kind' => 'auf_abruf', 'composition_version_id' => $version->id]);
|
||||
$display->release($version, $actor, 'Prüffreigabe');
|
||||
$this->info('Prüfbestand angelegt. Angebot: Prüfprogramm Abstand.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function ensureTrainer(): void
|
||||
{
|
||||
$trainer = User::query()->where('email', 'trainer-pruefung@example.test')->first();
|
||||
|
||||
if ($trainer === null) {
|
||||
$trainer = User::factory()->create([
|
||||
'name' => 'Trainer Prüfung',
|
||||
'email' => 'trainer-pruefung@example.test',
|
||||
'password' => Hash::make('Kursraum-Pruefung'),
|
||||
]);
|
||||
}
|
||||
|
||||
$offer = Offer::query()->where('name', 'Prüfprogramm Abstand')->first();
|
||||
|
||||
if ($offer !== null) {
|
||||
app(GrantIssuer::class)->claim($trainer, $offer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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