MDL-29548 allow message plugins to control message
defaults. At the moment, each message_provider can specify defaults for each message output, to say whether that message output should be used for this type of message: http://docs.moodle.org/dev/Messaging_2.0#Adding_new_message_type. If the message provider does not set a default, this change allows the message output to set the default.
This commit is contained in:
+30
-5
@@ -2308,6 +2308,34 @@ function get_message_processors($ready = false) {
|
||||
return $processors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of the message_output class for one of the output plugins.
|
||||
* @param string $type the message output type. E.g. 'email' or 'jabber'.
|
||||
* @return message_output message_output the requested class.
|
||||
*/
|
||||
function get_message_processor($type) {
|
||||
global $CFG;
|
||||
|
||||
// Note, we cannot use the get_message_processors function here, becaues this
|
||||
// code is called during install after installing each messaging plugin, and
|
||||
// get_message_processors caches the list of installed plugins.
|
||||
|
||||
$processorfile = $CFG->dirroot . "/message/output/{$type}/message_output_{$type}.php";
|
||||
if (!is_readable($processorfile)) {
|
||||
throw new coding_exception('Unknown message processor type ' . $type);
|
||||
}
|
||||
|
||||
include_once($processorfile);
|
||||
|
||||
$processclass = 'message_output_' . $type;
|
||||
if (!class_exists($processclass)) {
|
||||
throw new coding_exception('Message processor ' . $type .
|
||||
' does not define the right class');
|
||||
}
|
||||
|
||||
return new $processclass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get messaging outputs default (site) preferences
|
||||
*
|
||||
@@ -2345,11 +2373,8 @@ function translate_message_default_setting($plugindefault, $processorname) {
|
||||
);
|
||||
|
||||
// define the default setting
|
||||
if ($processorname == 'email') {
|
||||
$default = MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF;
|
||||
} else {
|
||||
$default = MESSAGE_PERMITTED;
|
||||
}
|
||||
$processor = get_message_processor($processorname);
|
||||
$default = $processor->get_default_messaging_settings();
|
||||
|
||||
// Validate the value. It should not exceed the maximum size
|
||||
if (!is_int($plugindefault) || ($plugindefault > 0x0f)) {
|
||||
|
||||
@@ -88,6 +88,15 @@ class message_output_email extends message_output {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the Default message output settings for this output, for
|
||||
* message providers that do not specify what the settings should be for
|
||||
* this output in the messages.php file.
|
||||
*/
|
||||
public function get_default_messaging_settings() {
|
||||
return MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config data from database to put on the form (initial load)
|
||||
* @param array $preferences preferences array
|
||||
|
||||
@@ -55,6 +55,14 @@ abstract class message_output {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the Default message output settings for this output, for
|
||||
* message providers that do not specify what the settings should be for
|
||||
* this output in the messages.php file.
|
||||
*/
|
||||
public function get_default_messaging_settings() {
|
||||
return MESSAGE_PERMITTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user