|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Controller\Admin; |
|
6
|
|
|
|
|
7
|
|
|
use App\Controller\BaseController; |
|
8
|
|
|
use App\Entity\Currency; |
|
9
|
|
|
use App\Form\Type\CurrencyType; |
|
10
|
|
|
use App\Repository\CurrencyRepository; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
|
12
|
|
|
use Symfony\Component\Form\ClickableInterface; |
|
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
16
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
17
|
|
|
|
|
18
|
|
|
final class CurrencyController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @Route("/admin/currency", name="admin_currency") |
|
22
|
|
|
*/ |
|
23
|
|
|
public function index(Request $request, CurrencyRepository $repository): Response |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->render('admin/currency/index.html.twig', [ |
|
26
|
|
|
'site' => $this->site($request), |
|
27
|
|
|
'currencies' => $repository->findAll(), |
|
28
|
|
|
]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @Route("/admin/currency/new", name="admin_currency_new") |
|
33
|
|
|
*/ |
|
34
|
|
|
public function new(Request $request): Response |
|
35
|
|
|
{ |
|
36
|
|
|
$currency = new Currency(); |
|
37
|
|
|
|
|
38
|
|
|
$form = $this->createForm(CurrencyType::class, $currency) |
|
39
|
|
|
->add('saveAndCreateNew', SubmitType::class); |
|
40
|
|
|
$form->handleRequest($request); |
|
41
|
|
|
|
|
42
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
43
|
|
|
$em = $this->doctrine->getManager(); |
|
44
|
|
|
$em->persist($currency); |
|
45
|
|
|
$em->flush(); |
|
46
|
|
|
|
|
47
|
|
|
$this->addFlash('success', 'message.created'); |
|
48
|
|
|
|
|
49
|
|
|
/** @var ClickableInterface $button */ |
|
50
|
|
|
$button = $form->get('saveAndCreateNew'); |
|
51
|
|
|
if ($button->isClicked()) { |
|
52
|
|
|
return $this->redirectToRoute('admin_currency_new'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->redirectToRoute('admin_currency'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->render('admin/currency/new.html.twig', [ |
|
59
|
|
|
'site' => $this->site($request), |
|
60
|
|
|
'currency' => $currency, |
|
61
|
|
|
'form' => $form->createView(), |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Displays a form to edit an existing Currency entity. |
|
67
|
|
|
* |
|
68
|
|
|
* @Route("/admin/currency/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_currency_edit") |
|
69
|
|
|
*/ |
|
70
|
|
|
public function edit(Request $request, Currency $currency): Response |
|
71
|
|
|
{ |
|
72
|
|
|
$form = $this->createForm(CurrencyType::class, $currency); |
|
73
|
|
|
$form->handleRequest($request); |
|
74
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
75
|
|
|
$this->doctrine->getManager()->flush(); |
|
76
|
|
|
$this->addFlash('success', 'message.updated'); |
|
77
|
|
|
|
|
78
|
|
|
return $this->redirectToRoute('admin_currency'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->render('admin/currency/edit.html.twig', [ |
|
82
|
|
|
'site' => $this->site($request), |
|
83
|
|
|
'form' => $form->createView(), |
|
84
|
|
|
]); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Deletes a Currency entity. |
|
89
|
|
|
* |
|
90
|
|
|
* @Route("/currency/{id<\d+>}/delete", methods={"POST"}, name="admin_currency_delete") |
|
91
|
|
|
* @IsGranted("ROLE_ADMIN") |
|
92
|
|
|
*/ |
|
93
|
|
|
public function delete(Request $request, Currency $currency): Response |
|
94
|
|
|
{ |
|
95
|
|
|
if (!$this->isCsrfTokenValid('delete', $request->request->get('token'))) { |
|
96
|
|
|
return $this->redirectToRoute('admin_currency'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$em = $this->doctrine->getManager(); |
|
100
|
|
|
$em->remove($currency); |
|
101
|
|
|
$em->flush(); |
|
102
|
|
|
$this->addFlash('success', 'message.deleted'); |
|
103
|
|
|
|
|
104
|
|
|
return $this->redirectToRoute('admin_currency'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|