|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the feedback project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Florian Moser <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace App\Controller\Administration\Semester; |
|
13
|
|
|
|
|
14
|
|
|
use App\Controller\Administration\Base\BaseController; |
|
15
|
|
|
use App\Entity\Event; |
|
16
|
|
|
use App\Entity\Semester; |
|
17
|
|
|
use App\Model\Breadcrumb; |
|
18
|
|
|
use App\Security\Voter\Base\BaseVoter; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
21
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @Route("/event") |
|
25
|
|
|
*/ |
|
26
|
|
|
class EventController extends BaseController |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @Route("/new", name="administration_semester_event_new") |
|
30
|
|
|
* |
|
31
|
|
|
* @param Request $request |
|
32
|
|
|
* @param Semester $semester |
|
33
|
|
|
* |
|
34
|
|
|
* @return Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function newAction(Request $request, Semester $semester) |
|
37
|
|
|
{ |
|
38
|
|
|
//create the event |
|
39
|
|
|
$event = new Event(); |
|
40
|
|
|
$event->setSemester($semester); |
|
41
|
|
|
$event->setName(''); |
|
42
|
|
|
|
|
43
|
|
|
//fill out default values as smart as possible |
|
44
|
|
|
/** @var Event|null $lastEvent */ |
|
45
|
|
|
$lastEvent = $semester->getEvents()->first(); |
|
46
|
|
|
if ($lastEvent) { |
|
47
|
|
|
$event->setFeedbackStartTime($lastEvent->getFeedbackStartTime()); |
|
48
|
|
|
$event->setFeedbackEndTime($lastEvent->getFeedbackEndTime()); |
|
49
|
|
|
$event->setTemplateName($lastEvent->getTemplateName()); |
|
50
|
|
|
} else { |
|
51
|
|
|
$event->setFeedbackStartTime('19:00:00'); |
|
52
|
|
|
$event->setFeedbackEndTime('21:00:00'); |
|
53
|
|
|
$event->setTemplateName('default.json'); |
|
54
|
|
|
} |
|
55
|
|
|
$event->setDate((new \DateTime())->modify('+20 day')->format('Y-m-d')); |
|
56
|
|
|
|
|
57
|
|
|
//check if can indeed create the event |
|
58
|
|
|
$this->ensureAccessGranted($event); |
|
59
|
|
|
|
|
60
|
|
|
//process form |
|
61
|
|
|
$myForm = $this->handleCreateForm( |
|
62
|
|
|
$request, |
|
63
|
|
|
$event, |
|
64
|
|
|
function () use ($event) { |
|
65
|
|
|
return $this->prePersistActions($event); |
|
66
|
|
|
} |
|
67
|
|
|
); |
|
68
|
|
|
if ($myForm instanceof Response) { |
|
69
|
|
|
return $myForm; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this->renderWithSemester('administration/semester/event/new.html.twig', $semester, ['form' => $myForm->createView()]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @Route("/{event}/edit", name="administration_semester_event_edit") |
|
77
|
|
|
* |
|
78
|
|
|
* @param Request $request |
|
79
|
|
|
* @param Semester $semester |
|
80
|
|
|
* @param Event $event |
|
81
|
|
|
* |
|
82
|
|
|
* @return Response |
|
83
|
|
|
*/ |
|
84
|
|
|
public function editAction(Request $request, Semester $semester, Event $event) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->ensureAccessGranted($event); |
|
87
|
|
|
|
|
88
|
|
|
//process form |
|
89
|
|
|
$myForm = $this->handleUpdateForm( |
|
90
|
|
|
$request, |
|
91
|
|
|
$event, |
|
92
|
|
|
function () use ($event) { |
|
93
|
|
|
return $this->prePersistActions($event); |
|
94
|
|
|
} |
|
95
|
|
|
); |
|
96
|
|
|
if ($myForm instanceof Response) { |
|
97
|
|
|
return $myForm; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $this->renderWithSemester('administration/semester/event/edit.html.twig', $semester, ['form' => $myForm->createView(), 'event' => $event]); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @Route("/{event}/view", name="administration_semester_event_view") |
|
105
|
|
|
* |
|
106
|
|
|
* @param Semester $semester |
|
107
|
|
|
* @param Event $event |
|
108
|
|
|
* |
|
109
|
|
|
* @return Response |
|
110
|
|
|
*/ |
|
111
|
|
|
public function viewAction(Semester $semester, Event $event) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->renderWithSemester('administration/semester/event/view.html.twig', $semester, ['event' => $event]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** * |
|
117
|
|
|
* @Route("/{event}/remove", name="administration_semester_event_remove") |
|
118
|
|
|
* |
|
119
|
|
|
* @param Request $request |
|
120
|
|
|
* @param Semester $semester |
|
121
|
|
|
* @param Event $event |
|
122
|
|
|
* |
|
123
|
|
|
* @return Response |
|
124
|
|
|
*/ |
|
125
|
|
|
public function removeAction(Request $request, Semester $semester, Event $event) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->ensureAccessGranted($event); |
|
128
|
|
|
|
|
129
|
|
|
//process form |
|
130
|
|
|
$form = $this->handleDeleteForm($request, $event); |
|
131
|
|
|
if ($form === null) { |
|
132
|
|
|
return $this->redirectToRoute('administration_semesters'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $this->renderWithSemester('administration/semester/event/remove.html.twig', $semester, ['event' => $event, 'form' => $form->createView()]); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* get the breadcrumbs leading to this controller. |
|
140
|
|
|
* |
|
141
|
|
|
* @return Breadcrumb[] |
|
142
|
|
|
*/ |
|
143
|
|
|
protected function getIndexBreadcrumbs() |
|
144
|
|
|
{ |
|
145
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
|
146
|
|
|
new Breadcrumb( |
|
147
|
|
|
$this->generateUrl('administration_semesters'), |
|
148
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration_semester') |
|
149
|
|
|
), |
|
150
|
|
|
]); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param Event $event |
|
155
|
|
|
*/ |
|
156
|
|
|
private function ensureAccessGranted(Event $event) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->denyAccessUnlessGranted(BaseVoter::VIEW, $event); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @param Event $event |
|
163
|
|
|
* |
|
164
|
|
|
* @return bool |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function prePersistActions(Event $event) |
|
167
|
|
|
{ |
|
168
|
|
|
$event->loadTemplateIfSafe($this->getParameter('PUBLIC_DIR')); |
|
169
|
|
|
|
|
170
|
|
|
return true; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* renders the view & prepares views which need the active election. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $view |
|
177
|
|
|
* @param Semester $semester |
|
178
|
|
|
* @param array $parameters |
|
179
|
|
|
* |
|
180
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
181
|
|
|
*/ |
|
182
|
|
|
protected function renderWithSemester(string $view, Semester $semester, array $parameters = []) |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->render($view, $parameters + ['semester' => $semester]); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|