ldc-legaulois/app/Http/Controllers/Club/GoldenCrushController.php

95 lines
2.8 KiB
PHP
Raw Normal View History

2026-04-22 17:49:56 +02:00
<?php
namespace App\Http\Controllers\Club;
use App\Http\Controllers\Controller;
2026-05-05 18:16:24 +02:00
use App\Http\Requests\Club\Games\GoldenCrushParticipateRequest;
2026-04-30 17:26:45 +02:00
use App\Lib\Helpers\GamePeriodHelper;
2026-04-29 17:59:19 +02:00
use App\Models\GoldenCrushGame;
2026-04-22 17:49:56 +02:00
class GoldenCrushController extends Controller
{
2026-04-29 17:59:19 +02:00
/**
2026-04-22 17:49:56 +02:00
* Show game page
*
2026-05-05 18:16:24 +02:00
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
2026-04-22 17:49:56 +02:00
*/
2026-05-05 18:16:24 +02:00
public function index(): \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
2026-04-29 17:59:19 +02:00
{
2026-05-05 18:16:24 +02:00
$routeNameForGoldenCrush = GamePeriodHelper::routeName();
2026-04-29 17:59:19 +02:00
$customerId = auth('club')->id();
$hasAlreadyParticipated = $customerId ? GoldenCrushGame::hasCustomerParticipated($customerId) : false;
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.golden-crush', [
2026-04-29 17:59:19 +02:00
'hasAlreadyParticipated' => $hasAlreadyParticipated,
'videos' => GoldenCrushGame::getVideos(),
2026-05-05 18:16:24 +02:00
'routeNameForGoldenCrush' => $routeNameForGoldenCrush,
2026-04-29 17:59:19 +02:00
]);
}
/**
* Register participation of costumer
*
2026-05-05 18:16:24 +02:00
* @param GoldenCrushParticipateRequest $request HTTP Request.
2026-04-29 17:59:19 +02:00
* @return RedirectResponse Response.
*/
2026-05-05 18:16:24 +02:00
public function store(GoldenCrushParticipateRequest $request)
2026-04-29 17:59:19 +02:00
{
$customerId = auth('club')->id();
$alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId);
if ($alreadyParticipated) {
return back()->with('error', 'Votre vote a déjà été enregistré.');
}
2026-05-05 18:16:24 +02:00
if ($request->validated()) {
GoldenCrushGame::create([
'customer_id' => $customerId,
'choice' => $request->integer('choice'),
2026-05-29 11:41:18 +02:00
'ip_address' => app('clientIp'),
2026-05-05 18:16:24 +02:00
]);
}
2026-04-29 17:59:19 +02:00
2026-04-30 17:26:45 +02:00
return redirect()->route('club.golden-crush.thanks-for-participation');
}
/**
* View to thanks if customer has participated.
2026-05-06 17:11:13 +02:00
*
2026-04-30 17:26:45 +02:00
* @return \Illuminate\Contracts\View\View
*/
public function thanksForParticipation(): \Illuminate\Contracts\View\View
{
2026-05-06 17:11:13 +02:00
$customerId = auth('club')->id();
2026-04-30 17:26:45 +02:00
$alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId);
if (!$alreadyParticipated) {
abort(404);
}
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.thanks-for-participation');
2026-04-29 17:59:19 +02:00
}
/**
* View for end of participation if customer has participated.
2026-04-30 17:26:45 +02:00
*
2026-04-29 17:59:19 +02:00
* @return \Illuminate\Contracts\View\View
*/
public function endOfParticipation(): \Illuminate\Contracts\View\View
2026-04-22 17:49:56 +02:00
{
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.end-of-participation');
2026-04-22 17:49:56 +02:00
}
2026-04-30 17:26:45 +02:00
/**
* View for end of game.
*
* @return \Illuminate\Contracts\View\View
*/
public function endOfGame(): \Illuminate\Contracts\View\View
{
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.end-of-game');
2026-04-30 17:26:45 +02:00
}
2026-04-22 17:49:56 +02:00
}