1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelEventsCalendar\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use DateTime; |
7
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar; |
8
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Mail\ContactOrganizer; |
9
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Mail\ReportMisuse; |
10
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Continent; |
11
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Country; |
12
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Event; |
13
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\EventCategory; |
14
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\EventRepetition; |
15
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\EventVenue; |
16
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Organizer; |
17
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Region; |
18
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Teacher; |
19
|
|
|
use Illuminate\Foundation\Auth\User; |
20
|
|
|
use Illuminate\Http\Request; |
21
|
|
|
use Illuminate\Support\Facades\Auth; |
22
|
|
|
use Illuminate\Support\Facades\DB; |
23
|
|
|
use Illuminate\Support\Facades\Mail; |
24
|
|
|
use Illuminate\Support\Str; |
25
|
|
|
use Illuminate\Validation\Rule; |
26
|
|
|
use Validator; |
27
|
|
|
|
28
|
|
|
class EventController extends Controller |
29
|
|
|
{ |
30
|
|
|
/***************************************************************************/ |
31
|
|
|
/* Restrict the access to this resource just to logged in users except show view */ |
32
|
27 |
|
public function __construct() |
33
|
|
|
{ |
34
|
27 |
|
$this->middleware('auth', ['except' => ['show', 'reportMisuse', 'reportMisuseThankyou', 'mailToOrganizer', 'mailToOrganizerSent', 'eventBySlug', 'eventBySlugAndRepetition', 'EventsListByCountry', 'calculateMonthlySelectOptions']]); |
35
|
27 |
|
} |
36
|
|
|
|
37
|
|
|
/***************************************************************************/ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Display a listing of the resource. |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @return \Illuminate\Http\Response |
43
|
|
|
*/ |
44
|
1 |
|
public function index(Request $request) |
45
|
|
|
{ |
46
|
|
|
// To show just the events created by the the user - If admin or super admin is set to null show all the events |
47
|
1 |
|
$authorUserId = ($this->getLoggedAuthorId()) ? $this->getLoggedAuthorId() : null; // if is 0 (super admin or admin) it's setted to null to avoid include it in the query |
48
|
|
|
|
49
|
1 |
|
$eventCategories = EventCategory::listsTranslations('name')->orderBy('name')->pluck('name', 'id'); |
50
|
1 |
|
$countries = Country::orderBy('name')->pluck('name', 'id'); |
51
|
1 |
|
$venues = EventVenue::pluck('country_id', 'id'); |
52
|
|
|
|
53
|
1 |
|
$searchKeywords = $request->input('keywords'); |
54
|
1 |
|
$searchCategory = $request->input('category_id'); |
55
|
1 |
|
$searchCountry = $request->input('country_id'); |
56
|
|
|
|
57
|
1 |
|
if ($searchKeywords || $searchCategory || $searchCountry) { |
58
|
|
|
$events = Event:: |
59
|
|
|
// Show only the events owned by the user, if the user is an admin or super admin show all the events |
60
|
|
|
when(isset($authorUserId), function ($query, $authorUserId) { |
61
|
|
|
return $query->where('created_by', $authorUserId); |
62
|
|
|
}) |
63
|
|
|
->when($searchKeywords, function ($query, $searchKeywords) { |
64
|
|
|
return $query->where('title', $searchKeywords)->orWhere('title', 'like', '%'.$searchKeywords.'%'); |
65
|
|
|
}) |
66
|
|
|
->when($searchCategory, function ($query, $searchCategory) { |
67
|
|
|
return $query->where('category_id', '=', $searchCategory); |
68
|
|
|
}) |
69
|
|
|
->when($searchCountry, function ($query, $searchCountry) { |
70
|
|
|
return $query->join('event_venues', 'events.venue_id', '=', 'event_venues.id')->where('event_venues.country_id', '=', $searchCountry); |
71
|
|
|
}) |
72
|
|
|
->select('*', 'events.id as id', 'events.slug as slug', 'events.image as image') // To keep in the join the id of the Events table - https://stackoverflow.com/questions/28062308/laravel-eloquent-getting-id-field-of-joined-tables-in-eloquent |
73
|
|
|
->paginate(20); |
74
|
|
|
|
75
|
|
|
//dd($events); |
76
|
|
|
} else { |
77
|
1 |
|
$events = Event::latest() |
78
|
|
|
->when($authorUserId, function ($query, $authorUserId) { |
79
|
|
|
return $query->where('created_by', $authorUserId); |
80
|
1 |
|
}) |
81
|
1 |
|
->paginate(20); |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
return view('laravel-events-calendar::events.index', compact('events')) |
85
|
1 |
|
->with('i', (request()->input('page', 1) - 1) * 20) |
86
|
1 |
|
->with('eventCategories', $eventCategories) |
87
|
1 |
|
->with('countries', $countries) |
88
|
1 |
|
->with('venues', $venues) |
89
|
1 |
|
->with('searchKeywords', $searchKeywords) |
90
|
1 |
|
->with('searchCategory', $searchCategory) |
91
|
1 |
|
->with('searchCountry', $searchCountry); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/***************************************************************************/ |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Show the form for creating a new resource. |
98
|
|
|
* |
99
|
|
|
* @return \Illuminate\Http\Response |
100
|
|
|
*/ |
101
|
1 |
|
public function create() |
102
|
|
|
{ |
103
|
1 |
|
$authorUserId = $this->getLoggedAuthorId(); |
104
|
|
|
|
105
|
1 |
|
$eventCategories = EventCategory::listsTranslations('name')->orderBy('name')->pluck('name', 'id'); |
106
|
1 |
|
$users = User::orderBy('name')->pluck('name', 'id'); |
107
|
1 |
|
$teachers = Teacher::orderBy('name')->pluck('name', 'id'); |
108
|
1 |
|
$organizers = Organizer::orderBy('name')->pluck('name', 'id'); |
109
|
|
|
//$venues = EventVenue::pluck('name', 'id'); |
110
|
1 |
|
$venues = DB::table('event_venues') |
111
|
1 |
|
->select('id', 'name', 'city')->orderBy('name')->get(); |
112
|
|
|
|
113
|
1 |
|
$dateTime = []; |
114
|
1 |
|
$dateTime['repeatUntil'] = null; |
115
|
1 |
|
$dateTime['multipleDates'] = null; |
116
|
|
|
|
117
|
1 |
|
return view('laravel-events-calendar::events.create') |
118
|
1 |
|
->with('eventCategories', $eventCategories) |
119
|
1 |
|
->with('users', $users) |
120
|
1 |
|
->with('teachers', $teachers) |
121
|
1 |
|
->with('organizers', $organizers) |
122
|
1 |
|
->with('venues', $venues) |
123
|
1 |
|
->with('dateTime', $dateTime) |
124
|
1 |
|
->with('authorUserId', $authorUserId); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/***************************************************************************/ |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Store a newly created resource in storage. |
131
|
|
|
* |
132
|
|
|
* @param \Illuminate\Http\Request $request |
133
|
|
|
* @return \Illuminate\Http\Response |
134
|
|
|
*/ |
135
|
22 |
|
public function store(Request $request) |
136
|
|
|
{ |
137
|
|
|
// Validate form datas |
138
|
22 |
|
$validator = $this->eventsValidator($request); |
139
|
22 |
|
if ($validator->fails()) { |
140
|
|
|
//dd($validator->failed()); |
141
|
1 |
|
return back()->withErrors($validator)->withInput(); |
142
|
|
|
} |
143
|
|
|
|
144
|
21 |
|
$event = new Event(); |
145
|
21 |
|
$this->saveOnDb($request, $event); |
146
|
|
|
|
147
|
21 |
|
return redirect()->route('events.index') |
148
|
21 |
|
->with('success', __('laravel-events-calendar::messages.event_added_successfully')); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/***************************************************************************/ |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Display the specified resource. |
155
|
|
|
* |
156
|
|
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
157
|
|
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\EventRepetition $firstRpDates |
158
|
|
|
* @return \Illuminate\Http\Response |
159
|
|
|
*/ |
160
|
5 |
|
public function show(Event $event, EventRepetition $firstRpDates) |
161
|
|
|
{ |
162
|
|
|
//dd($firstRpDates); |
163
|
5 |
|
$category = EventCategory::find($event->category_id); |
164
|
5 |
|
$teachers = $event->teachers()->get(); |
165
|
5 |
|
$organizers = $event->organizers()->get(); |
166
|
|
|
|
167
|
5 |
|
$venue = DB::table('event_venues') |
168
|
5 |
|
->select('id', 'name', 'city', 'address', 'zip_code', 'country_id', 'region_id', 'description', 'website', 'extra_info') |
169
|
5 |
|
->where('id', $event->venue_id) |
170
|
5 |
|
->first(); |
171
|
|
|
|
172
|
5 |
|
$country = Country::find($venue->country_id); |
173
|
5 |
|
$region = Region::listsTranslations('name')->find($venue->region_id); |
174
|
|
|
|
175
|
5 |
|
$continent = Continent::find($country->continent_id); |
176
|
|
|
|
177
|
|
|
// Repetition text to show |
178
|
5 |
|
switch ($event->repeat_type) { |
179
|
5 |
|
case '1': // noRepeat |
180
|
2 |
|
$repetition_text = null; |
181
|
2 |
|
break; |
182
|
3 |
|
case '2': // repeatWeekly |
183
|
1 |
|
$repeatUntil = new DateTime($event->repeat_until); |
184
|
|
|
|
185
|
|
|
// Get the name of the weekly day when the event repeat, if two days, return like "Thursday and Sunday" |
186
|
1 |
|
$repetitonWeekdayNumbersArray = explode(',', $event->repeat_weekly_on); |
187
|
1 |
|
$repetitonWeekdayNamesArray = []; |
188
|
1 |
|
foreach ($repetitonWeekdayNumbersArray as $key => $repetitonWeekdayNumber) { |
189
|
1 |
|
$repetitonWeekdayNamesArray[] = LaravelEventsCalendar::decodeRepeatWeeklyOn($repetitonWeekdayNumber); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
// create from an array a string with all the values divided by " and " |
192
|
1 |
|
$nameOfTheRepetitionWeekDays = implode(' and ', $repetitonWeekdayNamesArray); |
193
|
|
|
|
194
|
|
|
//$repetition_text = 'The event happens every '.$nameOfTheRepetitionWeekDays.' until '.$repeatUntil->format('d/m/Y'); |
195
|
1 |
|
$format = __('laravel-events-calendar::event.the_event_happens_every_x_until_x'); |
196
|
1 |
|
$repetition_text = sprintf($format, $nameOfTheRepetitionWeekDays, $repeatUntil->format('d/m/Y')); |
|
|
|
|
197
|
1 |
|
break; |
198
|
2 |
|
case '3': //repeatMonthly |
199
|
1 |
|
$repeatUntil = new DateTime($event->repeat_until); |
200
|
1 |
|
$repetitionFrequency = LaravelEventsCalendar::decodeOnMonthlyKind($event->on_monthly_kind); |
|
|
|
|
201
|
|
|
|
202
|
|
|
//$repetition_text = 'The event happens '.$repetitionFrequency.' until '.$repeatUntil->format('d/m/Y'); |
203
|
1 |
|
$format = __('laravel-events-calendar::event.the_event_happens_x_until_x'); |
204
|
1 |
|
$repetition_text = sprintf($format, $repetitionFrequency, $repeatUntil->format('d/m/Y')); |
205
|
1 |
|
break; |
206
|
|
|
|
207
|
1 |
|
case '4': //repeatMultipleDays |
208
|
1 |
|
$dateStart = date('d/m/Y', strtotime($firstRpDates->start_repeat)); |
209
|
1 |
|
$singleDaysRepeatDatas = explode(',', $event->multiple_dates); |
210
|
|
|
|
211
|
|
|
// Sort the datas |
212
|
|
|
usort($singleDaysRepeatDatas, function ($a, $b) { |
213
|
1 |
|
$a = Carbon::createFromFormat('d/m/Y', $a); |
214
|
1 |
|
$b = Carbon::createFromFormat('d/m/Y', $b); |
215
|
|
|
|
216
|
1 |
|
return strtotime($a) - strtotime($b); |
217
|
1 |
|
}); |
218
|
|
|
|
219
|
|
|
//$repetition_text = 'The event happens on this dates: '; |
220
|
1 |
|
$repetition_text = __('laravel-events-calendar::event.the_event_happens_on_this_dates'); |
221
|
|
|
|
222
|
1 |
|
$repetition_text .= $dateStart.', '; |
223
|
1 |
|
$repetition_text .= LaravelEventsCalendar::getStringFromArraySeparatedByComma($singleDaysRepeatDatas); |
|
|
|
|
224
|
|
|
|
225
|
1 |
|
break; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
// True if the repetition start and end on the same day |
229
|
5 |
|
$sameDateStartEnd = ((date('Y-m-d', strtotime($firstRpDates->start_repeat))) == (date('Y-m-d', strtotime($firstRpDates->end_repeat)))) ? 1 : 0; |
230
|
|
|
|
231
|
5 |
|
return view('laravel-events-calendar::events.show', compact('event')) |
232
|
5 |
|
->with('category', $category) |
233
|
5 |
|
->with('teachers', $teachers) |
234
|
5 |
|
->with('organizers', $organizers) |
235
|
5 |
|
->with('venue', $venue) |
236
|
5 |
|
->with('country', $country) |
237
|
5 |
|
->with('region', $region) |
238
|
5 |
|
->with('continent', $continent) |
239
|
5 |
|
->with('datesTimes', $firstRpDates) |
240
|
5 |
|
->with('repetition_text', $repetition_text) |
|
|
|
|
241
|
5 |
|
->with('sameDateStartEnd', $sameDateStartEnd); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/***************************************************************************/ |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Show the form for editing the specified resource. |
248
|
|
|
* |
249
|
|
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
250
|
|
|
* @return \Illuminate\Http\Response |
251
|
|
|
*/ |
252
|
1 |
|
public function edit(Event $event) |
253
|
|
|
{ |
254
|
|
|
//if (Auth::user()->id == $event->created_by || Auth::user()->isSuperAdmin() || Auth::user()->isAdmin()) { |
255
|
1 |
|
if (Auth::user()->id == $event->created_by || Auth::user()->group == 1 || Auth::user()->group == 2) { |
|
|
|
|
256
|
1 |
|
$authorUserId = $this->getLoggedAuthorId(); |
257
|
|
|
|
258
|
|
|
//$eventCategories = EventCategory::pluck('name', 'id'); // removed because was braking the tests |
259
|
1 |
|
$eventCategories = EventCategory::listsTranslations('name')->orderBy('name')->pluck('name', 'id'); |
260
|
|
|
|
261
|
1 |
|
$users = User::orderBy('name')->pluck('name', 'id'); |
262
|
1 |
|
$teachers = Teacher::orderBy('name')->pluck('name', 'id'); |
263
|
1 |
|
$organizers = Organizer::orderBy('name')->pluck('name', 'id'); |
264
|
1 |
|
$venues = DB::table('event_venues') |
265
|
1 |
|
->select('id', 'name', 'address', 'city')->orderBy('name')->get(); |
266
|
|
|
|
267
|
1 |
|
$eventFirstRepetition = DB::table('event_repetitions') |
268
|
1 |
|
->select('id', 'start_repeat', 'end_repeat') |
269
|
1 |
|
->where('event_id', '=', $event->id) |
270
|
1 |
|
->first(); |
271
|
|
|
|
272
|
1 |
|
$dateTime = []; |
273
|
1 |
|
$dateTime['dateStart'] = (isset($eventFirstRepetition->start_repeat)) ? date('d/m/Y', strtotime($eventFirstRepetition->start_repeat)) : ''; |
274
|
1 |
|
$dateTime['dateEnd'] = (isset($eventFirstRepetition->end_repeat)) ? date('d/m/Y', strtotime($eventFirstRepetition->end_repeat)) : ''; |
275
|
1 |
|
$dateTime['timeStart'] = (isset($eventFirstRepetition->start_repeat)) ? date('g:i A', strtotime($eventFirstRepetition->start_repeat)) : ''; |
276
|
1 |
|
$dateTime['timeEnd'] = (isset($eventFirstRepetition->end_repeat)) ? date('g:i A', strtotime($eventFirstRepetition->end_repeat)) : ''; |
277
|
1 |
|
$dateTime['repeatUntil'] = date('d/m/Y', strtotime($event->repeat_until)); |
278
|
1 |
|
$dateTime['multipleDates'] = $event->multiple_dates; |
279
|
|
|
|
280
|
|
|
$multiple_teachers = LaravelEventsCalendar::getCollectionIdsSeparatedByComma($event->teachers); |
|
|
|
|
281
|
|
|
$multiple_organizers = LaravelEventsCalendar::getCollectionIdsSeparatedByComma($event->organizers); |
282
|
|
|
|
283
|
|
|
return view('laravel-events-calendar::events.edit', compact('event')) |
284
|
|
|
->with('eventCategories', $eventCategories) |
285
|
|
|
->with('users', $users) |
286
|
|
|
->with('teachers', $teachers) |
287
|
1 |
|
->with('multiple_teachers', $multiple_teachers) |
288
|
|
|
->with('organizers', $organizers) |
289
|
|
|
->with('multiple_organizers', $multiple_organizers) |
290
|
|
|
->with('venues', $venues) |
291
|
|
|
->with('dateTime', $dateTime) |
292
|
|
|
->with('authorUserId', $authorUserId); |
293
|
|
|
} else { |
294
|
|
|
return redirect()->route('home')->with('message', __('auth.not_allowed_to_access')); |
295
|
|
|
} |
296
|
1 |
|
} |
297
|
|
|
|
298
|
1 |
|
/***************************************************************************/ |
299
|
1 |
|
|
300
|
1 |
|
/** |
301
|
1 |
|
* Update the specified resource in storage. |
302
|
1 |
|
* |
303
|
1 |
|
* @param \Illuminate\Http\Request $request |
304
|
1 |
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
305
|
1 |
|
* @return \Illuminate\Http\Response |
306
|
1 |
|
*/ |
307
|
1 |
|
public function update(Request $request, Event $event) |
308
|
|
|
{ |
309
|
|
|
// Validate form datas |
310
|
|
|
$validator = $this->eventsValidator($request); |
311
|
|
|
if ($validator->fails()) { |
312
|
|
|
return back()->withErrors($validator)->withInput(); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
$this->saveOnDb($request, $event); |
316
|
|
|
|
317
|
|
|
return redirect()->route('events.index') |
318
|
|
|
->with('success', __('laravel-events-calendar::messages.event_updated_successfully')); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/***************************************************************************/ |
322
|
2 |
|
|
323
|
|
|
/** |
324
|
|
|
* Remove the specified resource from storage. |
325
|
2 |
|
* |
326
|
2 |
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
327
|
1 |
|
* @return \Illuminate\Http\Response |
328
|
|
|
*/ |
329
|
|
|
public function destroy(Event $event) |
330
|
1 |
|
{ |
331
|
|
|
DB::table('event_repetitions') |
332
|
1 |
|
->where('event_id', $event->id) |
333
|
1 |
|
->delete(); |
334
|
|
|
|
335
|
|
|
$event->delete(); |
336
|
|
|
|
337
|
|
|
return redirect()->route('events.index') |
338
|
|
|
->with('success', __('laravel-events-calendar::messages.event_deleted_successfully')); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/***************************************************************************/ |
342
|
|
|
|
343
|
|
|
/** |
344
|
1 |
|
* To save event repetitions for create and update methods. |
345
|
|
|
* |
346
|
1 |
|
* @param \Illuminate\Http\Request $request |
347
|
1 |
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
348
|
1 |
|
* @return void |
349
|
|
|
*/ |
350
|
1 |
|
public function saveEventRepetitions(Request $request, int $eventId) |
351
|
|
|
{ |
352
|
1 |
|
EventRepetition::deletePreviousRepetitions($eventId); |
353
|
1 |
|
|
354
|
|
|
// Saving repetitions - If it's a single event will be stored with just one repetition |
355
|
|
|
//$timeStart = date('H:i:s', strtotime($request->get('time_start'))); |
356
|
|
|
//$timeEnd = date('H:i:s', strtotime($request->get('time_end'))); |
357
|
|
|
//$timeStart = $request->get('time_start'); |
358
|
|
|
//$timeEnd = $request->get('time_end'); |
359
|
|
|
$timeStart = date('H:i', strtotime($request->get('time_start'))); |
360
|
|
|
$timeEnd = date('H:i', strtotime($request->get('time_end'))); |
361
|
|
|
|
362
|
|
|
switch ($request->get('repeat_type')) { |
363
|
|
|
case '1': // noRepeat |
364
|
|
|
$eventRepetition = new EventRepetition(); |
365
|
21 |
|
$eventRepetition->event_id = $eventId; |
366
|
|
|
|
367
|
21 |
|
$dateStart = implode('-', array_reverse(explode('/', $request->get('startDate')))); |
368
|
|
|
$dateEnd = implode('-', array_reverse(explode('/', $request->get('endDate')))); |
369
|
|
|
|
370
|
|
|
$eventRepetition->start_repeat = $dateStart.' '.$timeStart; |
371
|
|
|
$eventRepetition->end_repeat = $dateEnd.' '.$timeEnd; |
372
|
|
|
$eventRepetition->save(); |
373
|
|
|
|
374
|
21 |
|
break; |
375
|
21 |
|
|
376
|
|
|
case '2': // repeatWeekly |
377
|
21 |
|
// Convert the start date in a format that can be used for strtotime |
378
|
21 |
|
$startDate = implode('-', array_reverse(explode('/', $request->get('startDate')))); |
379
|
13 |
|
|
380
|
13 |
|
// Calculate repeat until day |
381
|
|
|
$repeatUntilDate = implode('-', array_reverse(explode('/', $request->get('repeat_until')))); |
382
|
13 |
|
EventRepetition::saveWeeklyRepeatDates($eventId, $request->get('repeat_weekly_on_day'), $startDate, $repeatUntilDate, $timeStart, $timeEnd); |
|
|
|
|
383
|
13 |
|
|
384
|
|
|
break; |
385
|
13 |
|
|
386
|
13 |
|
case '3': //repeatMonthly |
387
|
13 |
|
// Same of repeatWeekly |
388
|
|
|
$startDate = implode('-', array_reverse(explode('/', $request->get('startDate')))); |
389
|
13 |
|
$repeatUntilDate = implode('-', array_reverse(explode('/', $request->get('repeat_until')))); |
390
|
|
|
|
391
|
8 |
|
// Get the array with month repeat details |
392
|
|
|
$monthRepeatDatas = explode('|', $request->get('on_monthly_kind')); |
393
|
2 |
|
//dump("pp_1"); |
394
|
|
|
EventRepetition::saveMonthlyRepeatDates($eventId, $monthRepeatDatas, $startDate, $repeatUntilDate, $timeStart, $timeEnd); |
395
|
|
|
|
396
|
2 |
|
break; |
397
|
2 |
|
|
398
|
|
|
case '4': //repeatMultipleDays |
399
|
2 |
|
// Same of repeatWeekly |
400
|
|
|
$startDate = implode('-', array_reverse(explode('/', $request->get('startDate')))); |
401
|
6 |
|
|
402
|
|
|
// Get the array with single day repeat details |
403
|
5 |
|
$singleDaysRepeatDatas = explode(',', $request->get('multiple_dates')); |
404
|
5 |
|
|
405
|
|
|
EventRepetition::saveMultipleRepeatDates($eventId, $singleDaysRepeatDatas, $startDate, $timeStart, $timeEnd); |
406
|
|
|
|
407
|
5 |
|
break; |
408
|
|
|
} |
409
|
5 |
|
} |
410
|
|
|
|
411
|
5 |
|
/***************************************************************************/ |
412
|
|
|
|
413
|
1 |
|
/** |
414
|
|
|
* Send the Misuse mail. |
415
|
1 |
|
* |
416
|
|
|
* @param \Illuminate\Http\Request $request |
417
|
|
|
* @return \Illuminate\Http\Response |
418
|
1 |
|
*/ |
419
|
|
|
public function reportMisuse(Request $request) |
420
|
1 |
|
{ |
421
|
|
|
$report = []; |
422
|
1 |
|
|
423
|
|
|
//$report['senderEmail'] = '[email protected]'; |
424
|
21 |
|
$report['senderEmail'] = $request->user_email; |
425
|
|
|
$report['senderName'] = 'Anonymus User'; |
426
|
|
|
$report['subject'] = 'Report misuse form'; |
427
|
|
|
//$report['adminEmail'] = env('ADMIN_MAIL'); |
428
|
|
|
$report['creatorEmail'] = $this->getCreatorEmail($request->created_by); |
429
|
|
|
|
430
|
|
|
$report['message_misuse'] = $request->message_misuse; |
431
|
|
|
$report['event_title'] = $request->event_title; |
432
|
|
|
$report['event_id'] = $request->event_id; |
433
|
|
|
$report['event_slug'] = $request->slug; |
434
|
|
|
|
435
|
|
|
$report['reason'] = LaravelEventsCalendar::getReportMisuseReasonDescription($request->reason); |
|
|
|
|
436
|
|
|
|
437
|
|
|
/* |
438
|
|
|
switch ($request->reason) { |
439
|
|
|
case '1': |
440
|
|
|
$report['reason'] = 'Not about Contact Improvisation'; |
441
|
|
|
break; |
442
|
|
|
case '2': |
443
|
|
|
$report['reason'] = 'Contains wrong informations'; |
444
|
|
|
break; |
445
|
|
|
case '3': |
446
|
|
|
$report['reason'] = 'It is not translated in english'; |
447
|
|
|
break; |
448
|
|
|
case '4': |
449
|
|
|
$report['reason'] = 'Other (specify in the message)'; |
450
|
|
|
break; |
451
|
|
|
} |
452
|
|
|
*/ |
453
|
|
|
|
454
|
|
|
//Mail::to($request->user())->send(new ReportMisuse($report)); |
455
|
|
|
Mail::to(env('ADMIN_MAIL'))->send(new ReportMisuse($report)); |
456
|
|
|
|
457
|
|
|
return redirect()->route('events.misuse-thankyou'); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/***************************************************************************/ |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Send the mail to the Organizer (from the event modal in the event show view). |
464
|
|
|
* |
465
|
|
|
* @param \Illuminate\Http\Request $request |
466
|
|
|
* @return \Illuminate\Http\Response |
467
|
|
|
*/ |
468
|
|
|
public function mailToOrganizer(Request $request) |
469
|
|
|
{ |
470
|
|
|
$message = []; |
471
|
|
|
$message['senderEmail'] = $request->user_email; |
472
|
|
|
$message['senderName'] = $request->user_name; |
473
|
|
|
$message['subject'] = 'Request from the Global CI Calendar'; |
474
|
|
|
//$message['emailTo'] = $organizersEmails; |
475
|
|
|
|
476
|
|
|
$message['message'] = $request->message; |
477
|
|
|
$message['event_title'] = $request->event_title; |
478
|
|
|
$message['event_id'] = $request->event_id; |
479
|
|
|
$message['event_slug'] = $request->slug; |
480
|
|
|
|
481
|
|
|
/* |
482
|
|
|
$eventOrganizers = Event::find($request->event_id)->organizers; |
483
|
|
|
foreach ($eventOrganizers as $eventOrganizer) { |
484
|
|
|
Mail::to($eventOrganizer->email)->send(new ContactOrganizer($message)); |
485
|
|
|
}*/ |
486
|
|
|
|
487
|
|
|
Mail::to($request->contact_email)->send(new ContactOrganizer($message)); |
488
|
|
|
|
489
|
|
|
return redirect()->route('events.organizer-sent'); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/***************************************************************************/ |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* Display the thank you view after the mail to the organizer is sent (called by /mailToOrganizer/sent route). |
496
|
|
|
* |
497
|
|
|
* @return \Illuminate\Http\Response |
498
|
|
|
*/ |
499
|
|
|
public function mailToOrganizerSent() |
500
|
|
|
{ |
501
|
|
|
return view('laravel-events-calendar::emails.contact.organizer-sent'); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/***************************************************************************/ |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Display the thank you view after the misuse report mail is sent (called by /misuse/thankyou route). |
508
|
|
|
* |
509
|
|
|
* @return \Illuminate\Http\Response |
510
|
1 |
|
*/ |
511
|
|
|
public function reportMisuseThankyou() |
512
|
1 |
|
{ |
513
|
|
|
return view('laravel-events-calendar::emails.report-thankyou'); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/***************************************************************************/ |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Set the Event attributes about repeating before store or update (repeat until field and multiple days). |
520
|
|
|
* |
521
|
|
|
* @param \Illuminate\Http\Request $request |
522
|
1 |
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
523
|
|
|
* @return \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
524
|
1 |
|
*/ |
525
|
|
|
public function setEventRepeatFields(Request $request, Event $event) |
526
|
|
|
{ |
527
|
|
|
// Set Repeat Until |
528
|
|
|
$event->repeat_type = $request->get('repeat_type'); |
529
|
|
|
if ($request->get('repeat_until')) { |
530
|
|
|
$dateRepeatUntil = implode('-', array_reverse(explode('/', $request->get('repeat_until')))); |
531
|
|
|
$event->repeat_until = $dateRepeatUntil.' 00:00:00'; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
// Weekely - Set multiple week days |
535
|
|
|
if ($request->get('repeat_weekly_on_day')) { |
536
|
21 |
|
$repeat_weekly_on_day = $request->get('repeat_weekly_on_day'); |
537
|
|
|
//dd($repeat_weekly_on_day); |
538
|
|
|
$i = 0; |
539
|
21 |
|
$len = count($repeat_weekly_on_day); // to put "," to all items except the last |
540
|
21 |
|
$event->repeat_weekly_on = ''; |
541
|
7 |
|
foreach ($repeat_weekly_on_day as $key => $weeek_day) { |
542
|
7 |
|
$event->repeat_weekly_on .= $weeek_day; |
543
|
|
|
if ($i != $len - 1) { // not last |
544
|
|
|
$event->repeat_weekly_on .= ','; |
545
|
|
|
} |
546
|
21 |
|
$i++; |
547
|
2 |
|
} |
548
|
|
|
} |
549
|
2 |
|
|
550
|
2 |
|
// Monthly |
551
|
2 |
|
|
552
|
2 |
|
/* $event->repeat_type = $request->get('repeat_monthly_on');*/ |
553
|
2 |
|
|
554
|
2 |
|
return $event; |
555
|
2 |
|
} |
556
|
|
|
|
557
|
2 |
|
/***************************************************************************/ |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Return the HTML of the monthly select dropdown - inspired by - https://www.theindychannel.com/calendar |
561
|
|
|
* - Used by the AJAX in the event repeat view - |
562
|
|
|
* - The HTML contain a <select></select> with four <options></options>. |
563
|
|
|
* |
564
|
|
|
* @param \Illuminate\Http\Request $request - Just the day |
565
|
21 |
|
* @return string |
566
|
|
|
*/ |
567
|
|
|
public function calculateMonthlySelectOptions(Request $request) |
568
|
|
|
{ |
569
|
|
|
$monthlySelectOptions = []; |
570
|
|
|
$date = implode('-', array_reverse(explode('/', $request->day))); // Our YYYY-MM-DD date string |
571
|
|
|
$unixTimestamp = strtotime($date); // Convert the date string into a unix timestamp. |
572
|
|
|
$dayOfWeekString = date('l', $unixTimestamp); // Monday | Tuesday | Wednesday | .. |
573
|
|
|
|
574
|
|
|
// Same day number - eg. "the 28th day of the month" |
575
|
|
|
$dateArray = explode('/', $request->day); |
576
|
|
|
$dayNumber = ltrim($dateArray[0], '0'); // remove the 0 in front of a day number eg. 02/10/2018 |
577
|
|
|
|
578
|
1 |
|
$format = __('laravel-events-calendar::ordinalDays.the_'.($dayNumber).'_x_of_the_month'); |
579
|
|
|
$repeatText = sprintf($format, 'day'); |
|
|
|
|
580
|
1 |
|
|
581
|
1 |
|
array_push($monthlySelectOptions, [ |
582
|
1 |
|
'value' => '0|'.$dayNumber, |
583
|
1 |
|
'text' => $repeatText, |
584
|
|
|
]); |
585
|
|
|
|
586
|
1 |
|
// Same weekday/week of the month - eg. the "1st Monday" 1|1|1 (first week, monday) |
587
|
1 |
|
$dayOfWeekValue = date('N', $unixTimestamp); // 1 (for Monday) through 7 (for Sunday) |
588
|
|
|
$weekOfTheMonth = LaravelEventsCalendar::weekdayNumberOfMonth($date, $dayOfWeekValue); // 1 | 2 | 3 | 4 | 5 |
|
|
|
|
589
|
1 |
|
|
590
|
1 |
|
$format = __('laravel-events-calendar::ordinalDays.the_'.($weekOfTheMonth).'_x_of_the_month'); |
591
|
|
|
$repeatText = sprintf($format, $dayOfWeekString); |
592
|
1 |
|
|
593
|
1 |
|
array_push($monthlySelectOptions, [ |
594
|
1 |
|
'value' => '1|'.$weekOfTheMonth.'|'.$dayOfWeekValue, |
595
|
|
|
'text' => $repeatText, |
596
|
|
|
]); |
597
|
|
|
|
598
|
1 |
|
// Same day of the month (from the end) - the 3rd to last day (0 if last day, 1 if 2nd to last day, , 2 if 3rd to last day) |
599
|
1 |
|
$dayOfMonthFromTheEnd = LaravelEventsCalendar::dayOfMonthFromTheEnd($unixTimestamp); // 1 | 2 | 3 | 4 | 5 |
|
|
|
|
600
|
|
|
|
601
|
1 |
|
$format = __('laravel-events-calendar::ordinalDays.the_'.($dayOfMonthFromTheEnd + 1).'_to_last_x_of_the_month'); |
602
|
1 |
|
$repeatText = sprintf($format, 'day'); |
603
|
|
|
|
604
|
1 |
|
array_push($monthlySelectOptions, [ |
605
|
1 |
|
'value' => '2|'.$dayOfMonthFromTheEnd, |
606
|
1 |
|
'text' => $repeatText, |
607
|
|
|
]); |
608
|
|
|
|
609
|
|
|
// Same weekday/week of the month (from the end) - the last Friday - (0 if last Friday, 1 if the 2nd to last Friday, 2 if the 3nd to last Friday) |
610
|
1 |
|
$weekOfMonthFromTheEnd = LaravelEventsCalendar::weekOfMonthFromTheEnd($unixTimestamp); // 1 | 2 | 3 | 4 | 5 |
|
|
|
|
611
|
|
|
|
612
|
1 |
|
if ($weekOfMonthFromTheEnd == 1) { |
613
|
1 |
|
$weekValue = 0; |
614
|
|
|
} else { |
615
|
1 |
|
$weekValue = $weekOfMonthFromTheEnd - 1; |
616
|
1 |
|
} |
617
|
1 |
|
|
618
|
|
|
$format = __('laravel-events-calendar::ordinalDays.the_'.($weekOfMonthFromTheEnd).'_to_last_x_of_the_month'); |
619
|
|
|
$repeatText = sprintf($format, $dayOfWeekString); |
620
|
|
|
|
621
|
1 |
|
array_push($monthlySelectOptions, [ |
622
|
|
|
'value' => '3|'.$weekValue.'|'.$dayOfWeekValue, |
623
|
1 |
|
'text' => $repeatText, |
624
|
|
|
]); |
625
|
|
|
|
626
|
1 |
|
// GENERATE the HTML to return |
627
|
|
|
$selectTitle = __('laravel-events-calendar::general.select_repeat_monthly_kind'); |
628
|
|
|
$onMonthlyKindSelect = "<select name='on_monthly_kind' id='on_monthly_kind' class='selectpicker' title='".$selectTitle."'>"; |
|
|
|
|
629
|
1 |
|
foreach ($monthlySelectOptions as $key => $monthlySelectOption) { |
630
|
1 |
|
$onMonthlyKindSelect .= "<option value='".$monthlySelectOption['value']."'>".$monthlySelectOption['text'].'</option>'; |
631
|
|
|
} |
632
|
1 |
|
$onMonthlyKindSelect .= '</select>'; |
633
|
1 |
|
|
634
|
1 |
|
return $onMonthlyKindSelect; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
// ********************************************************************** |
638
|
1 |
|
|
639
|
1 |
|
/** |
640
|
1 |
|
* Save/Update the record on DB. |
641
|
1 |
|
* |
642
|
|
|
* @param \Illuminate\Http\Request $request |
643
|
1 |
|
* @param \DavideCasiraghi\LaravelEventsCalendar\Models\Event $event |
644
|
|
|
* @return string $ret - the ordinal indicator (st, nd, rd, th) |
645
|
1 |
|
*/ |
646
|
|
|
public function saveOnDb(Request $request, Event $event) |
647
|
|
|
{ |
648
|
|
|
//$countries = Country::getCountries(); |
649
|
|
|
$teachers = Teacher::pluck('name', 'id'); |
650
|
|
|
|
651
|
|
|
/*$venue = DB::table('event_venues') |
652
|
|
|
->select('event_venues.id AS venue_id', 'event_venues.name AS venue_name', 'event_venues.country_id AS country_id', 'event_venues.continent_id', 'event_venues.city') |
653
|
|
|
->where('event_venues.id', '=', $request->get('venue_id')) |
654
|
|
|
->first();*/ |
655
|
|
|
|
656
|
|
|
$event->title = $request->get('title'); |
657
|
21 |
|
$event->description = clean($request->get('description')); |
658
|
|
|
|
659
|
|
|
if ($request->get('created_by')) { |
660
|
21 |
|
$event->created_by = $request->get('created_by'); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
if (! $event->slug) { |
664
|
|
|
$event->slug = Str::slug($event->title, '-').'-'.rand(100000, 1000000); |
665
|
|
|
} |
666
|
|
|
$event->category_id = $request->get('category_id'); |
667
|
21 |
|
$event->venue_id = $request->get('venue_id'); |
668
|
21 |
|
$event->image = $request->get('image'); |
669
|
|
|
$event->contact_email = $request->get('contact_email'); |
670
|
21 |
|
$event->website_event_link = $request->get('website_event_link'); |
671
|
21 |
|
$event->facebook_event_link = $request->get('facebook_event_link'); |
672
|
|
|
$event->status = $request->get('status'); |
673
|
|
|
$event->on_monthly_kind = $request->get('on_monthly_kind'); |
674
|
21 |
|
$event->multiple_dates = $request->get('multiple_dates'); |
675
|
21 |
|
|
676
|
|
|
// Event teaser image upload |
677
|
21 |
|
if ($request->file('image')) { |
678
|
21 |
|
$imageFile = $request->file('image'); |
679
|
21 |
|
$imageName = time().'.'.'jpg'; //$imageName = $teaserImageFile->hashName(); |
680
|
21 |
|
$imageSubdir = 'events_teaser'; |
681
|
21 |
|
$imageWidth = 968; |
682
|
21 |
|
$thumbWidth = 310; |
683
|
21 |
|
|
684
|
21 |
|
$this->uploadImageOnServer($imageFile, $imageName, $imageSubdir, $imageWidth, $thumbWidth); |
|
|
|
|
685
|
21 |
|
$event->image = $imageName; |
686
|
|
|
} else { |
687
|
|
|
$event->image = $request->get('image'); |
688
|
21 |
|
} |
689
|
|
|
|
690
|
|
|
// Support columns for homepage search (we need this to show events in HP with less use of resources) |
691
|
|
|
$event->sc_teachers_id = json_encode(explode(',', $request->get('multiple_teachers'))); // keep just this SC |
692
|
|
|
|
693
|
|
|
// Multiple teachers - populate support column field |
694
|
|
|
$event->sc_teachers_names = ''; |
695
|
|
|
if ($request->get('multiple_teachers')) { |
696
|
|
|
$multiple_teachers = explode(',', $request->get('multiple_teachers')); |
697
|
|
|
|
698
|
21 |
|
$multiple_teachers_names = []; |
699
|
|
|
foreach ($multiple_teachers as $key => $teacher_id) { |
700
|
|
|
$multiple_teachers_names[] = $teachers[$teacher_id]; |
701
|
|
|
} |
702
|
21 |
|
|
703
|
|
|
$event->sc_teachers_names .= LaravelEventsCalendar::getStringFromArraySeparatedByComma($multiple_teachers_names); |
704
|
|
|
} |
705
|
21 |
|
|
706
|
21 |
|
// Set the Event attributes about repeating (repeat until field and multiple days) |
707
|
2 |
|
$event = $this->setEventRepeatFields($request, $event); |
708
|
|
|
|
709
|
2 |
|
// Save event and repetitions |
710
|
2 |
|
$event->save(); |
711
|
2 |
|
$this->saveEventRepetitions($request, $event->id); |
712
|
|
|
|
713
|
|
|
// Update multi relationships with teachers and organizers tables. |
714
|
2 |
|
if ($request->get('multiple_teachers')) { |
715
|
|
|
$multiple_teachers = explode(',', $request->get('multiple_teachers')); |
716
|
|
|
$event->teachers()->sync($multiple_teachers); |
717
|
|
|
} else { |
718
|
21 |
|
$event->teachers()->sync([]); |
719
|
|
|
} |
720
|
|
|
if ($request->get('multiple_organizers')) { |
721
|
21 |
|
$multiple_organizers = explode(',', $request->get('multiple_organizers')); |
722
|
21 |
|
$event->organizers()->sync($multiple_organizers); |
723
|
|
|
} else { |
724
|
|
|
$event->organizers()->sync([]); |
725
|
21 |
|
} |
726
|
2 |
|
} |
727
|
2 |
|
|
728
|
|
|
/***********************************************************************/ |
729
|
19 |
|
|
730
|
|
|
/** |
731
|
21 |
|
* Get creator email. |
732
|
|
|
* |
733
|
|
|
* @param int $created_by |
734
|
|
|
* @return \Illuminate\Foundation\Auth\User |
735
|
21 |
|
*/ |
736
|
|
|
public function getCreatorEmail(int $created_by) |
737
|
21 |
|
{ |
738
|
|
|
$creatorEmail = DB::table('users') // Used to send the Report misuse (not in english) |
739
|
|
|
->select('email') |
740
|
|
|
->where('id', $created_by) |
741
|
|
|
->first(); |
742
|
|
|
|
743
|
|
|
$ret = $creatorEmail->email; |
744
|
|
|
|
745
|
|
|
return $ret; |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
/***************************************************************************/ |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* Return the event by SLUG. (eg. http://websitename.com/event/xxxx). |
752
|
|
|
* |
753
|
|
|
* @param string $slug |
754
|
|
|
* @return \Illuminate\Http\Response |
755
|
|
|
*/ |
756
|
|
|
public function eventBySlug(string $slug) |
757
|
|
|
{ |
758
|
|
|
$event = Event::where('slug', $slug)->first(); |
759
|
|
|
$firstRpDates = EventRepetition::getFirstEventRpDatesByEventId($event->id); |
760
|
|
|
|
761
|
|
|
return $this->show($event, $firstRpDates); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
/***************************************************************************/ |
765
|
|
|
|
766
|
|
|
/** |
767
|
1 |
|
* Return the event by SLUG. (eg. http://websitename.com/event/xxxx/300). |
768
|
|
|
* @param string $slug |
769
|
1 |
|
* @param int $repetitionId |
770
|
1 |
|
* @return \Illuminate\Http\Response |
771
|
|
|
*/ |
772
|
1 |
|
public function eventBySlugAndRepetition(string $slug, int $repetitionId) |
773
|
|
|
{ |
774
|
|
|
$event = Event::where('slug', $slug)->first(); |
775
|
|
|
$firstRpDates = EventRepetition::getFirstEventRpDatesByRepetitionId($repetitionId); |
776
|
|
|
|
777
|
|
|
// If not found get the first repetion of the event in the future. |
778
|
|
|
if (empty($firstRpDates)) { |
779
|
|
|
$firstRpDates = EventRepetition::getFirstEventRpDatesByEventId($event->id); |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
return $this->show($event, $firstRpDates); |
783
|
4 |
|
} |
784
|
|
|
|
785
|
4 |
|
/***************************************************************************/ |
786
|
4 |
|
|
787
|
|
|
/** |
788
|
|
|
* Return the Event validator with all the defined constraint. |
789
|
4 |
|
* @param \Illuminate\Http\Request $request |
790
|
1 |
|
* @return \Illuminate\Http\Response |
791
|
|
|
*/ |
792
|
|
|
public function eventsValidator(Request $request) |
793
|
4 |
|
{ |
794
|
|
|
$rules = [ |
795
|
|
|
'title' => 'required', |
796
|
|
|
'description' => 'required', |
797
|
|
|
'category_id' => 'required', |
798
|
|
|
'venue_id' => 'required', |
799
|
|
|
'startDate' => 'required', |
800
|
|
|
'endDate' => 'required', |
801
|
|
|
'repeat_until' => Rule::requiredIf($request->repeat_type == 2 || $request->repeat_type == 3), |
802
|
|
|
'repeat_weekly_on_day' => Rule::requiredIf($request->repeat_type == 2), |
803
|
22 |
|
'on_monthly_kind' => Rule::requiredIf($request->repeat_type == 3), |
804
|
|
|
'contact_email' => 'nullable|email', |
805
|
|
|
'facebook_event_link' => 'nullable|url', |
806
|
22 |
|
'website_event_link' => 'nullable|url', |
807
|
22 |
|
// 'image' => 'nullable|image|mimes:jpeg,jpg,png|max:3000', // BUG create problems to validate on edit. Fix this after the rollout |
808
|
22 |
|
]; |
809
|
22 |
|
if ($request->hasFile('image')) { |
810
|
22 |
|
$rules['image'] = 'nullable|image|mimes:jpeg,jpg,png|max:5000'; |
811
|
22 |
|
} |
812
|
22 |
|
|
813
|
22 |
|
$messages = [ |
814
|
22 |
|
'repeat_weekly_on_day[].required' => 'Please specify which day of the week is repeting the event.', |
815
|
22 |
|
'on_monthly_kind.required' => 'Please specify the kind of monthly repetion', |
816
|
22 |
|
'endDate.same' => 'If the event is repetitive the start date and end date must match', |
817
|
22 |
|
'facebook_event_link.url' => 'The facebook link is invalid. It should start with https://', |
818
|
|
|
'website_event_link.url' => 'The website link is invalid. It should start with https://', |
819
|
|
|
'image.max' => 'The maximum image size is 5MB. If you need to resize it you can use: www.simpleimageresizer.com', |
820
|
22 |
|
]; |
821
|
|
|
|
822
|
|
|
$validator = Validator::make($request->all(), $rules, $messages); |
823
|
|
|
|
824
|
|
|
// End date and start date must match if the event is repetitive |
825
|
22 |
|
$validator->sometimes('endDate', 'same:startDate', function ($input) { |
826
|
|
|
return $input->repeat_type > 1; |
827
|
|
|
}); |
828
|
|
|
|
829
|
|
|
return $validator; |
830
|
|
|
} |
831
|
|
|
} |
832
|
|
|
|