forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-27171 messages: add message outputs management interface page
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
Showing
8 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters