Development:Messaging 2.0: Difference between revisions
Andrew Davis (talk | contribs) |
|||
| (18 intermediate revisions by 4 users not shown) | |||
| Line 9: | Line 9: | ||
==How to configure it== | ==How to configure it== | ||
Visit your own profile page (you need '''moodle/user:editownmessageprofile''' permission). | Visit your own profile page (you need '''moodle/user:editownmessageprofile''' permission). Note that the types of messages listed in the "Configure destinations for incoming messages" box is determined by the contents of the message_providers table. | ||
[[Image:Messagingconfig.png]] | |||
==How it works== | ==How it works== | ||
=== | ===Providers (input)=== | ||
We have | We have [[Development:Events|Events]] called "message_send" that look like this: | ||
<code php> | <code php> | ||
$eventdata = new object(); | $eventdata = new object(); | ||
$eventdata->component = ' | $eventdata->component = 'mod_forum'; // the component sending the message. Along with name this must exist in the table message_providers | ||
$eventdata->name = 'posts'; | $eventdata->name = 'posts'; // type of message from that module (as module defines it). Along with component this must exist in the table message_providers | ||
$eventdata->userfrom = $userfrom; // object | $eventdata->userfrom = $userfrom; // user object | ||
$eventdata->userto = $userto; // object | $eventdata->userto = $userto; // user object | ||
$eventdata->subject = $postsubject; | $eventdata->subject = $postsubject; // very short one-line subject | ||
$eventdata->fullmessage = $posttext; // raw text | $eventdata->fullmessage = $posttext; // raw text | ||
$eventdata->fullmessageformat = FORMAT_PLAIN; // text format | $eventdata->fullmessageformat = FORMAT_PLAIN; // text format | ||
| Line 31: | Line 33: | ||
</code> | </code> | ||
More | The name of each provider is a string with a name like messageprovider:$name from the component lang file (in this case, forum.php is derived automatically from mod/forum): | ||
<code php> | |||
$string['messageprovider:posts'] = 'Subscribed forum posts'; | |||
$string['messageprovider:digests'] = 'Subscribed forum digests'; | |||
</code> | |||
More providers can be added throughout Moodle as necessary, it's quite easy. See the [[Development:Events|Events API]] for info. | |||
=== | ===Processors (output)=== | ||
In [http://cvs.moodle.org/moodle/message/output /message/output] there are full Moodle plugins for each type of output. | In [http://cvs.moodle.org/moodle/message/output /message/output] there are full Moodle plugins for each type of output. | ||
| Line 39: | Line 48: | ||
Currently we have support for email, jabber and web-based popups. Could add twitter and SMS quite easily. | 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 [http://cvs.moodle.org/moodle/message/output/lib.php /message/output/lib.php] with methods for: | Each plugin simply extends a class called "message_output" in [http://cvs.moodle.org/moodle/message/output/lib.php /message/output/lib.php] with methods such as: | ||
<code php> | |||
function send_message($message) { | |||
// Given a message object and user info, this actually sends it. | |||
} | |||
function config_form($preferences) { | |||
// This defines the little form fragment on the config page | |||
} | |||
function process_form($form, &$preferences) { | |||
// This processes the data from the config form fragment | |||
} | |||
function load_data(&$preferences, $userid) { | |||
// This loads up prefs for this plugin | |||
} | |||
</code> | |||
It should also provide a messageprocessor_xxxxx.php language file (where xxxxx is the name) and inside is an xxxxx string with the name of the processor, like this: | |||
<code php> | |||
$string['jabber'] = 'Jabber message'; | |||
</code> | |||
Finally, there should be a '''lib.php file''' containing an install routine to install itself as a message processor: | |||
<code php> | |||
function jabber_install(){ | |||
global $DB; | |||
$result = true; | |||
$provider = new object(); | |||
$provider->name = 'jabber'; | |||
if (!$DB->insert_record('message_processors', $provider)) { | |||
$result = false; | |||
} | |||
return $result; | |||
} | |||
</code> | |||
And a '''version.php''' file: | |||
<code php> | |||
$plugin->version = 2008090900; | |||
$plugin->requires = 2008091500; | |||
</code> | |||
==See also== | ==See also== | ||
| Line 51: | Line 101: | ||
* [[GSOC/2008]] | * [[GSOC/2008]] | ||
* [[Student projects/Messaging improvements|Messaging improvements]], a GSOC 2007 project | * [[Student projects/Messaging improvements|Messaging improvements]], a GSOC 2007 project | ||
* [[Development:Events|Events API]] | |||
* MDL-10107 | * MDL-10107 | ||
[[Category: | [[Category:Messaging]] | ||
[[Category:Developer]] | |||
Latest revision as of 06:59, 9 November 2010
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). Note that the types of messages listed in the "Configure destinations for incoming messages" box is determined by the contents of the message_providers table.
How it works
Providers (input)
We have Events called "message_send" that look like this:
$eventdata = new object();
$eventdata->component = 'mod_forum'; // the component sending the message. Along with name this must exist in the table message_providers
$eventdata->name = 'posts'; // type of message from that module (as module defines it). Along with component this must exist in the table message_providers
$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);
The name of each provider is a string with a name like messageprovider:$name from the component lang file (in this case, forum.php is derived automatically from mod/forum):
$string['messageprovider:posts'] = 'Subscribed forum posts';
$string['messageprovider:digests'] = 'Subscribed forum digests';
More providers can be added throughout Moodle as necessary, it's quite easy. See the Events API for info.
Processors (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) {
// Given a message object and user info, this actually sends it.
}
function config_form($preferences) {
// This defines the little form fragment on the config page
}
function process_form($form, &$preferences) {
// This processes the data from the config form fragment
}
function load_data(&$preferences, $userid) {
// This loads up prefs for this plugin
}
It should also provide a messageprocessor_xxxxx.php language file (where xxxxx is the name) and inside is an xxxxx string with the name of the processor, like this:
$string['jabber'] = 'Jabber message';
Finally, there should be a lib.php file containing an install routine to install itself as a message processor:
function jabber_install(){
global $DB;
$result = true;
$provider = new object();
$provider->name = 'jabber';
if (!$DB->insert_record('message_processors', $provider)) {
$result = false;
}
return $result;
}
And a version.php file:
$plugin->version = 2008090900;
$plugin->requires = 2008091500;
See also
- GSOC/2008
- Messaging improvements, a GSOC 2007 project
- Events API
- MDL-10107
