New Model for Event,Booking and Course

This commit is contained in:
Mathieu Lagace
2019-08-17 11:43:52 -04:00
parent b850b38b85
commit d4b3b1b47d
20 changed files with 629 additions and 61 deletions

18
app/Booking.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Booking extends Model
{
public function bookable()
{
return $this->morphTo();
}
public function user()
{
return $this->belongsTo('App\User');
}
}

23
app/Course.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Course extends Model
{
public function bookings()
{
return $this->morphMany('App\Booking', 'bookable');
}
public function user()
{
return $this->belongsTo('App\User');
}
public function event()
{
return $this->belongsTo('App\Event');
}
}

23
app/Event.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
public function bookings()
{
return $this->morphMany('App\Booking', 'bookable');
}
public function courses()
{
return $this->hasMany('App\Course');
}
public function user()
{
return $this->belongsTo('App\User');
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Http\Controllers;
use App\Booking;
use Illuminate\Http\Request;
class BookingController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function show(Booking $booking)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function edit(Booking $booking)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Booking $booking)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function destroy(Booking $booking)
{
//
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Http\Controllers;
use App\Course;
use Illuminate\Http\Request;
class CourseController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Course $course
* @return \Illuminate\Http\Response
*/
public function show(Course $course)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Course $course
* @return \Illuminate\Http\Response
*/
public function edit(Course $course)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Course $course
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Course $course)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Course $course
* @return \Illuminate\Http\Response
*/
public function destroy(Course $course)
{
//
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Http\Controllers;
use App\Event;
use Illuminate\Http\Request;
class EventController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Event $event
* @return \Illuminate\Http\Response
*/
public function show(Event $event)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Event $event
* @return \Illuminate\Http\Response
*/
public function edit(Event $event)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Event $event
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Event $event)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Event $event
* @return \Illuminate\Http\Response
*/
public function destroy(Event $event)
{
//
}
}

View File

@@ -57,56 +57,34 @@ class ScheduleController extends Controller
public function apiIndex()
{
$schedules = Schedule::all();
$activity = \App\ComplementaryActivity::all();
$start = substr(request()->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;
}
}

View File

@@ -17,4 +17,9 @@ class Item extends Model
$col_items->forget(0);
return $col_items;
}
public function bookings()
{
return $this->hasMany('App\Booking');
}
}

View File

@@ -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;

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -0,0 +1,39 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCoursesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('courses', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBookingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->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');
}
}

41
public/js/calendar.js vendored Normal file
View File

@@ -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();
});
}

View File

@@ -4,14 +4,7 @@
<div class="col-sm-12 col-lg-12">
<div class="card">
<div class="card-body pb-0">
<div class="dropdown float-right">
<button class="btn bg-transparent dropdown-toggle theme-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown">
<i class="fa fa-cog"></i>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
</div>
</div>
<div class="calendar"></div>
<div id="fullCalendar"></div>
</div>
</div>
</div>
@@ -61,8 +54,14 @@
@endsection
@section('custom_scripts')
<div class="log"></div>
<script src='/assets/fullcalendar/core/main.js'></script>
<script src='/assets/fullcalendar/daygrid/main.js'></script>
<script src='/assets/fullcalendar/interaction/main.js'></script>
<script src="/js/calendar.js"></script>
<div class="log"></div>
<script>
initFullCalendar(api_token)
function deleteEvent(pid){
swal({
title: 'Êtes vous certain ?',
@@ -97,4 +96,10 @@
})
}
</script>
<div class="modal fade" id="schedulemodal" tabindex="-1" role="dialog" aria-labelledby="schedulemodal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" id="modal-content">
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,5 @@
@extends('layouts.modal.schedule.show')
@section('content')
Test
@endsection

View File

@@ -20,5 +20,9 @@
<!-- Material Dashboard CSS -->
<link href="/css/material-dashboard.css" rel="stylesheet">
<!-- Plugin CSS -->
<link href='/assets/fullcalendar/core/main.css' rel='stylesheet' />
<link href='/assets/fullcalendar/daygrid/main.css' rel='stylesheet' />
<!-- Custom CSS -->
<link rel="stylesheet" href="/css/custom.css">

View File

@@ -13,8 +13,6 @@
<script src="/js/plugins/bootstrap-datetimepicker.min.js"></script>
<!-- DataTables.net Plugin, full documentation here: https://datatables.net/ -->
<script src="/js/plugins/jquery.dataTables.min.js"></script>
<!-- Full Calendar Plugin, full documentation here: https://github.com/fullcalendar/fullcalendar -->
<script src="/js/plugins/fullcalendar.min.js"></script>
<!-- Plugin for the Sliders, full documentation here: http://refreshless.com/nouislider/ -->
<script src="/js/plugins/nouislider.min.js" ></script>
<!-- Include a polyfill for ES6 Promises (optional) for IE11, UC Browser and Android browser support SweetAlert -->

View File

@@ -0,0 +1,14 @@
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{{$event->data['event_name']}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
@yield('content')
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>

View File

@@ -26,6 +26,8 @@ Route::middleware('auth:api')->group(function () {
Route::post('/calendar/loadDay', 'CalendarController@show');
Route::post('/calendar/delete', 'CalendarController@delete');
Route::get('/schedule/full/events/{id}/modal','ScheduleController@loadModalFull');
/** Message Route */
Route::post('/message/delete', 'MessageController@destroy');

View File

@@ -36,7 +36,7 @@ Route::middleware(['auth','admin'])->group(function () {
/** Calendar */
Route::get('/admin/calendar', 'CalendarController@index');
Route::get('/admin/calendar/add/{type}/{date}', ['uses' =>'CalendarController@add']);
Route::get('/admin/calendar/add/{date}', ['uses' =>'CalendarController@add']);
Route::get('/admin/calendar/edit/{id}', ['uses' =>'CalendarController@edit']);
Route::post('/admin/calendar/add', 'CalendarController@store');
Route::patch('/admin/calendar/edit/{id}', ['uses' =>'CalendarController@patch']);