Merge branch 'MDL-47810_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Dan Poltawski 2014-11-03 15:03:51 +00:00
commit 971163afaa
2 changed files with 36 additions and 17 deletions

View File

@ -165,13 +165,19 @@ class rules extends \table_sql implements \renderable {
public function col_select(\tool_monitor\rule $rule) {
global $OUTPUT;
$select = $rule->get_module_select($this->courseid);
$options = $rule->get_subscribe_options($this->courseid);
$text = get_string('subscribeto', 'tool_monitor', $rule->get_name($this->context));
if ($select instanceof \single_select) {
$select->set_label(get_string('subscribeto', 'tool_monitor', $rule->get_name($this->context)), array('class' => 'accesshide'));
return $OUTPUT->render($select);
if ($options instanceof \single_select) {
$options->set_label($text, array('class' => 'accesshide'));
return $OUTPUT->render($options);
} else if ($options instanceof \moodle_url) {
// A \moodle_url to subscribe.
$icon = $OUTPUT->pix_icon('t/add', $text);
$link = new \action_link($options, $icon);
return $OUTPUT->render($link);
} else {
return $select;
return $options;
}
}

View File

@ -86,26 +86,40 @@ class rule {
}
/**
* Generate a select drop down with list of possible modules for a given course and rule.
* Gets the rule subscribe options for a given course and rule.
*
* Could be a select drop down with a list of possible module
* instances or a single link to subscribe if the rule plugin
* is not a module.
*
* @param int $courseid course id
*
* @return \single_select a single select object
* @return \single_select|\moodle_url|string
* @throws \coding_exception
*/
public function get_module_select($courseid) {
public function get_subscribe_options($courseid) {
global $CFG;
$options = array();
if (strpos($this->plugin, 'mod_') === 0) {
$options[0] = get_string('allmodules', 'tool_monitor');
$url = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array(
'courseid' => $courseid,
'ruleid' => $this->id,
'action' => 'subscribe',
'sesskey' => sesskey()
));
if (strpos($this->plugin, 'mod_') !== 0) {
return $url;
} else {
$options[0] = get_string('allevents', 'tool_monitor');
}
if (strpos($this->plugin, 'mod_') === 0) {
// Single select when the plugin is an activity.
$options = array();
$options[0] = get_string('allmodules', 'tool_monitor');
if ($courseid == 0) {
// They need to be in a course to select module instance.
return get_string('selectcourse', 'tool_monitor');
}
// Let them select an instance.
$cms = get_fast_modinfo($courseid);
$instances = $cms->get_instances_of(str_replace('mod_', '', $this->plugin));
@ -115,10 +129,9 @@ class rule {
$options[$cminfo->id] = $cminfo->get_formatted_name();
}
}
return new \single_select($url, 'cmid', $options);
}
$url = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array('courseid' => $courseid, 'ruleid' => $this->id,
'action' => 'subscribe', 'sesskey' => sesskey()));
return new \single_select($url, 'cmid', $options, '', $nothing = array('' => 'choosedots'));
}
/**