|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Application; |
|
6
|
|
|
use App\Form\ApplicationType; |
|
7
|
|
|
use App\Repository\ApplicationRepositoryInterface; |
|
8
|
|
|
use App\Service\ApplicationKeyGenerator; |
|
9
|
|
|
use SchulIT\CommonBundle\Form\ConfirmType; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @Route("/admin/applications") |
|
16
|
|
|
*/ |
|
17
|
|
|
class ApplicationController extends AbstractController { |
|
18
|
|
|
|
|
19
|
|
|
private $repository; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct(ApplicationRepositoryInterface $repository) { |
|
22
|
|
|
$this->repository = $repository; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @Route("", name="applications") |
|
27
|
|
|
*/ |
|
28
|
|
|
public function index() { |
|
29
|
|
|
$applications = $this->repository->findAll(); |
|
30
|
|
|
|
|
31
|
|
|
return $this->render('applications/index.html.twig', [ |
|
32
|
|
|
'applications' => $applications |
|
33
|
|
|
]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @Route("/add", name="add_application") |
|
38
|
|
|
*/ |
|
39
|
|
|
public function add(Request $request, ApplicationKeyGenerator $keyGenerator) { |
|
40
|
|
|
$application = (new Application()); |
|
41
|
|
|
|
|
42
|
|
|
$form = $this->createForm(ApplicationType::class, $application); |
|
43
|
|
|
$form->handleRequest($request); |
|
44
|
|
|
|
|
45
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
46
|
|
|
$application->setApiKey($keyGenerator->generateApiKey()); |
|
47
|
|
|
$this->repository->persist($application); |
|
48
|
|
|
$this->addFlash('success', 'applications.add.success'); |
|
49
|
|
|
|
|
50
|
|
|
return $this->redirectToRoute('applications'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this->render('applications/add.html.twig', [ |
|
54
|
|
|
'form' => $form->createView() |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @Route("/{uuid}/edit", name="edit_application") |
|
60
|
|
|
*/ |
|
61
|
|
|
public function edit(Application $application, Request $request) { |
|
62
|
|
|
$form = $this->createForm(ApplicationType::class, $application); |
|
63
|
|
|
$form->handleRequest($request); |
|
64
|
|
|
|
|
65
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
66
|
|
|
$this->repository->persist($application); |
|
67
|
|
|
$this->addFlash('success', 'applications.edit.success'); |
|
68
|
|
|
|
|
69
|
|
|
return $this->redirectToRoute('applications'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this->render('applications/edit.html.twig', [ |
|
73
|
|
|
'form' => $form->createView(), |
|
74
|
|
|
'application' => $application |
|
75
|
|
|
]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @Route("/{uuid}/remove", name="remove_application") |
|
80
|
|
|
*/ |
|
81
|
|
|
public function remove(Application $application, Request $request) { |
|
82
|
|
|
$form = $this->createForm(ConfirmType::class, null, [ |
|
83
|
|
|
'message' => 'applications.remove.confirm', |
|
84
|
|
|
'message_parameters' => [ |
|
85
|
|
|
'%name%' => $application->getName() |
|
86
|
|
|
] |
|
87
|
|
|
]); |
|
88
|
|
|
$form->handleRequest($request); |
|
89
|
|
|
|
|
90
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
91
|
|
|
$this->repository->remove($application); |
|
92
|
|
|
$this->addFlash('success', 'applications.remove.success'); |
|
93
|
|
|
|
|
94
|
|
|
return $this->redirectToRoute('applications'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $this->render('applications/remove.html.twig', [ |
|
98
|
|
|
'application' => $application, |
|
99
|
|
|
'form' => $form->createView() |
|
100
|
|
|
]); |
|
101
|
|
|
} |
|
102
|
|
|
} |