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