|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\ServiceAttribute; |
|
6
|
|
|
use App\Form\ServiceAttributeType; |
|
7
|
|
|
use App\Repository\ServiceAttributeRepositoryInterface; |
|
8
|
|
|
use SchulIT\CommonBundle\Form\ConfirmType; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
14
|
|
|
|
|
15
|
|
|
class ServiceAttributeController extends AbstractController { |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(private ServiceAttributeRepositoryInterface $repository) |
|
18
|
|
|
{ |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
#[Route(path: '/admin/attributes', name: 'attributes')] |
|
22
|
|
|
public function index(): Response { |
|
23
|
|
|
$attributes = $this->repository |
|
24
|
|
|
->findAll(); |
|
25
|
|
|
|
|
26
|
|
|
return $this->render('service_attributes/index.html.twig', [ |
|
27
|
|
|
'attributes' => $attributes |
|
28
|
|
|
]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
#[Route(path: '/admin/attributes/add', name: 'add_attribute')] |
|
32
|
|
|
public function add(Request $request): Response { |
|
33
|
|
|
$attribute = new ServiceAttribute(); |
|
34
|
|
|
|
|
35
|
|
|
$form = $this->createForm(ServiceAttributeType::class, $attribute); |
|
36
|
|
|
$form->handleRequest($request); |
|
37
|
|
|
|
|
38
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
39
|
|
|
$this->repository->persist($attribute); |
|
40
|
|
|
|
|
41
|
|
|
$this->addFlash('success', 'service_attributes.add.success'); |
|
42
|
|
|
return $this->redirectToRoute('attributes'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->render('service_attributes/add.html.twig', [ |
|
46
|
|
|
'form' => $form->createView() |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
#[Route(path: '/admin/attributes/{uuid}/edit', name: 'edit_attribute')] |
|
51
|
|
|
public function edit(Request $request, ServiceAttribute $attribute): Response { |
|
52
|
|
|
$form = $this->createForm(ServiceAttributeType::class, $attribute); |
|
53
|
|
|
$form->handleRequest($request); |
|
54
|
|
|
|
|
55
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
56
|
|
|
$this->repository->persist($attribute); |
|
57
|
|
|
|
|
58
|
|
|
$this->addFlash('success', 'service_attributes.edit.success'); |
|
59
|
|
|
return $this->redirectToRoute('attributes'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->render('service_attributes/edit.html.twig', [ |
|
63
|
|
|
'form' => $form->createView(), |
|
64
|
|
|
'attribute' => $attribute |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
#[Route(path: '/admin/attributes/{uuid}/remove', name: 'remove_attribute')] |
|
69
|
|
|
public function remove(ServiceAttribute $attribute, Request $request, TranslatorInterface $translator): Response { |
|
70
|
|
|
$form = $this->createForm(ConfirmType::class, [], [ |
|
71
|
|
|
'message' => $translator->trans('service_attributes.remove.confirm', [ |
|
72
|
|
|
'%name%' => $attribute->getName() |
|
73
|
|
|
]), |
|
74
|
|
|
'label' => 'service_attributes.remove.label' |
|
75
|
|
|
]); |
|
76
|
|
|
$form->handleRequest($request); |
|
77
|
|
|
|
|
78
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
79
|
|
|
$this->repository->remove($attribute); |
|
80
|
|
|
|
|
81
|
|
|
$this->addFlash('success', 'service_attributes.remove.success'); |
|
82
|
|
|
return $this->redirectToRoute('attributes'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this->render('service_attributes/remove.html.twig', [ |
|
86
|
|
|
'form' => $form->createView(), |
|
87
|
|
|
'attribute' => $attribute |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
} |