Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Calendar API: Difference between revisions

From MoodleDocs
Line 14: Line 14:
==The calendar_event class==
==The calendar_event class==


All management of events that you might need to do can be done by the '''calendar_event()''' class.
In general functionality of calendar_event() class are to create, update and delete events.


(Rossi, describe this class and the methods available here - don't duplicate phpdocs but talk about the things that are possible in generalTry grouping all the functions into "clumps" that make sense)
===Creating new event===
Creating new calendar event to database by defining some properties for the event.
<code>
calendar_event::create($properties)
</code>
 
===Updating event===
Updating an existing event in database by providing at least an event id.  If the event is a repeated events, the rest of series event will also be updated (depending on the properties value of repeateditall).  This function could also be use to insert new event to database If the requested event is not exist in database.  The optional parameter $checkcapability is use to check user's capability to edit/add event.  By default $checkcapability parameter is set to true. 
<code>
calendar_event::update($data, $checkcapability=true)
</code>
 
===Deleting event===
Deleting an existing event in database.  The optional parameter $deleterepeated is use as indicator to remove the rest of repeated eventsThe default value for $deleterepeated is true. Deleting an event will also deleting all associated files related to the event's editor context.
<code>
calendar_event::delete($deleterepeated=false)
</code>


==Examples==
==Examples==

Revision as of 06:57, 16 January 2012

The Calendar API allows you to add and modify events in the calendar for user, groups, courses, or the whole site.

Overview

The Moodle Calendar collects and displays calendar events from everything users have access to.

If your plugin generates calendar events (such as due dates) then you need to add your events to the calendar.

File locations

All the calendar code is located in /calendar/lib.php. You need to include this file in your script if you intend to use it.


The calendar_event class

In general functionality of calendar_event() class are to create, update and delete events.

Creating new event

Creating new calendar event to database by defining some properties for the event. calendar_event::create($properties)

Updating event

Updating an existing event in database by providing at least an event id. If the event is a repeated events, the rest of series event will also be updated (depending on the properties value of repeateditall). This function could also be use to insert new event to database If the requested event is not exist in database. The optional parameter $checkcapability is use to check user's capability to edit/add event. By default $checkcapability parameter is set to true. calendar_event::update($data, $checkcapability=true)

Deleting event

Deleting an existing event in database. The optional parameter $deleterepeated is use as indicator to remove the rest of repeated events. The default value for $deleterepeated is true. Deleting an event will also deleting all associated files related to the event's editor context. calendar_event::delete($deleterepeated=false)

Examples

Adding an event to the calendar


Dealing with files


etc

See also