Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
calendar_event Class Reference

Public Member Functions

 __construct ($data=null)
 Instantiates a new event and optionally populates its properties with the data provided.
 
 __get ($key)
 Magic get method.
 
 __isset ($key)
 Magic isset method.
 
 __set ($key, $value)
 Magic set method.
 
 count_repeats ()
 Return the number of repeat events there are in this events series.
 
 delete ($deleterepeated=false)
 Deletes an event and if selected an repeated events in the same series.
 
 format_external_name ()
 Format the event name using the external API.
 
 format_external_text ()
 Format the text using the external API.
 
 properties ($prepareeditor=false)
 Fetch all event properties.
 
 toggle_visibility ($force=null)
 Toggles the visibility of an event.
 
 update ($data, $checkcapability=true)
 Update or create an event within the database.
 

Static Public Member Functions

static create ($properties, $checkcapability=true)
 Creates a new event and returns an event object.
 
static load ($param)
 Returns an event object when provided with an event id.
 

Protected Member Functions

 calculate_context ()
 Calculate the context value needed for an event.
 
 get_context ()
 Returns the context for this event.
 
 get_description ()
 Returns an event description: Called by __get Please use $blah = $event->description;.
 
 get_editoroptions ()
 Returns an array of editoroptions for this event.
 

Protected Attributes

string $_description = null
 The converted event discription with file paths resolved.
 
object $editorcontext = null
 The context to use with the description editor.
 
array $editoroptions
 The options to use with this description editor.
 
stdClass $properties = null
 An object containing the event properties can be accessed via the magic __get/set methods.
 

Constructor & Destructor Documentation

◆ __construct()

calendar_event::__construct ( $data = null)

Instantiates a new event and optionally populates its properties with the data provided.

Parameters
stdClass$dataOptional. An object containing the properties to for an event

Member Function Documentation

◆ __get()

calendar_event::__get ( $key)

Magic get method.

Attempts to call a get_$key method to return the property and ralls over to return the raw property.

Parameters
string$keyproperty name
Return values
mixedproperty value
Exceptions
coding_exception

◆ __isset()

calendar_event::__isset ( $key)

Magic isset method.

PHP needs an isset magic method if you use the get magic method and still want empty calls to work.

Parameters
string$key$key property name
Return values
bool|mixedproperty value, false if property is not exist

◆ __set()

calendar_event::__set ( $key,
$value )

Magic set method.

Attempts to call a set_$key method if one exists otherwise falls back to simply set the property.

Parameters
string$keyproperty name
mixed$valuevalue of the property

◆ calculate_context()

calendar_event::calculate_context ( )
protected

Calculate the context value needed for an event.

Event's type can be determine by the available value store in $data It is important to check for the existence of course/courseid to determine the course event. Default value is set to CONTEXT_USER

Return values
stdClassThe context object.

◆ count_repeats()

calendar_event::count_repeats ( )

Return the number of repeat events there are in this events series.

Return values
intnumber of event repeated

◆ create()

static calendar_event::create ( $properties,
$checkcapability = true )
static

Creates a new event and returns an event object.

Capability checking should be performed if the user is directly creating the event and no other capability has been tested. However if the event is not being created directly by the user and another capability has been checked for them to do this then capabilites should not be checked.

For example if a user is creating an event in the calendar the check should be true, but if you are creating an event in an activity when it is created then the calendar capabilites should not be checked.

Parameters
stdClass | array$propertiesAn object containing event properties
bool$checkcapabilityIf Moodle should check the user can manage the calendar events for this call or not.
Exceptions
coding_exception
Return values
calendar_event|boolThe event object or false if it failed

◆ delete()

calendar_event::delete ( $deleterepeated = false)

Deletes an event and if selected an repeated events in the same series.

This function deletes an event, any associated events if $deleterepeated=true, and cleans up any files associated with the events.

See also
self\delete()
Parameters
bool$deleterepeateddelete event repeatedly
Return values
boolsuccession of deleting event

◆ format_external_name()

calendar_event::format_external_name ( )

Format the event name using the external API.

This function should we used when text formatting is required in external functions.

Return values
stringFormatted name.

◆ format_external_text()

calendar_event::format_external_text ( )

Format the text using the external API.

This function should we used when text formatting is required in external functions.

Return values
arrayan array containing the text formatted and the text format

◆ get_context()

calendar_event::get_context ( )
protected

Returns the context for this event.

The context is calculated the first time is is requested and then stored in a member variable to be returned each subsequent time.

This is a magical getter function that will be called when ever the context property is accessed, e.g. $event->context.

Return values
context

◆ get_description()

calendar_event::get_description ( )
protected

Returns an event description: Called by __get Please use $blah = $event->description;.

Return values
stringevent description

◆ get_editoroptions()

calendar_event::get_editoroptions ( )
protected

Returns an array of editoroptions for this event.

Return values
arrayevent editor options

◆ load()

static calendar_event::load ( $param)
static

Returns an event object when provided with an event id.

This function makes use of MUST_EXIST, if the event id passed in is invalid it will result in an exception being thrown.

Parameters
int | object$paramevent object or event id
Return values
calendar_event

◆ properties()

calendar_event::properties ( $prepareeditor = false)

Fetch all event properties.

This function returns all of the events properties as an object and optionally can prepare an editor for the description field at the same time. This is designed to work when the properties are going to be used to set the default values of a moodle forms form.

Parameters
bool$prepareeditorIf set to true a editor is prepared for use with the mforms editor element. (for description)
Return values
stdClassObject containing event properties

◆ toggle_visibility()

calendar_event::toggle_visibility ( $force = null)

Toggles the visibility of an event.

Parameters
null | bool$forceIf it is left null the events visibility is flipped, If it is false the event is made hidden, if it is true it is made visible.
Return values
boolif event is successfully updated, toggle will be visible

◆ update()

calendar_event::update ( $data,
$checkcapability = true )

Update or create an event within the database.

Pass in a object containing the event properties and this function will insert it into the database and deal with any associated files

Capability checking should be performed if the user is directly manipulating the event and no other capability has been tested. However if the event is not being manipulated directly by the user and another capability has been checked for them to do this then capabilites should not be checked.

For example if a user is editing an event in the calendar the check should be true, but if you are updating an event in an activities settings are changed then the calendar capabilites should not be checked.

See also
self\create()
self\update()
Parameters
stdClass$dataobject of event
bool$checkcapabilityIf Moodle should check the user can manage the calendar events for this call or not.
Return values
boolevent updated

Member Data Documentation

◆ $_description

string calendar_event::$_description = null
protected

The converted event discription with file paths resolved.

This gets populated when someone requests description for the first time

◆ $editoroptions

array calendar_event::$editoroptions
protected
Initial value:
= array(
'subdirs' => false,
'forcehttps' => false,
'maxfiles' => -1,
'maxbytes' => null,
'trusttext' => false)

The options to use with this description editor.


The documentation for this class was generated from the following file: