2020-11-04 11:49:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-02 12:09:46 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2022-01-10 14:02:25 +01:00
|
|
|
namespace App\Http\Controllers\Bo;
|
2020-11-04 11:49:43 +01:00
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Participation;
|
2023-12-05 12:33:25 +01:00
|
|
|
use Illuminate\Contracts\View\View;
|
2026-10-02 12:09:46 +02:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2023-12-13 15:47:48 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-11-04 11:49:43 +01:00
|
|
|
|
2023-12-05 12:33:25 +01:00
|
|
|
class ParticipationController extends Controller
|
2020-11-04 11:49:43 +01:00
|
|
|
{
|
2023-08-23 10:38:11 +00:00
|
|
|
/**
|
2023-12-05 12:33:25 +01:00
|
|
|
* Create the controller instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->authorizeResource(Participation::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* View all winners
|
2023-08-23 10:38:11 +00:00
|
|
|
*/
|
2023-12-05 12:33:25 +01:00
|
|
|
public function viewWinnerList(): View
|
2021-08-18 17:08:02 +02:00
|
|
|
{
|
2023-12-05 12:33:25 +01:00
|
|
|
$this->authorize('viewWinnerList', Participation::class);
|
|
|
|
|
|
2026-10-02 12:09:46 +02:00
|
|
|
/** @var Builder $participationModels */
|
|
|
|
|
$participationModels = Participation::query()
|
|
|
|
|
->with(['customer', 'code', 'instantWin', 'product'])
|
|
|
|
|
->whereHas('instantWin');
|
2020-11-20 15:18:31 +01:00
|
|
|
|
2023-08-23 10:38:11 +00:00
|
|
|
/** Sort columns with a query */
|
|
|
|
|
$this->sortQuery($participationModels);
|
2021-02-23 18:27:03 +01:00
|
|
|
|
2023-08-23 10:38:11 +00:00
|
|
|
/** Custom pagination */
|
2023-11-23 17:31:28 +01:00
|
|
|
$participationModels = $this->paginate($participationModels);
|
2020-11-20 15:18:31 +01:00
|
|
|
|
2026-10-02 12:09:46 +02:00
|
|
|
/** @var view-string $view */
|
|
|
|
|
$view = 'back::pages.winners-list.index';
|
|
|
|
|
|
|
|
|
|
return view($view, ['participationModels' => $participationModels]);
|
2023-12-13 15:47:48 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-13 16:47:28 +01:00
|
|
|
/**
|
|
|
|
|
* Display participation form
|
|
|
|
|
*/
|
|
|
|
|
public function setComment(Participation $participation): View
|
|
|
|
|
{
|
2023-12-13 17:12:11 +01:00
|
|
|
$this->authorize('setComment', $participation);
|
2026-10-02 12:09:46 +02:00
|
|
|
|
|
|
|
|
/** @var view-string $view */
|
|
|
|
|
$view = 'back::pages.winners-list.set-comment';
|
|
|
|
|
|
|
|
|
|
return view($view, [
|
|
|
|
|
'participationModel' => $participation,
|
2023-12-13 16:47:28 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set Comment
|
|
|
|
|
*/
|
|
|
|
|
public function setCommentSubmit(Participation $participation): RedirectResponse
|
|
|
|
|
{
|
2023-12-13 17:12:11 +01:00
|
|
|
$this->authorize('setComment', $participation);
|
2026-10-02 12:09:46 +02:00
|
|
|
|
|
|
|
|
$participation->comment = request()->string('comment')->toString();
|
2023-12-13 16:47:28 +01:00
|
|
|
$participation->saveOrFail();
|
2026-10-02 12:09:46 +02:00
|
|
|
|
2023-12-13 16:47:28 +01:00
|
|
|
return back()->with('success', \trans(
|
|
|
|
|
'Le commentaire à bien été mis à jour'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 15:47:48 +01:00
|
|
|
/**
|
|
|
|
|
* Change prize sent
|
|
|
|
|
*/
|
|
|
|
|
public function changePrizeSent(Participation $participation): RedirectResponse
|
|
|
|
|
{
|
2023-12-13 17:12:11 +01:00
|
|
|
$this->authorize('changePrizeSent', $participation);
|
2023-12-13 15:47:48 +01:00
|
|
|
$participation->prize_sent = true;
|
|
|
|
|
$participation->saveOrFail();
|
2026-10-02 12:09:46 +02:00
|
|
|
|
2023-12-13 15:47:48 +01:00
|
|
|
return back()->with('success', \trans(
|
|
|
|
|
'Le lot est bien marqué comme envoyé et une notification à été envoyé au gagant'
|
2023-08-23 10:38:11 +00:00
|
|
|
));
|
2020-11-20 15:18:31 +01:00
|
|
|
}
|
2020-11-04 11:49:43 +01:00
|
|
|
}
|