Skip to content

Commit

Permalink
Merge branch 'MDL-47810_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 3, 2014
2 parents a46b057 + 88f64b5 commit 971163a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
18 changes: 12 additions & 6 deletions admin/tool/monitor/classes/output/managesubs/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,19 @@ public function col_filters(\tool_monitor\rule $rule) {
public function col_select(\tool_monitor\rule $rule) {
global $OUTPUT;

$select = $rule->get_module_select($this->courseid);

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);
$options = $rule->get_subscribe_options($this->courseid);
$text = get_string('subscribeto', 'tool_monitor', $rule->get_name($this->context));

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;
}
}

Expand Down
37 changes: 25 additions & 12 deletions admin/tool/monitor/classes/rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,40 @@ public function delete_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));
Expand All @@ -115,10 +129,9 @@ public function get_module_select($courseid) {
$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'));
}

/**
Expand Down

0 comments on commit 971163a

Please sign in to comment.