Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/lib/ -> messagelib.php (source)

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

Functions for interacting with the message system

Copyright: 2008 Luis Rodrigues and Martin Dougiamas
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 758 lines (34 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 1 file
 message/lib.php

Defines 10 functions


Functions that are not part of a class:

message_send(\core\message\message $eventdata)   X-Ref
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 is is not reported as false return value,
earlier versions did not do it consistently either.

param: \core\message\message $eventdata information about the message (component, userfrom, userto, ...)
return: mixed the integer ID of the new message or false if there was a problem with submitted data

message_handle_phpunit_redirection(\core\message\message $eventdata, string $table, \stdClass $tabledata)   X-Ref
Helper method containing the PHPUnit specific code, used to redirect and capture messages/notifications.

param: \core\message\message $eventdata the message object
param: string $table the table to store the tabledata in, either messages or notifications.
param: stdClass $tabledata the data to be stored when creating the message/notification.
return: int the id of the stored message.

message_update_providers($component='moodle')   X-Ref
Updates the message_providers table with the current set of message providers

param: string $component For example 'moodle', 'mod_forum' or 'block_quiz_results'
return: boolean True on success

message_update_processors($processorname)   X-Ref
This function populates default message preferences for all existing providers
when the new message processor is added.

param: string $processorname The name of message processor plugin (e.g. 'email', 'jabber')

message_set_default_message_preference($component, $messagename, $fileprovider, $processorname='')   X-Ref
Setting default messaging preferences for particular message provider

param: string $component   The name of component (e.g. moodle, mod_forum, etc.)
param: string $messagename The name of message provider
param: array  $fileprovider The value of $messagename key in the array defined in plugin messages.php
param: string $processorname The optional name of message processor

message_get_providers_for_user($userid)   X-Ref
Returns the active providers for the user specified, based on capability

param: int $userid id of user
return: array An array of message providers

message_get_providers_from_db($component)   X-Ref
Gets the message providers that are in the database for this component.

This is an internal function used within messagelib.php

param: string $component A moodle component like 'moodle', 'mod_forum', 'block_quiz_results'
return: array An array of message providers

message_get_providers_from_file($component)   X-Ref
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

param: string $component A moodle component like 'moodle', 'mod_forum', 'block_quiz_results'
return: array An array of message providers or empty array if not exists

message_provider_uninstall($component)   X-Ref
Remove all message providers for particular component and corresponding settings

param: string $component A moodle component like 'moodle', 'mod_forum', 'block_quiz_results'
return: void

message_processor_uninstall($name)   X-Ref
Uninstall a message processor

param: string $name A message processor name like 'email', 'jabber'