Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Messaging 2.0.

Development:Messaging 2.0

From MoodleDocs

The messaging system in 2.0 has been revamped significantly. It is now event-driven, and allows users to control exactly what messages they receive and how.


How to enable it

Admin > Optional subsystems > Enable messaging system = Yes


How to configure it

Visit your own profile page (you need moodle/user:editownmessageprofile permission).

Messagingconfig.png

How it works

Input

We have events called "message_send" that look like this:

$eventdata = new object(); $eventdata->component = 'mod/forum'; // path in Moodle $eventdata->name = 'posts'; // type of message from that module (as module defines it) $eventdata->userfrom = $userfrom; // user object $eventdata->userto = $userto; // user object $eventdata->subject = $postsubject; // very short one-line subject $eventdata->fullmessage = $posttext; // raw text $eventdata->fullmessageformat = FORMAT_PLAIN; // text format $eventdata->fullmessagehtml = $posthtml; // html rendered version $eventdata->smallmessage = ; // useful for plugins like sms or twitter

events_trigger('message_send', $eventdata);

More of these can be added throughout Moodle as necessary, it's quite easy.

Output

In /message/output there are full Moodle plugins for each type of output.

Currently we have support for email, jabber and web-based popups. Could add twitter and SMS quite easily.

Each plugin simply extends a class called "message_output" in /message/output/lib.php with methods such as:

function send_message($message) { }

function config_form($preferences) { }

function process_form($form, &$preferences) { }

function load_data(&$preferences, $userid) { }

See also