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