diff --git a/app/Booking.php b/app/Booking.php new file mode 100644 index 00000000..bf30ebc7 --- /dev/null +++ b/app/Booking.php @@ -0,0 +1,18 @@ +morphTo(); + } + + public function user() + { + return $this->belongsTo('App\User'); + } +} diff --git a/app/Course.php b/app/Course.php new file mode 100644 index 00000000..f4af73f0 --- /dev/null +++ b/app/Course.php @@ -0,0 +1,23 @@ +morphMany('App\Booking', 'bookable'); + } + + public function user() + { + return $this->belongsTo('App\User'); + } + + public function event() + { + return $this->belongsTo('App\Event'); + } +} diff --git a/app/Event.php b/app/Event.php new file mode 100644 index 00000000..1d534b48 --- /dev/null +++ b/app/Event.php @@ -0,0 +1,23 @@ +morphMany('App\Booking', 'bookable'); + } + + public function courses() + { + return $this->hasMany('App\Course'); + } + + public function user() + { + return $this->belongsTo('App\User'); + } +} diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php new file mode 100644 index 00000000..078761c0 --- /dev/null +++ b/app/Http/Controllers/BookingController.php @@ -0,0 +1,85 @@ +start,0,10); + $end = substr(request()->end,0,10); + $allschedules = Schedule::all(); + $allevents = \App\Event::all(); $events = []; + $jsonevents = []; + $schedules = []; + + foreach ($allschedules as $schedule) { + if($schedule->date >= $start && $schedule->date <= $end) { + array_push($schedules,$schedule); + } + } + + foreach ($allevents as $event) { + if($event->date_begin >= $start && $event->date_begin <= $end) { + array_push($events,$event); + } + if($event->date_end >= $start && $event->date_end <= $end) { + array_push($events,$event); + } + } + foreach ($schedules as $schedule) { - $color = 'blue'; - switch ($schedule->type) { - case 'regular': - $color = 'orange'; - break; - - case 'pilotage': - $color = '#58D3F7'; - break; - - case 'drill': - $color = 'blue'; - break; - - case 'music': - $color = 'green'; - break; - - case 'biathlon': - $color = 'red'; - break; - - case 'marksmanship': - $color = 'grey'; - break; - - case 'founding': - $color = '#00FF40'; - break; - - case 'volunteer': - $color = '#DF0174'; - break; - - case 'other': - $color = '#DF0174'; - break; - - default: - if ($activity->find($schedule->type)) { - $color = $activity->find($schedule->type)->calendar_color; - } - break; - }; + + $color = $this->getColor($schedule->type); $event = [ 'title' => $schedule->data['event_name'], @@ -115,14 +93,83 @@ class ScheduleController extends Controller 'color' => $color, 'id' => $schedule->id ]; - array_push($events,$event); + array_push($jsonevents,$event); } - return json_encode($events); + foreach ($events as $event) { + + $color = $this->getColor($event->type); + + $myevent = [ + 'title' => $event->name, + 'start' => $event->date_begin, + 'end' => $event->date_end, + 'color' => $color, + 'id' => $event->id + ]; + array_push($jsonevents,$myevent); + } + + return json_encode($jsonevents); } public function loadModal($id) { return view('public.modal.schedule',['event' => \App\Schedule::find($id)]); } + + public function loadModalFull($id) + { + return view('admin.schedule.modal.show',['event' => \App\Schedule::find($id)]); + } + + public function getColor($type) + { + $activity = \App\ComplementaryActivity::all(); + $color = 'blue'; + switch ($type) { + case 'regular': + $color = 'orange'; + break; + + case 'pilotage': + $color = '#58D3F7'; + break; + + case 'drill': + $color = 'blue'; + break; + + case 'music': + $color = 'green'; + break; + + case 'biathlon': + $color = 'red'; + break; + + case 'marksmanship': + $color = 'grey'; + break; + + case 'founding': + $color = '#00FF40'; + break; + + case 'volunteer': + $color = '#DF0174'; + break; + + case 'other': + $color = '#DF0174'; + break; + + default: + if ($activity->find($type)) { + $color = $activity->find($type)->calendar_color; + } + break; + }; + return $color; + } } diff --git a/app/Item.php b/app/Item.php index 8f6d7da0..de83e594 100644 --- a/app/Item.php +++ b/app/Item.php @@ -17,4 +17,9 @@ class Item extends Model $col_items->forget(0); return $col_items; } + + public function bookings() + { + return $this->hasMany('App\Booking'); + } } diff --git a/app/User.php b/app/User.php index 69657d4c..6fe3f330 100644 --- a/app/User.php +++ b/app/User.php @@ -50,6 +50,21 @@ class User extends Authenticatable return $this->hasMany(Message::class); } + public function events() + { + return $this->hasMany('App\Event'); + } + + public function bookings() + { + return $this->hasMany('App\Booking'); + } + + public function courses() + { + return $this->hasMany('App\Course'); + } + public function routeNotificationForNexmo($notification) { return $this->telephone; diff --git a/database/migrations/2019_08_17_102431_create_events_table.php b/database/migrations/2019_08_17_102431_create_events_table.php new file mode 100644 index 00000000..6149cb20 --- /dev/null +++ b/database/migrations/2019_08_17_102431_create_events_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->string('name'); + $table->string('date_begin'); + $table->string('date_end'); + $table->string('type'); + $table->string('user_id'); + $table->string('location'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('events'); + } +} diff --git a/database/migrations/2019_08_17_102836_create_courses_table.php b/database/migrations/2019_08_17_102836_create_courses_table.php new file mode 100644 index 00000000..16314a66 --- /dev/null +++ b/database/migrations/2019_08_17_102836_create_courses_table.php @@ -0,0 +1,39 @@ +increments('id'); + $table->string('name'); + $table->string('ocom'); + $table->integer('periode'); + $table->integer('level'); + $table->string('location'); + $table->text('comment'); + $table->integer('event_id'); + $table->integer('user_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('courses'); + } +} diff --git a/database/migrations/2019_08_17_102916_create_bookings_table.php b/database/migrations/2019_08_17_102916_create_bookings_table.php new file mode 100644 index 00000000..7763b376 --- /dev/null +++ b/database/migrations/2019_08_17_102916_create_bookings_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->integer('item_id'); + $table->integer('amount'); + $table->integer('bookable_id'); + $table->string('bookable_type'); + $table->integer('user_id'); + $table->text('comment'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bookings'); + } +} diff --git a/public/js/calendar.js b/public/js/calendar.js new file mode 100644 index 00000000..cb65f195 --- /dev/null +++ b/public/js/calendar.js @@ -0,0 +1,41 @@ +function initFullCalendar(authToken) { + document.addEventListener('DOMContentLoaded', function () { + var calendarEl = document.getElementById('fullCalendar'); + + var calendar = new FullCalendar.Calendar(calendarEl, { + plugins: ['dayGrid','interaction'], + locale: 'fr-ca', + header: { + left: 'title', + center: '', + right: 'prev,next' + }, + events: '/api/schedule/events', + eventClick: function (info) { + console.log(info.event.id) + $.get("/api/schedule/full/events/" + info.event.id + "/modal?api_token="+authToken, function (data) { + $("#modal-content").html(data); + }); + $('#schedulemodal').modal('toggle') + }, + dateClick: function (info) { + var date = moment(info.date).format("YYYY-MM-DD"); + Swal.fire({ + title: 'Ajouter un evenement?', + text: "Voulez vous ajouter un evenement le "+date, + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Oui', + cancelButtonText: 'Non', + }).then((result) => { + if (result.value) { + window.location.href = '/admin/schedule/add/'+date; + } + }) + } + }); + + calendar.render(); + }); + +} \ No newline at end of file diff --git a/resources/views/admin/calendar/calendar_display.blade.php b/resources/views/admin/calendar/calendar_display.blade.php index 77af26b2..912f32ba 100644 --- a/resources/views/admin/calendar/calendar_display.blade.php +++ b/resources/views/admin/calendar/calendar_display.blade.php @@ -4,14 +4,7 @@