From 88f64b5111d181d7cf8019d476a28c3757218565 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 3 Nov 2014 09:32:02 +0800 Subject: [PATCH] MDL-47810 tool_monitor: action_link when there is only 1 option When the rule plugin is not a module you can subscribe to it without having to select to which module instance you want to subscribe, so there is no need to display a drop down menu. --- .../classes/output/managesubs/rules.php | 16 +++++--- admin/tool/monitor/classes/rule.php | 37 +++++++++++++------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/admin/tool/monitor/classes/output/managesubs/rules.php b/admin/tool/monitor/classes/output/managesubs/rules.php index 70fd6af26ca..7014a3536ad 100644 --- a/admin/tool/monitor/classes/output/managesubs/rules.php +++ b/admin/tool/monitor/classes/output/managesubs/rules.php @@ -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; } } diff --git a/admin/tool/monitor/classes/rule.php b/admin/tool/monitor/classes/rule.php index df5d4b46113..2a23eb14841 100644 --- a/admin/tool/monitor/classes/rule.php +++ b/admin/tool/monitor/classes/rule.php @@ -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')); } /**