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\ChartLib; |
12
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Group; |
13
|
|
|
use VideoGamesRecords\CoreBundle\Form\CopyGroupForm; |
14
|
|
|
use VideoGamesRecords\CoreBundle\Form\Type\ChartTypeType; |
15
|
|
|
use VideoGamesRecords\CoreBundle\Form\VideoProofOnly; |
16
|
|
|
|
17
|
|
|
class GroupAdminController extends CRUDController |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param $id |
21
|
|
|
* @param Request $request |
22
|
|
|
* @return Response |
23
|
|
|
*/ |
24
|
|
|
public function copyAction($id, Request $request): Response |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** @var Group $group */ |
27
|
|
|
$group = $this->admin->getSubject(); |
28
|
|
|
|
29
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
|
|
|
|
30
|
|
|
$form = $this->createForm(CopyGroupForm::class); |
31
|
|
|
$form->handleRequest($request); |
32
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
33
|
|
|
$data = $form->getData(); |
34
|
|
|
$em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->copy($group, $data['withLibs']); |
35
|
|
|
|
36
|
|
|
$this->addFlash('sonata_flash_success', 'Group was successfully copied.'); |
37
|
|
|
return new RedirectResponse($this->admin->generateUrl('show', ['id' => $group->getId()])); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->render( |
41
|
|
|
'@VideoGamesRecordsCore/Admin/Form/form.default.html.twig', |
42
|
|
|
[ |
43
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
44
|
|
|
'admin' => $this->admin, |
45
|
|
|
'object' => $group, |
46
|
|
|
'form' => $form, |
47
|
|
|
'title' => 'Copy => ' . $group->getGame()->getName() . ' / ' . $group->getName(), |
48
|
|
|
'action' => 'edit' |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $id |
55
|
|
|
* @param Request $request |
56
|
|
|
* @return RedirectResponse|Response |
57
|
|
|
*/ |
58
|
|
|
public function addLibChartAction($id, Request $request): RedirectResponse|Response |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
/** @var Group $group */ |
61
|
|
|
$group = $this->admin->getSubject(); |
62
|
|
|
|
63
|
|
|
if ($group->getGame()->getGameStatus()->isActive()) { |
64
|
|
|
$this->addFlash('sonata_flash_error', 'Game is already activated'); |
65
|
|
|
return new RedirectResponse( |
66
|
|
|
$this->admin->generateUrl( |
67
|
|
|
'list', |
68
|
|
|
['filter' => $this->admin->getFilterParameters()] |
69
|
|
|
) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
74
|
|
|
$form = $this->createForm(ChartTypeType::class); |
75
|
|
|
$form->handleRequest($request); |
76
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
77
|
|
|
$data = $form->getData(); |
78
|
|
|
$type = $data['type']; |
79
|
|
|
$chartType = $em->getRepository('VideoGamesRecords\CoreBundle\Entity\ChartType')->find($type); |
80
|
|
|
|
81
|
|
|
foreach ($group->getCharts() as $chart) { |
82
|
|
|
$libChart = new ChartLib(); |
83
|
|
|
$libChart->setType($chartType); |
84
|
|
|
$chart->addLib($libChart); |
85
|
|
|
$em->persist($libChart); |
86
|
|
|
} |
87
|
|
|
$em->flush(); |
88
|
|
|
|
89
|
|
|
$this->addFlash('sonata_flash_success', 'Add all libchart on group successfully'); |
90
|
|
|
return new RedirectResponse($this->admin->generateUrl('show', ['id' => $group->getId()])); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->render( |
94
|
|
|
'@VideoGamesRecordsCore/Admin/Object/Group/form.add_libchart.html.twig', |
95
|
|
|
[ |
96
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
97
|
|
|
'admin' => $this->admin, |
98
|
|
|
'object' => $group, |
99
|
|
|
'form' => $form, |
100
|
|
|
'group' => $group, |
101
|
|
|
'action' => 'edit' |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param $id |
108
|
|
|
* @param Request $request |
109
|
|
|
* @return RedirectResponse|Response |
110
|
|
|
*/ |
111
|
|
|
public function setVideoProofOnlyAction($id, Request $request): RedirectResponse|Response |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
/** @var Group $group */ |
114
|
|
|
$group = $this->admin->getSubject(); |
115
|
|
|
|
116
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
117
|
|
|
$form = $this->createForm(VideoProofOnly::class); |
118
|
|
|
$form->handleRequest($request); |
119
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
120
|
|
|
$data = $form->getData(); |
121
|
|
|
$isVideoProofOnly = $data['isVideoProofOnly']; |
122
|
|
|
foreach ($group->getCharts() as $chart) { |
123
|
|
|
$chart->setIsProofVideoOnly($isVideoProofOnly); |
124
|
|
|
} |
125
|
|
|
$em->flush(); |
126
|
|
|
|
127
|
|
|
$this->addFlash('sonata_flash_success', 'All charts are updated successfully'); |
128
|
|
|
return new RedirectResponse($this->admin->generateUrl('show', ['id' => $group->getId()])); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $this->render( |
132
|
|
|
'@VideoGamesRecordsCore/Admin/Form/form.set_video_proof_only.html.twig', |
133
|
|
|
[ |
134
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
135
|
|
|
'admin' => $this->admin, |
136
|
|
|
'object' => $group, |
137
|
|
|
'form' => $form, |
138
|
|
|
'title' => $group->getGame()->getName() . ' / ' . $group->getName(), |
139
|
|
|
'action' => 'edit' |
140
|
|
|
] |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.