Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

New messaging class.

Copyright: 2015 onwards Ankit Agarwal
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 341 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: message  - X-Ref

New messaging class.

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. This is mandatory for NOTIFICACIONS and 1:1 personal messages.
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

Required parameters of the $eventdata object for PERSONAL MESSAGES:
convid int The conversation identifier where this message will be sent

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.
replyto string An email address which can be used to send an reply.
attachment stored_file File instance that needs to be sent as attachment.
attachname string Name of the attachment.
customdata mixed Custom data to be passed to the message processor. Must be serialisable using json_encode().

get_fullmessagehtml($processorname = '')   X-Ref
Fullmessagehtml content including any processor specific content.

param: string $processorname Name of the processor.
return: mixed|string

get_fullmessage($processorname = '')   X-Ref
Fullmessage content including any processor specific content.

param: string $processorname Name of the processor.
return: mixed|string

get_smallmessage($processorname = '')   X-Ref
Smallmessage content including any processor specific content.

param: string $processorname Name of the processor.
return: mixed|string

set_customdata($customdata)   X-Ref
Always JSON encode customdata.

param: mixed $customdata a data structure that must be serialisable using json_encode().

get_message_with_additional_content($processorname, $messagetype)   X-Ref
Helper method used to get message content added with processor specific content.

param: string $processorname Name of the processor.
param: string $messagetype one of 'fullmessagehtml', 'fullmessage', 'smallmessage'.
return: mixed|string

__get($prop)   X-Ref
Magic getter method.

param: string $prop name of property to get.
return: mixed

__set($prop, $value)   X-Ref
Magic setter method.

param: string $prop name of property to set.
param: mixed $value value to assign to the property.
return: mixed

__isset($prop)   X-Ref
Magic method to check if property is set.

param: string $prop name of property to check.
return: bool

set_additional_content($processorname, $content)   X-Ref
This method lets you define content that would be added to the message only for specific message processors.

Example of $content:-
array('fullmessagehtml' => array('header' => 'header content', 'footer' => 'footer content'),
'smallmessage' => array('header' => 'header content for small message', 'footer' => 'footer content'),
'*' => array('header' => 'header content for all types', 'footer' => 'footer content')
)

param: string $processorname name of the processor.
param: array $content content to add in the above defined format.

get_eventobject_for_processor($processorname)   X-Ref
Get a event object for a specific processor in stdClass format.

param: string $processorname Name of the processor.
return: \stdClass event object in stdClass format.