I am using the jQuery library Fullcalendar to display events for sports teams from a MYSQL database. I have managed to properly setup a JSON feed which displays all the events in the database.
However, a coach can administrate up to three teams, and each of these teams have their own page with its own calendar. Currently, all events are listed in all calendars. I need some sort of filter to make sure that only events belonging to the right team is displayed in each calendar.
I have given each team a unique URL based on their ID, like this.
http://localhost/master/index.php/team/56
The JSON feed currently outputs this:
{"id":"14","event_id":"8","team":"56","start":"2013-12-16 18:00:00","title":"Mandagsgym","description":"Ivar er trenar","location":"Haukelandshallen","start_time":"18:00:00","end_time":"20:00:00"}
My current jQuery:
var filter_id = $('#filter_id').val(); //a variable with the team ID,
fetched from a hidden input field
$('#calendar').fullCalendar({
firstDay:'1',
defaultView: 'basicWeek',
height: 400,
editable: true,
weekends: false,
header:
{
left: '',
center: '',
right: 'prev,next, month,basicWeek'
},
columnFormat: 'ddd d/M',
allDayDefault: false,
events:
{
url: 'http://localhost/master/index.php/team/json'
}
});
As I see it, I have two options: 1) Find a way to assign the third segment of the URL (the team ID) to the JSON feed PHP function, hence providing the calendars with dynamic JSON feeds.
2) Fetch the team ID from the URL, assign it to a Javascript variable and then do some filtering using the Fullcalendar methods, removing or at least hiding the events from the calendar where the team ID does not match the team ID in the URL.
Both of these proposed approaches are well beyond my relatively limited knowledge. I personally fancy approach nr.2. I would be absolutely delighted if anyone could come up with a solution, as I've been stuck on this problem for days.