Skip to content

Commit

Permalink
MDL-27171 messages: add message outputs management interface page
Browse files Browse the repository at this point in the history
This introduces the page for management message outputs (processors) where
admin may enable/disable them and jump to configuration pages.
  • Loading branch information
Ruslan Kabalin committed May 27, 2011
1 parent 21e6c82 commit 75c34c2
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 1 deletion.
56 changes: 56 additions & 0 deletions admin/message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* Message outputs configuration page
*
* @package message
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(dirname(dirname(__FILE__)) . '/message/lib.php');
require_once($CFG->libdir.'/adminlib.php');

// This is an admin page
admin_externalpage_setup('managemessageoutputs');

// Require site configuration capability
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

// Get the submitted params
$disable = optional_param('disable', 0, PARAM_INT);
$enable = optional_param('enable', 0, PARAM_INT);

if (!empty($disable) && confirm_sesskey()) {
if (!$processor = $DB->get_record('message_processors', array('id'=>$disable))) {
print_error('outputdoesnotexist', 'message');
}
$DB->set_field('message_processors', 'enabled', '0', array('id'=>$processor->id)); // Disable output
}

if (!empty($enable) && confirm_sesskey() ) {
if (!$processor = $DB->get_record('message_processors', array('id'=>$enable))) {
print_error('outputdoesnotexist', 'message');
}
$DB->set_field('message_processors', 'enabled', '1', array('id'=>$processor->id)); // Enable output
}

if ($disable || $enable) {
$url = new moodle_url('message.php');
redirect($url);
}
// Page settings
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));

// Grab the renderer
$renderer = $PAGE->get_renderer('core', 'message');

// Display the manage message outputs interface
$processors = get_message_processors();
$messageoutputs = $renderer->manage_messageoutputs($processors);

// Display the page
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('managemessageoutputs', 'message'));
echo $messageoutputs;
echo $OUTPUT->footer();
5 changes: 5 additions & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
}
}

// message outputs
$ADMIN->add('modules', new admin_category('messageoutputs', get_string('messageoutputs', 'message')));
$ADMIN->add('messageoutputs', new admin_page_managemessageoutputs());


// authentication plugins
$ADMIN->add('modules', new admin_category('authsettings', get_string('authentication', 'admin')));

Expand Down
7 changes: 7 additions & 0 deletions lang/en/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
$string['loggedoff'] = 'Not online';
$string['loggedoffdescription'] = 'When I\'m offline';
$string['managecontacts'] = 'Manage my contacts';
$string['managemessageoutputs'] = 'Manage message outputs';
$string['messageoutputs'] = 'Message outputs';
$string['mostrecent'] = 'Recent messages';
$string['mostrecentconversations'] = 'Recent conversations';
$string['mostrecentnotifications'] = 'Recent notifications';
Expand All @@ -90,6 +92,11 @@
$string['onlyfromme'] = 'Only messages from me';
$string['onlymycourses'] = 'Only in my courses';
$string['onlytome'] = 'Only messages to me';
$string['outputdisabled'] = 'Output disabled';
$string['outputdoesnotexist'] = 'Message output does not exists';
$string['outputenabled'] = 'Output enabled';
$string['outputnotavailable'] = 'Not available';
$string['outputnotconfigured'] = 'Not configured';
$string['pagerefreshes'] = 'This page refreshes automatically every {$a} seconds';
$string['private_config'] = 'Popup message window';
$string['processortag'] = 'Destination';
Expand Down
54 changes: 54 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4909,6 +4909,60 @@ public function search($query) {
}
}

