Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)

Functions

 message_get_providers_for_user ($userid)
 Returns the active providers for the user specified, based on capability.
 
 message_get_providers_from_db ($component)
 Gets the message providers that are in the database for this component.
 
 message_get_providers_from_file ($component)
 Loads the messages definitions for a component from file.
 
 message_handle_phpunit_redirection (\core\message\message $eventdata, string $table, stdClass $tabledata)
 Helper method containing the PHPUnit specific code, used to redirect and capture messages/notifications.
 
 message_processor_uninstall ($name)
 Uninstall a message processor.
 
 message_provider_uninstall ($component)
 Remove all message providers for particular component and corresponding settings.
 
 message_send (\core\message\message $eventdata)
 Called when a message provider wants to send a message.
 
 message_set_default_message_preference ($component, $messagename, $fileprovider, $processorname='')
 Setting default messaging preferences for particular message provider.
 
 message_update_processors ($processorname)
 This function populates default message preferences for all existing providers when the new message processor is added.
 
 message_update_providers ($component='moodle')
 Updates the message_providers table with the current set of message providers.
 

Detailed Description

Function Documentation

◆ message_get_providers_for_user()

message_get_providers_for_user ( $userid)

Returns the active providers for the user specified, based on capability.

Parameters
int$useridid of user
Return values
arrayAn array of message providers

◆ message_get_providers_from_db()

message_get_providers_from_db ( $component)

Gets the message providers that are in the database for this component.

This is an internal function used within messagelib.php

See also
message_update_providers()
Parameters
string$componentA moodle component like 'moodle', 'mod_forum', 'block_activity_results'
Return values
arrayAn array of message providers

◆ message_get_providers_from_file()

message_get_providers_from_file ( $component)

Loads the messages definitions for a component from file.

If no messages are defined for the component, return an empty array. This is an internal function used within messagelib.php

See also
message_update_providers()
message_update_processors()
Parameters
string$componentA moodle component like 'moodle', 'mod_forum', 'block_activity_results'
Return values
arrayAn array of message providers or empty array if not exists

◆ message_handle_phpunit_redirection()

message_handle_phpunit_redirection ( \core\message\message $eventdata,
string $table,
stdClass $tabledata )

Helper method containing the PHPUnit specific code, used to redirect and capture messages/notifications.

Parameters
core\message\message$eventdatathe message object
string$tablethe table to store the tabledata in, either messages or notifications.
stdClass$tabledatathe data to be stored when creating the message/notification.
Return values
intthe id of the stored message.

◆ message_processor_uninstall()

message_processor_uninstall ( $name)

Uninstall a message processor.

Parameters
string$nameA message processor name like 'email', 'jabber'

◆ message_provider_uninstall()

message_provider_uninstall ( $component)

Remove all message providers for particular component and corresponding settings.

Parameters
string$componentA moodle component like 'moodle', 'mod_forum', 'block_activity_results'
Return values
void

◆ message_send()

message_send ( \core\message\message $eventdata)

Called when a message provider wants to send a message.

This functions checks the message recipient's message processor configuration then sends the message to the configured processors

Required parameters of the $eventdata object: component string component name. must exist in message_providers name string message type name. must exist in message_providers userfrom object|int the user sending the message userto object|int the message recipient subject string the message subject fullmessage string the full message in a given format fullmessageformat int the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..) fullmessagehtml string the full version (the message processor will choose with one to use) smallmessage string the small version of the message

Optional parameters of the $eventdata object: notification bool should the message be considered as a notification rather than a personal message contexturl string if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of. contexturlname string the display text for contexturl

Note: processor failure will not reported as false return value in all scenarios, for example when it is called while a database transaction is open, earlier versions did not do it consistently either.

Parameters
core\message\message$eventdatainformation about the message (component, userfrom, userto, ...)
Return values
mixedthe integer ID of the new message or false if there was a problem (with submitted data or sending the message to the message processor)

◆ message_set_default_message_preference()

message_set_default_message_preference ( $component,
$messagename,
$fileprovider,
$processorname = '' )

Setting default messaging preferences for particular message provider.

Parameters
string$componentThe name of component (e.g. moodle, mod_forum, etc.)
string$messagenameThe name of message provider
array$fileproviderThe value of $messagename key in the array defined in plugin messages.php
string$processornameThe optional name of message processor

◆ message_update_processors()

message_update_processors ( $processorname)

This function populates default message preferences for all existing providers when the new message processor is added.

Parameters
string$processornameThe name of message processor plugin (e.g. 'email', 'jabber')
Exceptions
invalid_parameter_exceptionif $processorname does not exist in the database

◆ message_update_providers()

message_update_providers ( $component = 'moodle')

Updates the message_providers table with the current set of message providers.

Parameters
string$componentFor example 'moodle', 'mod_forum' or 'block_activity_results'
Return values
booleanTrue on success