Skip to content

Commit

Permalink
Merge branch 'MDL-29548' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Oct 4, 2011
2 parents cdee9bd + 7529f9e commit 66f7705
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
35 changes: 30 additions & 5 deletions message/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)) {
Expand Down
9 changes: 9 additions & 0 deletions message/output/email/message_output_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions message/output/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down

0 comments on commit 66f7705

Please sign in to comment.