Build world campaigns rewards and recaps
This commit is contained in:
43
app/Http/Controllers/Api/WorldAnalyticsEventController.php
Normal file
43
app/Http/Controllers/Api/WorldAnalyticsEventController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Worlds\WorldAnalyticsService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
final class WorldAnalyticsEventController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly WorldAnalyticsService $analytics,
|
||||
) {
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'world_id' => ['required', 'integer', 'exists:worlds,id'],
|
||||
'event_type' => ['required', 'string', Rule::in($this->analytics->allowedEventTypes())],
|
||||
'section_key' => ['sometimes', 'nullable', 'string', 'max:80'],
|
||||
'cta_key' => ['sometimes', 'nullable', 'string', 'max:80'],
|
||||
'entity_type' => ['sometimes', 'nullable', 'string', 'max:40'],
|
||||
'entity_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
'entity_title' => ['sometimes', 'nullable', 'string', 'max:180'],
|
||||
'challenge_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
'source_surface' => ['sometimes', 'nullable', 'string', Rule::in($this->analytics->allowedSourceSurfaces())],
|
||||
'source_detail' => ['sometimes', 'nullable', 'string', 'max:80'],
|
||||
'visitor_token' => ['sometimes', 'nullable', 'string', 'max:100'],
|
||||
'meta' => ['sometimes', 'array'],
|
||||
]);
|
||||
|
||||
$this->analytics->recordEvent($request, $payload);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
], 202);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use App\Models\Group;
|
||||
use App\Models\GroupChallenge;
|
||||
use App\Services\GroupChallengeService;
|
||||
use App\Services\GroupService;
|
||||
use App\Services\Worlds\WorldService;
|
||||
use App\Support\Seo\SeoFactory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -22,6 +23,7 @@ class GroupChallengeController extends Controller
|
||||
public function __construct(
|
||||
private readonly GroupService $groups,
|
||||
private readonly GroupChallengeService $challenges,
|
||||
private readonly WorldService $worlds,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ class GroupChallengeController extends Controller
|
||||
return Inertia::render('Group/GroupChallengeShow', [
|
||||
'group' => $groupPayload,
|
||||
'challenge' => $challengePayload,
|
||||
'linkedWorld' => $this->worlds->linkedWorldForChallenge($challenge),
|
||||
'seo' => $seo,
|
||||
])->rootView('collections');
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Http\Requests\Groups\UpdateGroupChallengeRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupChallenge;
|
||||
use App\Models\GroupChallengeOutcome;
|
||||
use App\Services\GroupChallengeService;
|
||||
use App\Services\GroupService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -53,6 +54,7 @@ class GroupChallengeStudioController extends Controller
|
||||
'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(),
|
||||
'outcomeTypeOptions' => collect(GroupChallengeOutcome::supportedTypes())->map(fn (string $value): array => ['value' => $value, 'label' => GroupChallengeOutcome::labelForType($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(),
|
||||
@@ -84,6 +86,7 @@ class GroupChallengeStudioController extends Controller
|
||||
'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(),
|
||||
'outcomeTypeOptions' => collect(GroupChallengeOutcome::supportedTypes())->map(fn (string $value): array => ['value' => $value, 'label' => GroupChallengeOutcome::labelForType($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(),
|
||||
|
||||
@@ -4,11 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Studio;
|
||||
|
||||
use App\Enums\WorldRewardType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Worlds\StoreWorldRequest;
|
||||
use App\Http\Requests\Worlds\UpdateWorldRequest;
|
||||
use App\Models\World;
|
||||
use App\Models\WorldSubmission;
|
||||
use App\Services\Worlds\WorldAnalyticsService;
|
||||
use App\Services\Worlds\WorldEditorialSuggestionService;
|
||||
use App\Services\Worlds\WorldRewardService;
|
||||
use App\Services\Worlds\WorldService;
|
||||
use App\Services\Worlds\WorldSubmissionService;
|
||||
use App\Support\Seo\SeoFactory;
|
||||
@@ -22,7 +26,10 @@ final class StudioWorldController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly WorldService $worlds,
|
||||
private readonly WorldEditorialSuggestionService $editorialSuggestions,
|
||||
private readonly WorldSubmissionService $submissions,
|
||||
private readonly WorldRewardService $rewards,
|
||||
private readonly WorldAnalyticsService $analytics,
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -35,6 +42,7 @@ final class StudioWorldController extends Controller
|
||||
'title' => 'Worlds',
|
||||
'description' => 'Create and manage seasonal, event, and campaign destinations across Skinbase Nova.',
|
||||
'listing' => $this->worlds->studioListing($request->only(['q', 'status', 'type', 'per_page'])),
|
||||
'analytics' => $this->analytics->portfolioReport(),
|
||||
'statusOptions' => [
|
||||
['value' => World::STATUS_DRAFT, 'label' => 'Draft'],
|
||||
['value' => World::STATUS_PUBLISHED, 'label' => 'Published'],
|
||||
@@ -76,6 +84,8 @@ final class StudioWorldController extends Controller
|
||||
],
|
||||
'storeUrl' => route('studio.worlds.store'),
|
||||
'entitySearchUrl' => route('studio.worlds.entity-search'),
|
||||
'suggestions' => null,
|
||||
'suggestionActions' => null,
|
||||
'duplicateActions' => null,
|
||||
'mediaSupport' => [
|
||||
'picker_available' => false,
|
||||
@@ -123,12 +133,23 @@ final class StudioWorldController extends Controller
|
||||
'updateUrl' => route('studio.worlds.update', ['world' => $world]),
|
||||
'previewUrl' => route('studio.worlds.preview', ['world' => $world]),
|
||||
'publishUrl' => route('studio.worlds.publish', ['world' => $world]),
|
||||
'publishRecapUrl' => route('studio.worlds.recap.publish', ['world' => $world]),
|
||||
'archiveUrl' => route('studio.worlds.archive', ['world' => $world]),
|
||||
'entitySearchUrl' => route('studio.worlds.entity-search'),
|
||||
'suggestions' => $this->editorialSuggestions->editorPayload($world, $request->user()),
|
||||
'suggestionActions' => [
|
||||
'add' => route('studio.worlds.suggestions.add', ['world' => $world]),
|
||||
'pin' => route('studio.worlds.suggestions.pin', ['world' => $world]),
|
||||
'dismiss' => route('studio.worlds.suggestions.dismiss', ['world' => $world]),
|
||||
'notRelevant' => route('studio.worlds.suggestions.not-relevant', ['world' => $world]),
|
||||
'restore' => route('studio.worlds.suggestions.restore', ['world' => $world]),
|
||||
],
|
||||
'duplicateActions' => [
|
||||
'duplicateUrl' => route('studio.worlds.duplicate', ['world' => $world]),
|
||||
'newEditionUrl' => route('studio.worlds.new-edition', ['world' => $world]),
|
||||
'canCreateEdition' => $this->worlds->canCreateNewEdition($world),
|
||||
'duplicateModeOptions' => $this->worlds->duplicateModeOptions(false),
|
||||
'newEditionModeOptions' => $this->worlds->duplicateModeOptions(true),
|
||||
],
|
||||
'mediaSupport' => [
|
||||
'picker_available' => false,
|
||||
@@ -169,12 +190,33 @@ final class StudioWorldController extends Controller
|
||||
return back()->with('success', 'World archived.');
|
||||
}
|
||||
|
||||
public function publishRecap(Request $request, World $world): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$this->worlds->publishRecap($world);
|
||||
|
||||
return back()->with('success', 'World recap published.');
|
||||
}
|
||||
|
||||
public function duplicate(Request $request, World $world): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', World::class);
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$duplicate = $this->worlds->duplicate($world, $request->user(), false);
|
||||
$validated = $request->validate([
|
||||
'copy_mode' => ['nullable', 'string', 'in:' . implode(',', [
|
||||
WorldService::COPY_MODE_STRUCTURE_ONLY,
|
||||
WorldService::COPY_MODE_WITH_RELATIONS,
|
||||
])],
|
||||
]);
|
||||
|
||||
$duplicate = $this->worlds->duplicateWithMode(
|
||||
$world,
|
||||
$request->user(),
|
||||
false,
|
||||
(string) ($validated['copy_mode'] ?? WorldService::COPY_MODE_WITH_RELATIONS),
|
||||
);
|
||||
|
||||
return redirect()->route('studio.worlds.edit', ['world' => $duplicate])->with('success', 'World duplicated into a new draft.');
|
||||
}
|
||||
@@ -184,7 +226,19 @@ final class StudioWorldController extends Controller
|
||||
$this->authorize('create', World::class);
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$edition = $this->worlds->duplicate($world, $request->user(), true);
|
||||
$validated = $request->validate([
|
||||
'copy_mode' => ['nullable', 'string', 'in:' . implode(',', [
|
||||
WorldService::COPY_MODE_STRUCTURE_ONLY,
|
||||
WorldService::COPY_MODE_WITH_RELATIONS,
|
||||
])],
|
||||
]);
|
||||
|
||||
$edition = $this->worlds->duplicateWithMode(
|
||||
$world,
|
||||
$request->user(),
|
||||
true,
|
||||
(string) ($validated['copy_mode'] ?? WorldService::COPY_MODE_WITH_RELATIONS),
|
||||
);
|
||||
|
||||
return redirect()->route('studio.worlds.edit', ['world' => $edition])->with('success', 'Next edition draft created.');
|
||||
}
|
||||
@@ -203,6 +257,106 @@ final class StudioWorldController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function addSuggestion(Request $request, World $world): JsonResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$validated = $request->validate([
|
||||
'related_type' => ['required', 'string'],
|
||||
'related_id' => ['required', 'integer', 'min:1'],
|
||||
'section_key' => ['required', 'string'],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
$this->editorialSuggestions->addSuggestionToSection(
|
||||
$world,
|
||||
$request->user(),
|
||||
(string) $validated['related_type'],
|
||||
(int) $validated['related_id'],
|
||||
(string) $validated['section_key'],
|
||||
(bool) ($validated['is_featured'] ?? false),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function pinSuggestion(Request $request, World $world): JsonResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$validated = $request->validate([
|
||||
'related_type' => ['required', 'string'],
|
||||
'related_id' => ['required', 'integer', 'min:1'],
|
||||
'section_key' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
$this->editorialSuggestions->pinSuggestion(
|
||||
$world,
|
||||
$request->user(),
|
||||
(string) $validated['related_type'],
|
||||
(int) $validated['related_id'],
|
||||
(string) ($validated['section_key'] ?? ''),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function dismissSuggestion(Request $request, World $world): JsonResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$validated = $request->validate([
|
||||
'related_type' => ['required', 'string'],
|
||||
'related_id' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
$this->editorialSuggestions->dismissSuggestion(
|
||||
$world,
|
||||
$request->user(),
|
||||
(string) $validated['related_type'],
|
||||
(int) $validated['related_id'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function markSuggestionNotRelevant(Request $request, World $world): JsonResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$validated = $request->validate([
|
||||
'related_type' => ['required', 'string'],
|
||||
'related_id' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
$this->editorialSuggestions->markSuggestionNotRelevant(
|
||||
$world,
|
||||
$request->user(),
|
||||
(string) $validated['related_type'],
|
||||
(int) $validated['related_id'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function restoreSuggestion(Request $request, World $world): JsonResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$validated = $request->validate([
|
||||
'related_type' => ['required', 'string'],
|
||||
'related_id' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
$this->editorialSuggestions->restoreSuggestion(
|
||||
$world,
|
||||
(string) $validated['related_type'],
|
||||
(int) $validated['related_id'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function approveSubmission(Request $request, World $world, WorldSubmission $submission): RedirectResponse
|
||||
{
|
||||
return $this->transitionSubmission($request, $world, $submission, WorldSubmission::STATUS_LIVE, 'Submission approved and is now live.');
|
||||
@@ -243,11 +397,43 @@ final class StudioWorldController extends Controller
|
||||
return $this->transitionSubmission($request, $world, $submission, WorldSubmission::STATUS_PENDING, 'Submission returned to pending.');
|
||||
}
|
||||
|
||||
public function grantSubmissionReward(Request $request, World $world, WorldSubmission $submission, string $rewardType): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
abort_unless((int) $submission->world_id === (int) $world->id, 404);
|
||||
|
||||
$reward = WorldRewardType::tryFrom($rewardType);
|
||||
abort_if($reward === null || $reward->isAutomatic(), 404);
|
||||
|
||||
$validated = $request->validate([
|
||||
'review_note' => ['nullable', 'string', 'max:1000'],
|
||||
]);
|
||||
|
||||
$this->rewards->grantManualReward($submission, $request->user(), $reward, (string) ($validated['review_note'] ?? ''));
|
||||
|
||||
return back()->with('success', $reward->label() . ' reward granted.');
|
||||
}
|
||||
|
||||
public function revokeSubmissionReward(Request $request, World $world, WorldSubmission $submission, string $rewardType): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
abort_unless((int) $submission->world_id === (int) $world->id, 404);
|
||||
|
||||
$reward = WorldRewardType::tryFrom($rewardType);
|
||||
abort_if($reward === null || $reward->isAutomatic(), 404);
|
||||
|
||||
$this->rewards->revokeManualReward($submission, $reward);
|
||||
|
||||
return back()->with('success', $reward->label() . ' reward revoked.');
|
||||
}
|
||||
|
||||
public function preview(Request $request, World $world): \Inertia\Response
|
||||
{
|
||||
$this->authorize('update', $world);
|
||||
|
||||
$payload = $this->worlds->publicShowPayload($world, $request->user());
|
||||
$payload = $this->worlds->publicShowPayload($world, $request->user(), true);
|
||||
$seo = app(SeoFactory::class)->collectionPage(
|
||||
$world->seo_title ?: ($world->title . ' — Skinbase Nova Preview'),
|
||||
$world->seo_description ?: ($world->summary ?: $world->description ?: 'Preview world page'),
|
||||
|
||||
@@ -32,6 +32,13 @@ class StoreGroupChallengeRequest extends FormRequest
|
||||
'linked_collection_id' => ['nullable', 'integer'],
|
||||
'linked_project_id' => ['nullable', 'integer'],
|
||||
'featured_artwork_id' => ['nullable', 'integer'],
|
||||
'outcomes' => ['nullable', 'array'],
|
||||
'outcomes.*.artwork_id' => ['required_with:outcomes', 'integer'],
|
||||
'outcomes.*.outcome_type' => ['required_with:outcomes', 'in:' . implode(',', (array) config('groups.challenges.outcome_types', []))],
|
||||
'outcomes.*.position' => ['nullable', 'integer', 'min:1'],
|
||||
'outcomes.*.sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
'outcomes.*.title_override' => ['nullable', 'string', 'max:120'],
|
||||
'outcomes.*.note' => ['nullable', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@ declare(strict_types=1);
|
||||
namespace App\Http\Requests\Worlds;
|
||||
|
||||
use App\Models\World;
|
||||
use App\Models\GroupChallenge;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreWorldRequest extends FormRequest
|
||||
@@ -34,8 +36,11 @@ class StoreWorldRequest extends FormRequest
|
||||
'slug' => ['nullable', 'string', 'max:180', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/', Rule::notIn($this->reservedSlugs())],
|
||||
'tagline' => ['nullable', 'string', 'max:220'],
|
||||
'summary' => ['nullable', 'string', 'max:320'],
|
||||
'teaser_title' => ['nullable', 'string', 'max:180'],
|
||||
'teaser_summary' => ['nullable', 'string', 'max:320'],
|
||||
'description' => ['nullable', 'string', 'max:20000'],
|
||||
'cover_path' => ['nullable', 'string', 'max:2048'],
|
||||
'teaser_image_path' => ['nullable', 'string', 'max:2048'],
|
||||
'theme_key' => ['nullable', 'string', 'max:80'],
|
||||
'accent_color' => ['nullable', 'string', 'max:16'],
|
||||
'accent_color_secondary' => ['nullable', 'string', 'max:16'],
|
||||
@@ -45,6 +50,8 @@ class StoreWorldRequest extends FormRequest
|
||||
'type' => ['required', Rule::in([World::TYPE_SEASONAL, World::TYPE_EVENT, World::TYPE_CAMPAIGN, World::TYPE_TRIBUTE])],
|
||||
'starts_at' => ['nullable', 'date'],
|
||||
'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
|
||||
'promotion_starts_at' => ['nullable', 'date'],
|
||||
'promotion_ends_at' => ['nullable', 'date', 'after_or_equal:promotion_starts_at'],
|
||||
'accepts_submissions' => ['nullable', 'boolean'],
|
||||
'participation_mode' => ['nullable', Rule::in([
|
||||
World::PARTICIPATION_MODE_MANUAL_APPROVAL,
|
||||
@@ -57,6 +64,9 @@ class StoreWorldRequest extends FormRequest
|
||||
'community_section_enabled' => ['nullable', 'boolean'],
|
||||
'allow_readd_after_removal' => ['nullable', 'boolean'],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
'is_active_campaign' => ['nullable', 'boolean'],
|
||||
'is_homepage_featured' => ['nullable', 'boolean'],
|
||||
'campaign_priority' => ['nullable', 'integer', 'min:0', 'max:9999'],
|
||||
'is_recurring' => ['nullable', 'boolean'],
|
||||
'recurrence_key' => ['nullable', 'string', 'max:120'],
|
||||
'recurrence_rule' => ['nullable', 'string', 'max:160'],
|
||||
@@ -64,12 +74,22 @@ class StoreWorldRequest extends FormRequest
|
||||
'cta_label' => ['nullable', 'string', 'max:120'],
|
||||
'cta_url' => ['nullable', 'url', 'max:2048'],
|
||||
'badge_label' => ['nullable', 'string', 'max:120'],
|
||||
'campaign_label' => ['nullable', 'string', 'max:120'],
|
||||
'badge_description' => ['nullable', 'string', 'max:2000'],
|
||||
'submission_guidelines' => ['nullable', 'string', 'max:5000'],
|
||||
'badge_url' => ['nullable', 'url', 'max:2048'],
|
||||
'seo_title' => ['nullable', 'string', 'max:255'],
|
||||
'seo_description' => ['nullable', 'string', 'max:300'],
|
||||
'og_image_path' => ['nullable', 'string', 'max:2048'],
|
||||
'recap_status' => ['nullable', Rule::in([World::RECAP_STATUS_DRAFT, World::RECAP_STATUS_PUBLISHED])],
|
||||
'recap_title' => ['nullable', 'string', 'max:180'],
|
||||
'recap_summary' => ['nullable', 'string', 'max:320'],
|
||||
'recap_intro' => ['nullable', 'string', 'max:12000'],
|
||||
'recap_editor_note' => ['nullable', 'string', 'max:4000'],
|
||||
'recap_cover_path' => ['nullable', 'string', 'max:2048'],
|
||||
'recap_article_id' => ['nullable', 'integer', 'exists:news_articles,id'],
|
||||
'recap_stats_snapshot_json' => ['nullable', 'array'],
|
||||
'recap_published_at' => ['nullable', 'date'],
|
||||
'related_tags_json' => ['nullable', 'array', 'max:12'],
|
||||
'related_tags_json.*' => ['string', 'max:40'],
|
||||
'section_order_json' => ['nullable', 'array'],
|
||||
@@ -77,6 +97,15 @@ class StoreWorldRequest extends FormRequest
|
||||
'section_visibility_json' => ['nullable', 'array'],
|
||||
'section_visibility_json.*' => ['boolean'],
|
||||
'parent_world_id' => ['nullable', 'integer', 'exists:worlds,id'],
|
||||
'linked_challenge_id' => ['nullable', 'integer', 'exists:group_challenges,id'],
|
||||
'show_linked_challenge_section' => ['nullable', 'boolean'],
|
||||
'show_linked_challenge_entries' => ['nullable', 'boolean'],
|
||||
'show_linked_challenge_winners' => ['nullable', 'boolean'],
|
||||
'show_linked_challenge_finalists' => ['nullable', 'boolean'],
|
||||
'auto_grant_challenge_world_rewards' => ['nullable', 'boolean'],
|
||||
'challenge_teaser_override' => ['nullable', 'string', 'max:2000'],
|
||||
'hidden_linked_challenge_artwork_ids_json' => ['nullable', 'array'],
|
||||
'hidden_linked_challenge_artwork_ids_json.*' => ['integer', 'distinct', 'exists:artworks,id'],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
'relations' => ['nullable', 'array', 'max:60'],
|
||||
'relations.*.section_key' => ['required_with:relations', 'string', Rule::in($sectionKeys)],
|
||||
@@ -92,25 +121,32 @@ class StoreWorldRequest extends FormRequest
|
||||
{
|
||||
$validator->after(function ($validator): void {
|
||||
$sections = (array) config('worlds.sections', []);
|
||||
$recurrenceKey = trim((string) $this->input('recurrence_key', ''));
|
||||
$editionYear = $this->input('edition_year');
|
||||
$hasRecurrenceSignals = $this->boolean('is_recurring')
|
||||
|| $recurrenceKey !== ''
|
||||
|| is_numeric($editionYear)
|
||||
|| trim((string) $this->input('recurrence_rule', '')) !== '';
|
||||
|
||||
if ($this->boolean('is_recurring')) {
|
||||
if (trim((string) $this->input('recurrence_key', '')) === '') {
|
||||
if ($hasRecurrenceSignals && ! $this->boolean('is_recurring')) {
|
||||
$validator->errors()->add('is_recurring', 'Turn on recurrence when this world belongs to a recurring campaign family.');
|
||||
}
|
||||
|
||||
if ($hasRecurrenceSignals) {
|
||||
if ($recurrenceKey === '') {
|
||||
$validator->errors()->add('recurrence_key', 'Recurring worlds need a recurrence key such as halloween or retro-month.');
|
||||
}
|
||||
|
||||
if (! is_numeric($this->input('edition_year'))) {
|
||||
if (! is_numeric($editionYear)) {
|
||||
$validator->errors()->add('edition_year', 'Recurring worlds need an edition year.');
|
||||
}
|
||||
}
|
||||
|
||||
$recurrenceKey = trim((string) $this->input('recurrence_key', ''));
|
||||
$editionYear = $this->input('edition_year');
|
||||
|
||||
if ($recurrenceKey !== '' && ! preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $recurrenceKey)) {
|
||||
$validator->errors()->add('recurrence_key', 'Use lowercase letters, numbers, and dashes only.');
|
||||
}
|
||||
|
||||
if ($this->boolean('is_recurring') && $recurrenceKey !== '' && is_numeric($editionYear)) {
|
||||
if ($hasRecurrenceSignals && $recurrenceKey !== '' && is_numeric($editionYear)) {
|
||||
$worldId = $this->route('world')?->id;
|
||||
$exists = World::query()
|
||||
->where('recurrence_key', $recurrenceKey)
|
||||
@@ -121,6 +157,25 @@ class StoreWorldRequest extends FormRequest
|
||||
if ($exists) {
|
||||
$validator->errors()->add('edition_year', 'That recurrence key already has an edition for this year.');
|
||||
}
|
||||
|
||||
$startsAt = $this->filled('starts_at') ? Carbon::parse((string) $this->input('starts_at')) : null;
|
||||
$endsAt = $this->filled('ends_at') ? Carbon::parse((string) $this->input('ends_at')) : null;
|
||||
$wouldBeCurrentNow = (string) $this->input('status') === World::STATUS_PUBLISHED
|
||||
&& ($startsAt === null || ! $startsAt->isFuture())
|
||||
&& ($endsAt === null || ! $endsAt->isPast());
|
||||
|
||||
if ($wouldBeCurrentNow) {
|
||||
$hasCurrentConflict = World::query()
|
||||
->published()
|
||||
->where('recurrence_key', $recurrenceKey)
|
||||
->when($worldId, fn (Builder $builder) => $builder->where('id', '!=', $worldId))
|
||||
->get()
|
||||
->contains(fn (World $world): bool => $world->isCurrent());
|
||||
|
||||
if ($hasCurrentConflict) {
|
||||
$validator->errors()->add('status', 'This recurrence family already has a current published edition. Archive it or move its dates before publishing another current edition.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) $this->input('relations', []) as $index => $relation) {
|
||||
@@ -136,6 +191,87 @@ class StoreWorldRequest extends FormRequest
|
||||
if ((string) $this->input('participation_mode') === World::PARTICIPATION_MODE_CLOSED && $this->boolean('accepts_submissions')) {
|
||||
$validator->errors()->add('accepts_submissions', 'Closed worlds cannot accept creator submissions.');
|
||||
}
|
||||
|
||||
if ($this->boolean('is_homepage_featured') && ! $this->boolean('is_active_campaign')) {
|
||||
$validator->errors()->add('is_active_campaign', 'Homepage featured worlds must also be marked as active campaigns.');
|
||||
}
|
||||
|
||||
$linkedChallengeId = (int) $this->input('linked_challenge_id', 0);
|
||||
|
||||
if ($linkedChallengeId > 0) {
|
||||
$challenge = GroupChallenge::query()->with('group')->find($linkedChallengeId);
|
||||
|
||||
if (! $challenge) {
|
||||
$validator->errors()->add('linked_challenge_id', 'Select a valid linked challenge.');
|
||||
} elseif ((string) $challenge->status === GroupChallenge::STATUS_DRAFT && (string) $this->input('status') !== World::STATUS_DRAFT) {
|
||||
$validator->errors()->add('linked_challenge_id', 'Draft challenges can only be linked while the world is still a draft.');
|
||||
} elseif ((string) $this->input('status') === World::STATUS_PUBLISHED && (string) $challenge->status === GroupChallenge::STATUS_ARCHIVED) {
|
||||
$validator->errors()->add('linked_challenge_id', 'Archived challenges cannot be linked to a live world.');
|
||||
} elseif ((string) $this->input('status') === World::STATUS_PUBLISHED && ! $this->linkedChallengeMatchesWorldWindow($challenge)) {
|
||||
$validator->errors()->add('linked_challenge_id', 'The linked challenge should overlap this world\'s intended campaign window.');
|
||||
}
|
||||
|
||||
if ($challenge) {
|
||||
$challengeArtworkIds = $challenge->artworkLinks()
|
||||
->pluck('artwork_id')
|
||||
->map(fn ($id): int => (int) $id)
|
||||
->all();
|
||||
|
||||
$invalidHiddenArtworkIds = collect((array) $this->input('hidden_linked_challenge_artwork_ids_json', []))
|
||||
->map(fn ($id): int => (int) $id)
|
||||
->filter(fn (int $id): bool => $id > 0)
|
||||
->diff($challengeArtworkIds)
|
||||
->values();
|
||||
|
||||
if ($invalidHiddenArtworkIds->isNotEmpty()) {
|
||||
$validator->errors()->add('hidden_linked_challenge_artwork_ids_json', 'Hidden challenge entries must belong to the linked challenge.');
|
||||
}
|
||||
}
|
||||
} elseif (collect((array) $this->input('hidden_linked_challenge_artwork_ids_json', []))->filter()->isNotEmpty()) {
|
||||
$validator->errors()->add('hidden_linked_challenge_artwork_ids_json', 'Hide specific challenge entries only after linking a primary challenge.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function linkedChallengeMatchesWorldWindow(GroupChallenge $challenge): bool
|
||||
{
|
||||
$worldStartsAt = $this->dateInput('promotion_starts_at') ?? $this->dateInput('starts_at');
|
||||
$worldEndsAt = $this->dateInput('promotion_ends_at') ?? $this->dateInput('ends_at');
|
||||
$challengeStartsAt = $challenge->start_at;
|
||||
$challengeEndsAt = $challenge->end_at;
|
||||
|
||||
if (! $worldStartsAt && ! $worldEndsAt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $challengeStartsAt && ! $challengeEndsAt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$effectiveWorldStart = $worldStartsAt ?? $worldEndsAt;
|
||||
$effectiveWorldEnd = $worldEndsAt ?? $worldStartsAt;
|
||||
$effectiveChallengeStart = $challengeStartsAt ?? $challengeEndsAt;
|
||||
$effectiveChallengeEnd = $challengeEndsAt ?? $challengeStartsAt;
|
||||
|
||||
if (! $effectiveWorldStart || ! $effectiveWorldEnd || ! $effectiveChallengeStart || ! $effectiveChallengeEnd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $effectiveChallengeStart->lte($effectiveWorldEnd) && $effectiveChallengeEnd->gte($effectiveWorldStart);
|
||||
}
|
||||
|
||||
private function dateInput(string $key): ?Carbon
|
||||
{
|
||||
$value = $this->input($key);
|
||||
|
||||
if (! is_string($value) || trim($value) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Carbon::parse($value);
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user