EDIT: Range is now structures correctly as an array and dates and times are now formatted as ISO8601. Unfortunately same error message on console with hasTime.
I am trying to make a school timetable using FullCalendar, loading each lesson from a database using php to encode to json.
I am trying to show each lesson recurring weekly on the timetable only within the dates of the semester (2016/09/26 - 2016/12/16) This range might be different for other lessons.
Below is the output of the EventListRecurring.php
[{
"id": "1",
"title": "History",
"start": "09:00",
"end": "10:00",
"dow": "1",
"ranges": [{
"start": "2016-09-26",
"end": "2016-12-16"
}],
"allDay": false
}, {
"id": "2",
"title": "English",
"start": "10:00",
"end": "12:00",
"dow": "2",
"ranges": [{
"start": "2016-09-26",
"end": "2016-12-16"
}],
"allDay": false
}, {
"id": "3",
"title": "Geography",
"start": "14:00",
"end": "16:00",
"dow": "3",
"ranges": [{
"start": "2016-09-26",
"end": "2016-12-16"
}],
"allDay": false
}]
I have tried using slicedtoads solution with the following javascript but there are no events on the calendar and getting only get this error
CalendarTimetableRecurring
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<link rel='stylesheet' href='fullcalendar/fullcalendar.min.css' />
<script src='fullcalendar/lib/jquery.min.js'></script>
<script src='fullcalendar/lib/moment.min.js'></script>
<script src='fullcalendar/fullcalendar.js'></script>
</head>
<body>
<h1>Reapeating Events Example </h1>
<div id='calendar'></div>
<script type="text/javascript">
var repeatingEvents =
'EventListRecurring.php'
var getEvents = function( start, end ){
return repeatingEvents;
}
$('#calendar').fullCalendar({
defaultDate: moment(),
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'month',
eventRender: function(event, element, view){
console.log(event.start.format());
return (event.ranges.filter(function(range){
return (event.start.isBefore(range.end) &&
event.end.isAfter(range.start));
}).length)>0;
},
events: function( start, end, timezone, callback ){
var events = getEvents(start,end);
callback(events);
},
});
</script>
</body>
</html>
EventListRecurring.php
<?php
$record[0]["title"]="History";
$record[1]["title"]="English";
$record[2]["title"]="Geography";
$record[0]["start_time"]="09:00";
$record[1]["start_time"]="10:00";
$record[2]["start_time"]="14:00";
$record[0]["end_time"]="10:00";
$record[1]["end_time"]="12:00";
$record[2]["end_time"]="16:00";
$record[0]["dow"]="1";
$record[1]["dow"]="2";
$record[2]["dow"]="3";
$record[0]["start_date"]="2016-09-26";
$record[1]["start_date"]="2016-09-26";
$record[2]["start_date"]="2016-09-26";
$record[0]["end_date"]="2016-12-16";
$record[1]["end_date"]="2016-12-16";
$record[2]["end_date"]="2016-12-16";
$record[0]["id"]="1";
$record[1]["id"]="2";
$record[2]["id"]="3";
for ($i=0; $i<3; $i++) {
$event_array[] = array(
'id' => $record[$i]['id'],
'title' => $record[$i]['title'],
'start' => $record[$i]['start_time'],
'end' => $record[$i]['end_time'],
'dow' => $record[$i]['dow'],
'ranges' => array(
0 => array(
'start' => $record[$i]['start_date'],
'end' => $record[$i]['end_date'],
)
),
'allDay' => false
);
}
echo json_encode($event_array);
exit;
?>