|
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\Base\BaseFormController; |
|
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
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @Route("/event") |
|
26
|
|
|
*/ |
|
27
|
|
|
class EventController extends BaseFormController |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @Route("/new", name="administration_semester_event_new") |
|
31
|
|
|
* |
|
32
|
|
|
* @param Request $request |
|
33
|
|
|
* @param Semester $semester |
|
34
|
|
|
* @param TranslatorInterface $translator |
|
35
|
|
|
* |
|
36
|
|
|
* @return Response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function newAction(Request $request, Semester $semester, TranslatorInterface $translator) |
|
39
|
|
|
{ |
|
40
|
|
|
//create the event |
|
41
|
|
|
$event = new Event(); |
|
42
|
|
|
$event->setSemester($semester); |
|
43
|
|
|
|
|
44
|
|
|
//fill out default values as smart as possible |
|
45
|
|
|
$lastEvent = $this->getDoctrine()->getRepository(Event::class)->findBy([], ['createdAt' => 'DESC'], 1); |
|
46
|
|
|
if (\count($lastEvent) > 0) { |
|
47
|
|
|
$event->setFeedbackStartTime($lastEvent[0]->getFeedbackStartTime()); |
|
48
|
|
|
$event->setFeedbackEndTime($$lastEvent[0]->getFeedbackEndTime()); |
|
49
|
|
|
} else { |
|
50
|
|
|
$event->setFeedbackStartTime('19:00'); |
|
51
|
|
|
$event->setFeedbackEndTime('21:00'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
//check if can indeed create the event |
|
55
|
|
|
$this->ensureAccessGranted($event); |
|
56
|
|
|
|
|
57
|
|
|
//process form |
|
58
|
|
|
$myForm = $this->handleCreateForm( |
|
59
|
|
|
$request, |
|
60
|
|
|
$event, |
|
61
|
|
|
function () use ($event) { |
|
62
|
|
|
return $this->prePersistActions($event); |
|
63
|
|
|
} |
|
64
|
|
|
); |
|
65
|
|
|
if ($myForm instanceof Response) { |
|
66
|
|
|
return $myForm; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->renderWithSemester('administration/semester/event/new.html.twig', $semester, ['form' => $myForm->createView()]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @Route("/{event}/edit", name="administration_semester_event_edit") |
|
74
|
|
|
* |
|
75
|
|
|
* @param Request $request |
|
76
|
|
|
* @param Semester $semester |
|
77
|
|
|
* @param Event $event |
|
78
|
|
|
* @param TranslatorInterface $translator |
|
79
|
|
|
* |
|
80
|
|
|
* @return Response |
|
81
|
|
|
*/ |
|
82
|
|
|
public function editAction(Request $request, Semester $semester, Event $event, TranslatorInterface $translator) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
$this->ensureAccessGranted($event); |
|
85
|
|
|
|
|
86
|
|
|
//process form |
|
87
|
|
|
$myForm = $this->handleUpdateForm( |
|
88
|
|
|
$request, |
|
89
|
|
|
$event, |
|
90
|
|
|
function () use ($event) { |
|
91
|
|
|
return $this->prePersistActions($event); |
|
92
|
|
|
} |
|
93
|
|
|
); |
|
94
|
|
|
if ($myForm instanceof Response) { |
|
95
|
|
|
return $myForm; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->renderWithSemester('administration/semester/event/edit.html.twig', $semester, ['form' => $myForm->createView(), 'event' => $event]); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** * |
|
102
|
|
|
* @Route("/{event}/remove", name="administration_semester_event_remove") |
|
103
|
|
|
* |
|
104
|
|
|
* @param Request $request |
|
105
|
|
|
* @param Semester $semester |
|
106
|
|
|
* @param Event $event |
|
107
|
|
|
* |
|
108
|
|
|
* @return Response |
|
109
|
|
|
*/ |
|
110
|
|
|
public function removeAction(Request $request, Semester $semester, Event $event) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->ensureAccessGranted($event); |
|
113
|
|
|
|
|
114
|
|
|
//process form |
|
115
|
|
|
$form = $this->handleDeleteForm($request, $event); |
|
116
|
|
|
if ($form === null) { |
|
117
|
|
|
return $this->redirectToRoute('administration_semesters'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->renderWithSemester('administration/semester/event/remove.html.twig', $semester, ['event' => $event, 'form' => $form->createView()]); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* get the breadcrumbs leading to this controller. |
|
125
|
|
|
* |
|
126
|
|
|
* @return Breadcrumb[] |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function getIndexBreadcrumbs() |
|
129
|
|
|
{ |
|
130
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
|
131
|
|
|
new Breadcrumb( |
|
132
|
|
|
$this->generateUrl('administration_semesters'), |
|
133
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration_semester') |
|
134
|
|
|
), |
|
135
|
|
|
]); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param Event $event |
|
140
|
|
|
*/ |
|
141
|
|
|
private function ensureAccessGranted(Event $event) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->denyAccessUnlessGranted(BaseVoter::VIEW, $event); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param Event $event |
|
148
|
|
|
* |
|
149
|
|
|
* @return bool |
|
150
|
|
|
*/ |
|
151
|
|
|
protected function prePersistActions(Event $event) |
|
152
|
|
|
{ |
|
153
|
|
|
$event->loadTemplateIfSafe($this->getParameter('PUBLIC_DIR')); |
|
154
|
|
|
|
|
155
|
|
|
return true; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* renders the view & prepares views which need the active election. |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $view |
|
162
|
|
|
* @param Semester $semester |
|
163
|
|
|
* @param array $parameters |
|
164
|
|
|
* |
|
165
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function renderWithSemester(string $view, Semester $semester, array $parameters = []) |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->render($view, $parameters + ['semester' => $semester]); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.