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