1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Controller\Admin; |
6
|
|
|
|
7
|
|
|
use Sonata\AdminBundle\Controller\CRUDController; |
8
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Game; |
12
|
|
|
use VideoGamesRecords\CoreBundle\Form\DefaultForm; |
13
|
|
|
use VideoGamesRecords\CoreBundle\Form\VideoProofOnly; |
14
|
|
|
use VideoGamesRecords\CoreBundle\Manager\GameManager; |
15
|
|
|
use Yokai\SonataWorkflow\Controller\WorkflowControllerTrait; |
16
|
|
|
|
17
|
|
|
class GameAdminController extends CRUDController |
18
|
|
|
{ |
19
|
|
|
use WorkflowControllerTrait; |
20
|
|
|
|
21
|
|
|
private GameManager $gameManager; |
22
|
|
|
|
23
|
|
|
public function __construct(GameManager $gameManager) |
24
|
|
|
{ |
25
|
|
|
$this->gameManager = $gameManager; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param $id |
30
|
|
|
* @param Request $request |
31
|
|
|
* @return Response |
32
|
|
|
*/ |
33
|
|
|
public function copyAction($id, Request $request): Response |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
/** @var Game $game */ |
36
|
|
|
$game = $this->admin->getSubject(); |
37
|
|
|
|
38
|
|
|
$form = $this->createForm(DefaultForm::class); |
39
|
|
|
$form->handleRequest($request); |
40
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
41
|
|
|
$this->gameManager->copy($game); |
42
|
|
|
$this->addFlash('sonata_flash_success', 'The game was successfully copied.'); |
43
|
|
|
return new RedirectResponse($this->admin->generateUrl('show', ['id' => $game->getId()])); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->render( |
47
|
|
|
'@VideoGamesRecordsCore/Admin/Form/form.default.html.twig', |
48
|
|
|
[ |
49
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
50
|
|
|
'admin' => $this->admin, |
51
|
|
|
'object' => $game, |
52
|
|
|
'form' => $form, |
53
|
|
|
'title' => 'Copy => ' . $game->getName(), |
54
|
|
|
'action' => 'edit' |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $id |
61
|
|
|
* @return RedirectResponse |
62
|
|
|
*/ |
63
|
|
|
public function majAction($id): RedirectResponse |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$this->gameManager->maj($this->admin->getSubject()); |
66
|
|
|
$this->addFlash('sonata_flash_success', 'Game maj successfully'); |
67
|
|
|
return new RedirectResponse($this->admin->generateUrl('list')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $id |
72
|
|
|
* @param Request $request |
73
|
|
|
* @return RedirectResponse|Response |
74
|
|
|
*/ |
75
|
|
|
public function setVideoProofOnlyAction($id, Request $request): RedirectResponse|Response |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
/** @var Game $game */ |
78
|
|
|
$game = $this->admin->getSubject(); |
79
|
|
|
|
80
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
|
|
|
|
81
|
|
|
$form = $this->createForm(VideoProofOnly::class); |
82
|
|
|
$form->handleRequest($request); |
83
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
84
|
|
|
$data = $form->getData(); |
85
|
|
|
$isVideoProofOnly = $data['isVideoProofOnly']; |
86
|
|
|
foreach ($game->getGroups() as $group) { |
87
|
|
|
foreach ($group->getCharts() as $chart) { |
88
|
|
|
$chart->setIsProofVideoOnly($isVideoProofOnly); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
$em->flush(); |
92
|
|
|
|
93
|
|
|
$this->addFlash('sonata_flash_success', 'All charts are updated successfully'); |
94
|
|
|
return new RedirectResponse($this->admin->generateUrl('show', ['id' => $game->getId()])); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->render( |
98
|
|
|
'@VideoGamesRecordsCore/Admin/Form/form.set_video_proof_only.html.twig', |
99
|
|
|
[ |
100
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
101
|
|
|
'admin' => $this->admin, |
102
|
|
|
'object' => $game, |
103
|
|
|
'form' => $form, |
104
|
|
|
'title' => $game->getName(), |
105
|
|
|
'action' => 'edit' |
106
|
|
|
] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.