I am using jQuery FullCalendar as my calendar used in my website for availability agenda.
Is there any functions/methods/options in fullcalendar that handles my recurring events by Days? For example, Monday only to time 7:00AM to 9:00 AM, tuesdays - 4:00PM to 9:00PM, something like that?
At the moment I'm doing project where I have FullCalendar and I have to do Recurring events. So this is my why how it's can be done. Hope this code help someone:)
I have next table in database:
and I developed next php class to get events with repeat events:
function get_events get all events + recurring events in my way there are 4 type of recurring events: daily, weekly, monthly,yearly + there is repeat interval, repeat date end and repeat limit.
function get_repeat_events calculate difference for each type of event and include repeat event if exist.
note: function db_query() can be replace to myslq_query or something else
to prepare events to FullCalendar I'm using next code
No need to make parent and child relationship here is the code that provide simple solution for recurring events in jquery Full calender use these below functions in your php file that you use further to call all your events.
in the above code i used repeat_desk in which i store json code for repeat frequency
and jquery to call your file
i used this for wordpress you can use this code as per your requirement
Simple Repeating Events
To add a simple alternative to those listed here, Fullcalendar now (somewhat) supports weekly recurring events. So if you only need something like:
[Every Monday and Thursday from 10:00am to 02:00pm]
, you can use the following:JSFiddle
This is documented in Background events but it works for regular events as well.
Saving this to a database wouldn't be hard.
Add some restrictions
If you don't want them to repeat infinitely, you would need to add some start and end dates.
So, in the DB:
Pass this to the client as JSON:
And client side, use fullcalendar's eventRender to only render events when there are within one of the time ranges. Something like this should work:
That's assuming your events are structured as:
JSFiddle
Overnight
In case you want overnight repeating events (like here), just go over
24:00
for the end time. For instance:JSFiddle
This seemed to work quite nicely within the eventRender: function(event, element){}
1) Set a Start/End date & time in the JSON.
2) Create two custom recur Start and recur Ends in the JSON.
3) Use moment.js to create the recur durations: http://momentjs.com/docs/#/durations/.
4) Recur Start uses the (start:) date to pinpoint the start of the week.
5) Recur End uses (end:) date to pinpoint the end of the week + adding 1 week.
6) Adding 1, 2, 3 weeks can create the recur limit.
7) Adding another part of the JSON called (recurlimit:"") could manage the recur limit.
8) Using variables within the eventRender - set the date my example uses (theDate) which is moment(event.start). It's important to format this correctly so that the start/ end/ recurstart etc all match formats i.e (YYYY-MM-DD) http://momentjs.com/docs/#/displaying/format/.
9) Variable for the custom recurstart
10) Variable for the custom recurend
11) Use an IF statement to see weather the (theDate) falls between (recurstart) & (recurend) - log result
12) Use ELSE statement to return the length>0 to hide other events that don't fall within that parameter.
13) Non recurring events must have moment("match start date").startOf("month") & moment("match start date").endOf("month") otherwise they won't be visible.
Take a look at this site... http://fajitanachos.com/Fullcalendar-and-recurring-events/
It offers alot of good insite on recurring events. FullCalendar does support recurring events in respect to the id. You can handle the events either server side or client side, but the preference would be server side. I will give you some ideas, but its not all inclusive. As I have learned recurring events are a pain to maintain.
If you wanted to handle them client side, you would have to loop through the frequency of the repeating event and the logic of which days. You would probably need to use the eventRender callback, then render each looped event using the options callback. The problem with this will be that you still have to save the recurring frequency and a logical operator for your frequency option in your database...
...and then anytime you edited that event it would edit all of the events. If you needed delete just one event you would run into a series of issues within your logic and it could easily become a GIANT mess.
The second option was to do all this server side. Creating two tables, one with the parent event, and the second with all its recurrences. In the parent table you would store the general information, such as a unique id, color, background color, title, allDay, isRecurring, frequency, type etc. In the child table, you would use the unique id from the parent table to associate each recurrence (keep in mind if you want to delete/edit individual events the child table rows need to have their own unique id as well and a column that labels which table it is located). When you add a recurring event, you need to add a enum field that labels whether or not it is a recurring event or not AKA...
... and then you need to add each recurrence, into the child table with its specific information like start and end etc. When you query the event you could either query from the parent and then if the event is recurring get those events associated in a second query, or you could use an INNER JOIN on table1.id=table2.parentID in one single query.
As you can see, recurring event can get very detailed very fast, find out what logic you need and I hope this helps you or someone at least get started. Cheers.
There is now a plugin that will do what you want: http://momentjs.com/docs/#/plugins/recur/