From 7529f9e94421ad5572a7023aca6609aa353b76b4 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 27 Sep 2011 18:05:38 +0100 Subject: [PATCH] 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. --- message/lib.php | 35 ++++++++++++++++--- message/output/email/message_output_email.php | 9 +++++ message/output/lib.php | 8 +++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/message/lib.php b/message/lib.php index eae88ae4be18b..7ad36cf9fe75d 100644 --- a/message/lib.php +++ b/message/lib.php @@ -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)) { diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index 7f27f62614d42..5e56f1b4b051a 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -88,6 +88,15 @@ function process_form($form, &$preferences){ } } + /** + * @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 diff --git a/message/output/lib.php b/message/output/lib.php index f669c50d0f597..7d7aa3a6c08be 100644 --- a/message/output/lib.php +++ b/message/output/lib.php @@ -55,6 +55,14 @@ public function is_user_configured($user = null) { 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; + } }