Commit workspace changes

This commit is contained in:
2026-04-05 19:42:33 +02:00
parent 148a3bbe43
commit 08ad757bcb
312 changed files with 35149 additions and 399 deletions

View File

@@ -0,0 +1,126 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Studio;
use App\Http\Controllers\Controller;
use App\Http\Requests\Groups\AttachArtworkToGroupChallengeRequest;
use App\Http\Requests\Groups\StoreGroupChallengeRequest;
use App\Http\Requests\Groups\UpdateGroupChallengeRequest;
use App\Models\Artwork;
use App\Models\Group;
use App\Models\GroupChallenge;
use App\Services\GroupChallengeService;
use App\Services\GroupService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class GroupChallengeStudioController extends Controller
{
public function __construct(
private readonly GroupService $groups,
private readonly GroupChallengeService $challenges,
) {
}
public function index(Request $request, Group $group): Response
{
$this->authorize('manageChallenges', $group);
return Inertia::render('Studio/StudioGroupChallenges', [
'title' => $group->name . ' Challenges',
'description' => 'Run creative prompts, themed sprints, and public or internal participation campaigns.',
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
'listing' => $this->challenges->studioListing($group, $request->only(['bucket', 'page', 'per_page'])),
'recentHistory' => $this->groups->recentHistory($group),
'createUrl' => route('studio.groups.challenges.create', ['group' => $group]),
]);
}
public function create(Request $request, Group $group): Response
{
$this->authorize('manageChallenges', $group);
return Inertia::render('Studio/StudioGroupChallengeEditor', [
'title' => 'Create challenge',
'description' => 'Set the timeline, rules, and participation model for a new group challenge.',
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
'challenge' => null,
'statusOptions' => collect((array) config('groups.challenges.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
'visibilityOptions' => collect((array) config('groups.challenges.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
'participationScopeOptions' => collect((array) config('groups.challenges.participation_scopes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
'judgingModeOptions' => collect((array) config('groups.challenges.judging_modes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
'storeUrl' => route('studio.groups.challenges.store', ['group' => $group]),
]);
}
public function store(StoreGroupChallengeRequest $request, Group $group): RedirectResponse
{
$this->authorize('manageChallenges', $group);
$challenge = $this->challenges->create($group, $request->user(), $request->validated());
return redirect()->route('studio.groups.challenges.edit', ['group' => $group, 'challenge' => $challenge])
->with('success', 'Challenge created.');
}
public function edit(Request $request, Group $group, GroupChallenge $challenge): Response
{
$this->authorize('manageChallenges', $group);
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
return Inertia::render('Studio/StudioGroupChallengeEditor', [
'title' => 'Edit challenge',
'description' => 'Publish and curate challenge entries from one editing view.',
'studioGroup' => $this->groups->mapGroupDetail($group, $request->user()),
'challenge' => $this->challenges->detailPayload($challenge, $request->user()),
'statusOptions' => collect((array) config('groups.challenges.statuses', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
'visibilityOptions' => collect((array) config('groups.challenges.visibility_options', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucfirst($value)])->values()->all(),
'participationScopeOptions' => collect((array) config('groups.challenges.participation_scopes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
'judgingModeOptions' => collect((array) config('groups.challenges.judging_modes', []))->map(fn (string $value): array => ['value' => $value, 'label' => ucwords(str_replace('_', ' ', $value))])->values()->all(),
'collectionOptions' => $group->collections()->orderBy('title')->get(['id', 'title'])->map(fn ($collection): array => ['id' => (int) $collection->id, 'title' => $collection->title])->values()->all(),
'projectOptions' => $group->projects()->orderBy('title')->get(['id', 'title'])->map(fn ($project): array => ['id' => (int) $project->id, 'title' => $project->title])->values()->all(),
'artworkOptions' => $group->artworks()->whereNull('deleted_at')->latest('updated_at')->limit(30)->get(['id', 'title'])->map(fn ($artwork): array => ['id' => (int) $artwork->id, 'title' => $artwork->title])->values()->all(),
'updateUrl' => route('studio.groups.challenges.update', ['group' => $group, 'challenge' => $challenge]),
'publishUrl' => route('studio.groups.challenges.publish', ['group' => $group, 'challenge' => $challenge]),
'attachArtworkUrl' => route('studio.groups.challenges.attach-artwork', ['group' => $group, 'challenge' => $challenge]),
]);
}
public function update(UpdateGroupChallengeRequest $request, Group $group, GroupChallenge $challenge): RedirectResponse
{
$this->authorize('manageChallenges', $group);
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
$this->challenges->update($challenge, $request->user(), $request->validated());
return back()->with('success', 'Challenge updated.');
}
public function publish(Request $request, Group $group, GroupChallenge $challenge): RedirectResponse
{
$this->authorize('manageChallenges', $group);
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
$this->challenges->publish($challenge, $request->user());
return back()->with('success', 'Challenge published.');
}
public function attachArtwork(AttachArtworkToGroupChallengeRequest $request, Group $group, GroupChallenge $challenge): RedirectResponse
{
$this->authorize('manageChallenges', $group);
abort_unless((int) $challenge->group_id === (int) $group->id, 404);
$artwork = Artwork::query()->findOrFail((int) $request->validated('artwork_id'));
$this->challenges->attachArtwork($challenge, $artwork, $request->user());
return back()->with('success', 'Artwork attached to challenge.');
}
}