|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Controller\Admin; |
|
6
|
|
|
|
|
7
|
|
|
use App\Controller\BaseController; |
|
8
|
|
|
use App\Entity\DealType; |
|
9
|
|
|
use App\Form\Type\DealTypeType; |
|
10
|
|
|
use App\Service\Admin\DealTypeService; |
|
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 DealTypeController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @Route("/admin/deal_type", name="admin_deal_type") |
|
22
|
|
|
*/ |
|
23
|
|
|
public function index(Request $request): Response |
|
24
|
|
|
{ |
|
25
|
|
|
$repository = $this->doctrine->getRepository(DealType::class); |
|
26
|
|
|
|
|
27
|
|
|
$dealTypes = $repository->findAll(); |
|
28
|
|
|
|
|
29
|
|
|
return $this->render('admin/deal_type/index.html.twig', [ |
|
30
|
|
|
'site' => $this->site($request), |
|
31
|
|
|
'dealTypes' => $dealTypes, |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @Route("/admin/deal_type/new", name="admin_deal_type_new") |
|
37
|
|
|
*/ |
|
38
|
|
|
public function new(Request $request, DealTypeService $service): Response |
|
39
|
|
|
{ |
|
40
|
|
|
$dealType = new DealType(); |
|
41
|
|
|
|
|
42
|
|
|
$form = $this->createForm(DealTypeType::class, $dealType) |
|
43
|
|
|
->add('saveAndCreateNew', SubmitType::class); |
|
44
|
|
|
$form->handleRequest($request); |
|
45
|
|
|
|
|
46
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
47
|
|
|
$service->create($dealType); |
|
48
|
|
|
|
|
49
|
|
|
/** @var ClickableInterface $button */ |
|
50
|
|
|
$button = $form->get('saveAndCreateNew'); |
|
51
|
|
|
if ($button->isClicked()) { |
|
52
|
|
|
return $this->redirectToRoute('admin_deal_type_new'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->redirectToRoute('admin_deal_type'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->render('admin/deal_type/new.html.twig', [ |
|
59
|
|
|
'site' => $this->site($request), |
|
60
|
|
|
'deal_type' => $dealType, |
|
61
|
|
|
'form' => $form->createView(), |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Displays a form to edit an existing DealType entity. |
|
67
|
|
|
* |
|
68
|
|
|
* @Route("/admin/deal_type/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_deal_type_edit") |
|
69
|
|
|
*/ |
|
70
|
|
|
public function edit(Request $request, DealType $dealType, DealTypeService $service): Response |
|
71
|
|
|
{ |
|
72
|
|
|
$form = $this->createForm(DealTypeType::class, $dealType); |
|
73
|
|
|
$form->handleRequest($request); |
|
74
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
75
|
|
|
$service->update($dealType); |
|
76
|
|
|
|
|
77
|
|
|
return $this->redirectToRoute('admin_deal_type'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $this->render('admin/deal_type/edit.html.twig', [ |
|
81
|
|
|
'site' => $this->site($request), |
|
82
|
|
|
'form' => $form->createView(), |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Deletes a DealType entity. |
|
88
|
|
|
* |
|
89
|
|
|
* @Route("/deal_type/{id<\d+>}/delete", methods={"POST"}, name="admin_deal_type_delete") |
|
90
|
|
|
* @IsGranted("ROLE_ADMIN") |
|
91
|
|
|
*/ |
|
92
|
|
|
public function delete(Request $request, DealType $dealType, DealTypeService $service): Response |
|
93
|
|
|
{ |
|
94
|
|
|
if (!$this->isCsrfTokenValid('delete', $request->request->get('token'))) { |
|
95
|
|
|
return $this->redirectToRoute('admin_deal_type'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$service->remove($dealType); |
|
99
|
|
|
|
|
100
|
|
|
return $this->redirectToRoute('admin_deal_type'); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|