1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Helpers\Helper; |
6
|
|
|
use App\Http\Requests\EventSearchRequest; |
7
|
|
|
use App\Http\Requests\EventStoreRequest; |
8
|
|
|
use App\Models\Event; |
9
|
|
|
use App\Services\EventCategoryService; |
10
|
|
|
use App\Services\EventRepetitionService; |
11
|
|
|
use App\Services\EventService; |
12
|
|
|
use App\Services\OrganizerService; |
13
|
|
|
use App\Services\TeacherService; |
14
|
|
|
use App\Services\VenueService; |
15
|
|
|
use Carbon\Carbon; |
16
|
|
|
use Illuminate\Http\RedirectResponse; |
17
|
|
|
use Illuminate\Http\Request; |
18
|
|
|
use App\Traits\CheckPermission; |
19
|
|
|
use Illuminate\Support\Facades\Log; |
20
|
|
|
use Illuminate\View\View; |
21
|
|
|
|
22
|
|
|
class EventController extends Controller |
23
|
|
|
{ |
24
|
|
|
use CheckPermission; |
|
|
|
|
25
|
|
|
|
26
|
|
|
private EventService $eventService; |
27
|
|
|
private EventCategoryService $eventCategoryService; |
28
|
|
|
private VenueService $venueService; |
29
|
|
|
private TeacherService $teacherService; |
30
|
|
|
private OrganizerService $organizerService; |
31
|
|
|
private EventRepetitionService $eventRepetitionService; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
EventService $eventService, |
35
|
|
|
EventCategoryService $eventCategoryService, |
36
|
|
|
VenueService $venueService, |
37
|
|
|
TeacherService $teacherService, |
38
|
|
|
OrganizerService $organizerService, |
39
|
|
|
EventRepetitionService $eventRepetitionService |
40
|
|
|
) { |
41
|
|
|
$this->eventService = $eventService; |
42
|
|
|
$this->eventCategoryService = $eventCategoryService; |
43
|
|
|
$this->venueService = $venueService; |
44
|
|
|
$this->teacherService = $teacherService; |
45
|
|
|
$this->organizerService = $organizerService; |
46
|
|
|
$this->eventRepetitionService = $eventRepetitionService; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Display a listing of the resource. |
51
|
|
|
* |
52
|
|
|
* @param \App\Http\Requests\EventSearchRequest $request |
53
|
|
|
* |
54
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
55
|
|
|
*/ |
56
|
|
|
public function index(EventSearchRequest $request): View |
57
|
|
|
{ |
58
|
|
|
$this->checkPermission('events.view'); |
59
|
|
|
|
60
|
|
|
$searchParameters = Helper::getSearchParameters($request, Event::SEARCH_PARAMETERS); |
61
|
|
|
|
62
|
|
|
$events = $this->eventService->getEvents(20, $searchParameters); |
63
|
|
|
$eventsCategories = $this->eventCategoryService->getEventCategories(); |
64
|
|
|
$statuses = Event::PUBLISHING_STATUS; |
65
|
|
|
|
66
|
|
|
return view('events.index', [ |
67
|
|
|
'events' => $events, |
68
|
|
|
'eventsCategories' => $eventsCategories, |
69
|
|
|
'searchParameters' => $searchParameters, |
70
|
|
|
'statuses' => $statuses, |
71
|
|
|
'eventRepetitionService' => $this->eventRepetitionService, |
72
|
|
|
'eventService' => $this->eventService, |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Show the form for creating a new resource. |
78
|
|
|
* |
79
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
80
|
|
|
*/ |
81
|
|
|
public function create(): View |
82
|
|
|
{ |
83
|
|
|
$this->checkPermission('events.create'); |
84
|
|
|
|
85
|
|
|
$eventCategories = $this->eventCategoryService->getEventCategories(); |
86
|
|
|
$venues = $this->venueService->getVenues(); |
87
|
|
|
$teachers = $this->teacherService->getTeachers(); |
88
|
|
|
$organizers = $this->organizerService->getOrganizers(); |
89
|
|
|
|
90
|
|
|
$eventDateTimeParameters['multipleDates'] = null; |
|
|
|
|
91
|
|
|
$eventDateTimeParameters['repeatUntil'] = null; |
92
|
|
|
|
93
|
|
|
return view('events.create', [ |
94
|
|
|
'eventCategories' => $eventCategories, |
95
|
|
|
'venues' => $venues, |
96
|
|
|
'teachers' => $teachers, |
97
|
|
|
'organizers' => $organizers, |
98
|
|
|
'eventDateTimeParameters' => $eventDateTimeParameters, |
99
|
|
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Store a newly created resource in storage. |
104
|
|
|
* |
105
|
|
|
* @param \App\Http\Requests\EventStoreRequest $request |
106
|
|
|
* |
107
|
|
|
* @return \Illuminate\Http\RedirectResponse |
108
|
|
|
* @throws \Spatie\ModelStatus\Exceptions\InvalidStatus |
109
|
|
|
*/ |
110
|
|
|
public function store(EventStoreRequest $request): RedirectResponse |
111
|
|
|
{ |
112
|
|
|
$this->checkPermission('events.create'); |
113
|
|
|
|
114
|
|
|
$event = $this->eventService->createEvent($request); |
|
|
|
|
115
|
|
|
|
116
|
|
|
return redirect()->route('events.index') |
117
|
|
|
->with('success', 'Event updated successfully'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Display the specified resource. |
122
|
|
|
* |
123
|
|
|
* @param int $eventId |
124
|
|
|
* |
125
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
126
|
|
|
*/ |
127
|
|
|
public function show(string $eventSlug): View |
128
|
|
|
{ |
129
|
|
|
$event = $this->eventService->getBySlug($eventSlug); |
130
|
|
|
|
131
|
|
|
// todo - probably $eventFirstRepetition has to change since in the previous calendar was a show() parameter. |
132
|
|
|
$eventFirstRepetition = $this->eventRepetitionService->getFirstByEventId($event->id); |
133
|
|
|
$repetitionTextString = $this->eventService->getRepetitionTextString($event, $eventFirstRepetition); |
134
|
|
|
|
135
|
|
|
return view('events.show', [ |
136
|
|
|
'event' => $event, |
137
|
|
|
'repetitionTextString' => $repetitionTextString, |
138
|
|
|
]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Show the form for editing the specified resource. |
143
|
|
|
* |
144
|
|
|
* @param int $eventId |
145
|
|
|
* |
146
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
147
|
|
|
*/ |
148
|
|
|
public function edit(int $eventId): View |
149
|
|
|
{ |
150
|
|
|
$this->checkPermission('events.edit'); |
151
|
|
|
|
152
|
|
|
$event = $this->eventService->getById($eventId); |
153
|
|
|
|
154
|
|
|
$eventCategories = $this->eventCategoryService->getEventCategories(); |
155
|
|
|
$venues = $this->venueService->getVenues(); |
156
|
|
|
$teachers = $this->teacherService->getTeachers(); |
157
|
|
|
$organizers = $this->organizerService->getOrganizers(); |
158
|
|
|
|
159
|
|
|
$eventFirstRepetition = $this->eventRepetitionService->getFirstByEventId($event->id); |
160
|
|
|
$eventDateTimeParameters = $this->eventService->getEventDateTimeParameters($event, $eventFirstRepetition); |
161
|
|
|
|
162
|
|
|
return view('events.edit', [ |
163
|
|
|
'event' => $event, |
164
|
|
|
'eventCategories' => $eventCategories, |
165
|
|
|
'venues' => $venues, |
166
|
|
|
'teachers' => $teachers, |
167
|
|
|
'organizers' => $organizers, |
168
|
|
|
'eventFirstRepetition' => $eventFirstRepetition, |
169
|
|
|
'eventDateTimeParameters' => $eventDateTimeParameters, |
170
|
|
|
]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Update the specified resource in storage. |
175
|
|
|
* |
176
|
|
|
* @param \App\Http\Requests\EventStoreRequest $request |
177
|
|
|
* @param int $eventId |
178
|
|
|
* |
179
|
|
|
* @return \Illuminate\Http\RedirectResponse |
180
|
|
|
*/ |
181
|
|
|
public function update(EventStoreRequest $request, int $eventId): RedirectResponse |
182
|
|
|
{ |
183
|
|
|
$this->checkPermission('events.edit'); |
184
|
|
|
|
185
|
|
|
$event = $this->eventService->updateEvent($request, $eventId); |
|
|
|
|
186
|
|
|
|
187
|
|
|
return redirect()->route('events.index') |
188
|
|
|
->with('success', 'Event updated successfully'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Remove the specified resource from storage. |
193
|
|
|
* |
194
|
|
|
* @param int $eventId |
195
|
|
|
* |
196
|
|
|
* @return \Illuminate\Http\RedirectResponse |
197
|
|
|
*/ |
198
|
|
|
public function destroy(int $eventId): RedirectResponse |
199
|
|
|
{ |
200
|
|
|
$this->checkPermission('events.delete'); |
201
|
|
|
|
202
|
|
|
$this->eventService->deleteEvent($eventId); |
203
|
|
|
|
204
|
|
|
return redirect()->route('events.index') |
205
|
|
|
->with('success', 'Event deleted successfully'); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Return the HTML of the monthly select dropdown - inspired by - https://www.theindychannel.com/calendar |
210
|
|
|
* - Used by the AJAX in the event repeat view - |
211
|
|
|
* - The HTML contain a <select></select> with four <options></options>. |
212
|
|
|
* |
213
|
|
|
* @param \Illuminate\Http\Request $request - Just the day |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function calculateMonthlySelectOptions(Request $request): string |
217
|
|
|
{ |
218
|
|
|
$date = $request['day']; |
219
|
|
|
|
220
|
|
|
return $this->eventService->getMonthlySelectOptions($date); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Display list of upcoming events in the frontend Events page. |
225
|
|
|
* |
226
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
227
|
|
|
*/ |
228
|
|
|
public function nextEvents(): View |
229
|
|
|
{ |
230
|
|
|
$searchParameters = []; |
231
|
|
|
$searchParameters['startDate'] = Carbon::today()->format('d/m/Y'); |
232
|
|
|
$searchParameters['is_published'] = true; |
233
|
|
|
|
234
|
|
|
$events = $this->eventService->getEvents(10, $searchParameters); |
235
|
|
|
|
236
|
|
|
return view('events.frontend', [ |
237
|
|
|
'events' => $events, |
238
|
|
|
'eventRepetitionService' => $this->eventRepetitionService, |
239
|
|
|
'eventService' => $this->eventService, |
240
|
|
|
]); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Display list of past events in the frontend Events page. |
245
|
|
|
* |
246
|
|
|
* @return View |
247
|
|
|
*/ |
248
|
|
|
public function pastEvents(): View |
249
|
|
|
{ |
250
|
|
|
$searchParameters = []; |
251
|
|
|
$searchParameters['endDate'] = Carbon::today()->format('d/m/Y'); |
252
|
|
|
$searchParameters['is_published'] = true; |
253
|
|
|
|
254
|
|
|
$events = $this->eventService->getEvents(10, $searchParameters); |
255
|
|
|
|
256
|
|
|
return view('events.past', [ |
257
|
|
|
'events' => $events, |
258
|
|
|
'eventRepetitionService' => $this->eventRepetitionService, |
259
|
|
|
'eventService' => $this->eventService, |
260
|
|
|
]); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Check if there are expiring repeat events and in case send emails to the organizers. |
265
|
|
|
* |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
|
|
/* public function sendEmailToExpiringEventsOrganizers(): string |
269
|
|
|
{ |
270
|
|
|
$expiringEvents = $this->eventService->getRepetitiveEventsExpiringInOneWeek(true); |
271
|
|
|
|
272
|
|
|
$this->eventService->sendEmailToExpiringEventsOrganizers($expiringEvents); |
273
|
|
|
|
274
|
|
|
$message = empty($expiringEventsList) ? |
275
|
|
|
'No events were expiring' |
276
|
|
|
: count($expiringEventsList) . ' events were expiring, mails sent to the organizers.'; |
277
|
|
|
|
278
|
|
|
Log::notice($message); |
279
|
|
|
return $message; |
280
|
|
|
}*/ |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
|
284
|
|
|
} |
285
|
|
|
|