1
|
|
|
<?php |
2
|
|
|
namespace VideoGamesRecords\CoreBundle\Controller\Admin; |
3
|
|
|
|
4
|
|
|
use Sonata\AdminBundle\Controller\CRUDController; |
5
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
9
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Group; |
10
|
|
|
use VideoGamesRecords\CoreBundle\Form\Type\ChartTypeType; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class GroupAdminController |
14
|
|
|
*/ |
15
|
|
|
class GroupAdminController extends CRUDController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param $id |
19
|
|
|
* @return RedirectResponse |
20
|
|
|
*/ |
21
|
|
|
public function copyAction($id) |
22
|
|
|
{ |
23
|
|
|
$object = $this->admin->getSubject(); |
24
|
|
|
|
25
|
|
|
if (!$object) { |
|
|
|
|
26
|
|
|
throw new NotFoundHttpException(sprintf('unable to find the object with id: %s', $id)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
|
|
|
|
30
|
|
|
$em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->copy($id, false); |
31
|
|
|
|
32
|
|
|
$this->addFlash('sonata_flash_success', 'Copied successfully'); |
33
|
|
|
|
34
|
|
|
return new RedirectResponse($this->admin->generateUrl('list')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param $id |
39
|
|
|
* @return RedirectResponse |
40
|
|
|
*/ |
41
|
|
|
public function copyWithLibChartAction($id) |
42
|
|
|
{ |
43
|
|
|
$object = $this->admin->getSubject(); |
44
|
|
|
|
45
|
|
|
if (!$object) { |
|
|
|
|
46
|
|
|
throw new NotFoundHttpException(sprintf('unable to find the object with id: %s', $id)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
50
|
|
|
$em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->copy($id, true); |
51
|
|
|
|
52
|
|
|
$this->addFlash('sonata_flash_success', 'Copied with libchart successfully'); |
53
|
|
|
|
54
|
|
|
return new RedirectResponse($this->admin->generateUrl('list')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $id |
59
|
|
|
* @param Request $request |
60
|
|
|
* @return Response |
61
|
|
|
*/ |
62
|
|
|
public function addLibChartAction($id, Request $request) |
63
|
|
|
{ |
64
|
|
|
/** @var Group $object */ |
65
|
|
|
$object = $this->admin->getSubject(); |
66
|
|
|
|
67
|
|
|
if ($object->getGame()->getStatus()->isActive()) { |
68
|
|
|
$this->addFlash('sonata_flash_error', 'Game is already activated'); |
69
|
|
|
return new RedirectResponse($this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass()); |
73
|
|
|
$form = $this->createForm(ChartTypeType::class); |
74
|
|
|
$form->handleRequest($request); |
75
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
76
|
|
|
$data = $form->getData(); |
77
|
|
|
$type = $data['type']; |
78
|
|
|
$result = $em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->insertLibChart($id, $type->getIdType()); |
79
|
|
|
if ($result) { |
80
|
|
|
$this->addFlash('sonata_flash_success', 'Add all libchart on group successfully'); |
81
|
|
|
return new RedirectResponse($this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])); |
82
|
|
|
} else { |
83
|
|
|
$this->addFlash('sonata_flash_error', 'Add all libchart on group successfully'); |
84
|
|
|
return new RedirectResponse($this->admin->generateUrl('add-lib-chart')); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->renderForm('@VideoGamesRecordsCore/Admin/group_add_chart_form.html.twig', |
89
|
|
|
[ |
90
|
|
|
'base_template' => '@SonataAdmin/standard_layout.html.twig', |
91
|
|
|
'admin' => $this->admin, |
92
|
|
|
'object' => $object, |
93
|
|
|
'form' => $form, |
94
|
|
|
'group' => $object, |
95
|
|
|
'action' => 'edit' |
96
|
|
|
] |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|