1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the vseth-semesterly-reports 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\Organisation; |
13
|
|
|
|
14
|
|
|
use App\Controller\Administration\Base\BaseController; |
15
|
|
|
use App\Entity\Event; |
16
|
|
|
use App\Entity\Organisation; |
17
|
|
|
use App\Form\Type\SemesterType; |
18
|
|
|
use App\Model\Breadcrumb; |
19
|
|
|
use App\Security\Voter\Base\BaseVoter; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
23
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @Route("/event") |
27
|
|
|
*/ |
28
|
|
|
class EventController extends BaseController |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var Organisation |
32
|
|
|
*/ |
33
|
|
|
private $organisation; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @Route("/new", name="organisation_event_new") |
37
|
|
|
* |
38
|
|
|
* @return Response |
39
|
|
|
*/ |
40
|
|
|
public function newAction(Organisation $organisation, Request $request, TranslatorInterface $translator) |
41
|
|
|
{ |
42
|
|
|
//create the event |
43
|
|
|
$event = new Event(); |
44
|
|
|
$event->setSemester(SemesterType::getCurrentSemester()); |
45
|
|
|
$event->setOrganisation($organisation); |
46
|
|
|
$event->setLocation(''); |
47
|
|
|
$event->setRevenue(0); |
48
|
|
|
$event->setNeedFinancialSupport(false); |
49
|
|
|
$event->setStartDate(new \DateTime('today 18:00 + 2 weeks')); |
50
|
|
|
|
51
|
|
|
return $this->displayNewForm($request, $translator, $organisation, $event); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return \Symfony\Component\Form\FormInterface|Response |
56
|
|
|
*/ |
57
|
|
|
private function displayNewForm(Request $request, TranslatorInterface $translator, Organisation $organisation, Event $event) |
58
|
|
|
{ |
59
|
|
|
//process form |
60
|
|
|
$myForm = $this->handleCreateForm( |
61
|
|
|
$request, |
62
|
|
|
$event, |
63
|
|
|
function () use ($event, $translator) { |
64
|
|
|
return $this->validateEvent($event, $translator); |
65
|
|
|
} |
66
|
|
|
); |
67
|
|
|
if ($myForm instanceof Response) { |
68
|
|
|
return $myForm; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->organisation = $organisation; |
72
|
|
|
|
73
|
|
|
return $this->render('organisation/event/new.html.twig', ['form' => $myForm->createView()]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @Route("/{event}/clone", name="organisation_event_copy") |
78
|
|
|
* |
79
|
|
|
* @return Response |
80
|
|
|
*/ |
81
|
|
|
public function copyAction(Request $request, Organisation $organisation, Event $event, TranslatorInterface $translator) |
82
|
|
|
{ |
83
|
|
|
$this->ensureAccessGranted($event); |
84
|
|
|
$clonedEvent = clone $event; |
85
|
|
|
|
86
|
|
|
return $this->displayNewForm($request, $translator, $organisation, $clonedEvent); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @Route("/{event}/edit", name="organisation_event_edit") |
91
|
|
|
* |
92
|
|
|
* @return Response |
93
|
|
|
*/ |
94
|
|
|
public function editAction(Organisation $organisation, Request $request, Event $event, TranslatorInterface $translator) |
95
|
|
|
{ |
96
|
|
|
$this->ensureAccessGranted($event); |
97
|
|
|
|
98
|
|
|
//process form |
99
|
|
|
$myForm = $this->handleUpdateForm( |
100
|
|
|
$request, |
101
|
|
|
$event, |
102
|
|
|
function () use ($event, $translator) { |
103
|
|
|
return $this->validateEvent($event, $translator); |
104
|
|
|
} |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
if ($myForm instanceof Response) { |
108
|
|
|
return $myForm; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$this->organisation = $organisation; |
112
|
|
|
|
113
|
|
|
return $this->render('organisation/event/edit.html.twig', ['form' => $myForm->createView(), 'event' => $event]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** * |
117
|
|
|
* @Route("/{event}/remove", name="organisation_event_remove") |
118
|
|
|
* |
119
|
|
|
* @return Response |
120
|
|
|
*/ |
121
|
|
|
public function removeAction(Organisation $organisation, Request $request, Event $event) |
122
|
|
|
{ |
123
|
|
|
$this->ensureAccessGranted($event); |
124
|
|
|
|
125
|
|
|
//process form |
126
|
|
|
$form = $this->handleDeleteForm($request, $event); |
127
|
|
|
if ($form === null) { |
128
|
|
|
return $this->redirectToRoute('organisation_view', ['organisation' => $organisation->getId()]); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$this->organisation = $organisation; |
132
|
|
|
|
133
|
|
|
return $this->render('organisation/event/remove.html.twig', ['form' => $form->createView(), 'event' => $event]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
private function validateEvent(Event $event, TranslatorInterface $translator): bool |
137
|
|
|
{ |
138
|
|
|
if (mb_strlen($event->getNameDe()) === 0 && mb_strlen($event->getNameEn()) === 0) { |
139
|
|
|
$this->displayError($translator->trans('new.error.no_name', [], 'organisation_event')); |
140
|
|
|
|
141
|
|
|
return false; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if ($event->getStartDate() !== null) { |
145
|
|
|
$semester = SemesterType::getSemesterFor($event->getStartDate()); |
146
|
|
|
$event->setSemester($semester); |
147
|
|
|
} elseif ($event->getEndDate() !== null) { |
148
|
|
|
$semester = SemesterType::getSemesterFor($event->getEndDate()); |
149
|
|
|
$event->setSemester($semester); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return true; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
private function ensureAccessGranted(Event $event) |
156
|
|
|
{ |
157
|
|
|
$this->denyAccessUnlessGranted(BaseVoter::VIEW, $event); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* get the breadcrumbs leading to this controller. |
162
|
|
|
* |
163
|
|
|
* @return Breadcrumb[] |
164
|
|
|
*/ |
165
|
|
|
protected function getIndexBreadcrumbs() |
166
|
|
|
{ |
167
|
|
|
// test in frontend |
168
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
169
|
|
|
new Breadcrumb( |
170
|
|
|
$this->generateUrl('organisation_view', ['organisation' => $this->organisation->getId()]), |
171
|
|
|
$this->getTranslator()->trans('view.title', [], 'organisation') |
172
|
|
|
), |
173
|
|
|
]); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|