/**
* Message outputs configuration
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_page_managemessageoutputs extends admin_externalpage {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
global $CFG;
parent::__construct('managemessageoutputs', get_string('managemessageoutputs', 'message'), "$CFG->wwwroot/$CFG->admin/message.php");
}

/**
* Search for a specific block
*
* @param string $query The string to search for
* @return array
*/
public function search($query) {
global $CFG, $DB;
if ($result = parent::search($query)) {
return $result;
}

$found = false;
if ($blocks = $DB->get_records('block')) {
$textlib = textlib_get_instance();
foreach ($blocks as $block) {
if (!file_exists("$CFG->dirroot/blocks/$block->name/")) {
continue;
}
if (strpos($block->name, $query) !== false) {
$found = true;
break;
}
$strblockname = get_string('pluginname', 'block_'.$block->name);
if (strpos($textlib->strtolower($strblockname), $query) !== false) {
$found = true;
break;
}
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
}

/**
* Question type manage page
Expand Down
11 changes: 11 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6112,6 +6112,17 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011052300.02);
}

if ($oldversion < 2011052500.01) {
// Add enabled filed to message_processors
$table = new xmldb_table('message_processors');
$field = new xmldb_field('enabled');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'name');

// Launch add field addition
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
}

return true;
}
Expand Down
31 changes: 31 additions & 0 deletions message/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2167,3 +2167,34 @@ function message_print_heading($title, $colspan=3) {
echo html_writer::tag('td', $title, array('colspan' => $colspan, 'class' => 'heading'));
echo html_writer::end_tag('tr');
}

/**
* Get all message processors and validate corresponding plugin existance and
* configuration
* @return array $processors array of objects containing information on message processors
*/
function get_message_processors() {
global $DB, $CFG;

$processors = $DB->get_records('message_processors', null, 'name');
foreach ($processors as &$processor){
$processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php';
if (is_readable($processorfile)) {
include_once($processorfile);
$processclass = 'message_output_' . $processor->name;
if (class_exists($processclass)) {
$pclass = new $processclass();
$processor->configured = 0;
if ($pclass->is_system_configured()) {
$processor->configured = 1;
}
$processor->available = 1;
} else {
print_error('errorcallingprocessor', 'message');
}
} else {
$processor->available = 0;
}
}
return $processors;
}
92 changes: 92 additions & 0 deletions message/renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/**
* Messaging libraries
*
* @package message
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* message Renderer
*
* Class for rendering various message objects
*
* @package message
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_renderer extends plugin_renderer_base {

/**
* Display the interface to manage message outputs
*
* @param array $processors The list of message processors
* @return string The text to render
*/
public function manage_messageoutputs($processors) {
// Display the current workflows
$table = new html_table();
$table->attributes['class'] = 'generaltable';
$table->head = array();
$table->colclasses = array();
$table->data = array();
$table->head = array(
get_string('name'),
get_string('enable'),
get_string('settings'),
);
$table->colclasses = array(
'displayname', 'availability', 'settings',
);

foreach ( $processors as $processor ){
$row = new html_table_row();
$row->attributes['class'] = 'workflow';

// Name
$name = new html_table_cell($processor->name);

// Enable
$enable = new html_table_cell();
if (!$processor->available) {
$enable->text = html_writer::nonempty_tag('span', get_string('outputnotavailable', 'message'), array('class' => 'error'));
} else if (!$processor->configured) {
$enable->text = html_writer::nonempty_tag('span', get_string('outputnotconfigured', 'message'), array('class' => 'error'));
} else if ($processor->enabled) {
$row->attributes['class'] .= 'enabled';
$url = new moodle_url('/admin/message.php', array('disable' => $processor->id, 'sesskey' => sesskey()));
$enable->text = html_writer::link($url, html_writer::empty_tag('img',
array('src' => $this->output->pix_url('i/hide'),
'class' => 'icon',
'title' => get_string('outputenabled', 'message'),
'alt' => get_string('outputenabled', 'message'),
)
));
} else {
$row->attributes['class'] .= 'disabled';
$url = new moodle_url('/admin/message.php', array('enable' => $processor->id, 'sesskey' => sesskey()));
$enable->text = html_writer::link($url, html_writer::empty_tag('img',
array('src' => $this->output->pix_url('i/show'),
'class' => 'icon',
'title' => get_string('outputdisabled', 'message'),
'alt' => get_string('outputdisabled', 'message'),
)
));
}

$settings = new html_table_cell();
if ($processor->available) {
$settingsurl = new moodle_url('/message/output/'.$processor->name.'/settings.php');
$settings->text = html_writer::link($settingsurl, get_string('settings', 'message'));
}

$row->cells = array($name, $enable, $settings);
$table->data[] = $row;
}
return html_writer::table($table);
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();


$version = 2011052500.00; // YYYYMMDD = weekly release date of this DEV branch
$version = 2011052500.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

Expand Down

0 comments on commit 75c34c2

Please sign in to comment.