From c4701daa75c9867d0e3afa16fd5d245a1480d6ee Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sun, 26 Oct 2014 22:52:08 -0700 Subject: [PATCH 1/4] MDL-47758 tool_monitor: prevent DB error when revisiting a delete URL --- .../classes/output/managerules/renderable.php | 7 ++--- .../classes/output/managesubs/subs.php | 9 ++---- admin/tool/monitor/index.php | 31 ++++++++++++++++--- admin/tool/monitor/managerules.php | 30 +++++++++++++++--- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/admin/tool/monitor/classes/output/managerules/renderable.php b/admin/tool/monitor/classes/output/managerules/renderable.php index c42f83724f7..0d405e1cd6e 100644 --- a/admin/tool/monitor/classes/output/managerules/renderable.php +++ b/admin/tool/monitor/classes/output/managerules/renderable.php @@ -171,11 +171,8 @@ class renderable extends \table_sql implements \renderable { $icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor'))); $manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon')); - $a = $rule->get_name($this->context); - $action = new \component_action('click', 'M.util.show_confirm_dialog', array('message' => get_string('ruleareyousure', - 'tool_monitor', $a))); - $icon = $OUTPUT->action_link($deleteurl, new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor')), $action); - $manage .= $icon; + $icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor'))); + $manage .= \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); } else { $manage = get_string('nopermission', 'tool_monitor'); } diff --git a/admin/tool/monitor/classes/output/managesubs/subs.php b/admin/tool/monitor/classes/output/managesubs/subs.php index 8ba616d52d4..11c123137e7 100644 --- a/admin/tool/monitor/classes/output/managesubs/subs.php +++ b/admin/tool/monitor/classes/output/managesubs/subs.php @@ -135,14 +135,11 @@ class subs extends \table_sql implements \renderable { public function col_unsubscribe(\tool_monitor\subscription $sub) { global $OUTPUT, $CFG; - $a = $sub->get_name($this->context); $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array('subscriptionid' => $sub->id, 'action' => 'unsubscribe', 'courseid' => $this->courseid, 'sesskey' => sesskey())); - $action = new \component_action('click', 'M.util.show_confirm_dialog', array('message' => get_string('subareyousure', - 'tool_monitor', $a))); - $icon = $OUTPUT->action_link($deleteurl, - new \pix_icon('t/delete', get_string('deletesubscription', 'tool_monitor')), $action); - return $icon; + $icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deletesubscription', 'tool_monitor'))); + + return \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); } /** diff --git a/admin/tool/monitor/index.php b/admin/tool/monitor/index.php index 3a02a62c49e..2983eade182 100644 --- a/admin/tool/monitor/index.php +++ b/admin/tool/monitor/index.php @@ -30,6 +30,7 @@ $action = optional_param('action', '', PARAM_ALPHA); $cmid = optional_param('cmid', 0, PARAM_INT); $ruleid = optional_param('ruleid', 0, PARAM_INT); $subscriptionid = optional_param('subscriptionid', 0, PARAM_INT); +$confirm = optional_param('confirm', false, PARAM_BOOL); // Validate course id. if (empty($courseid)) { @@ -61,8 +62,6 @@ $PAGE->set_pagelayout('report'); $PAGE->set_title($title); $PAGE->set_heading($title); -echo $OUTPUT->header(); - // Create/delete subscription if needed. if (!empty($action)) { require_sesskey(); @@ -70,14 +69,38 @@ if (!empty($action)) { case 'subscribe' : $rule = \tool_monitor\rule_manager::get_rule($ruleid); $rule->subscribe_user($courseid, $cmid); + echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('subcreatesuccess', 'tool_monitor'), 'notifysuccess'); break; case 'unsubscribe' : - \tool_monitor\subscription_manager::delete_subscription($subscriptionid); - echo $OUTPUT->notification(get_string('subdeletesuccess', 'tool_monitor'), 'notifysuccess'); + // If the subscription does not exist, then redirect back as the subscription must have already been deleted. + if (!$subscription = $DB->record_exists('tool_monitor_subscriptions', array('id' => $subscriptionid))) { + redirect(new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid))); + } + + // Set the URLs. + $confirmurl = new moodle_url('/admin/tool/monitor/index.php', array('subscriptionid' => $subscriptionid, + 'courseid' => $courseid, 'action' => 'unsubscribe', 'confirm' => true, + 'sesskey' => sesskey())); + $cancelurl = new moodle_url('/admin/tool/monitor/index.php', array('subscriptionid' => $subscriptionid, + 'courseid' => $courseid, 'sesskey' => sesskey())); + if ($confirm) { + \tool_monitor\subscription_manager::delete_subscription($subscriptionid); + echo $OUTPUT->header(); + echo $OUTPUT->notification(get_string('subdeletesuccess', 'tool_monitor'), 'notifysuccess'); + } else { + $subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid); + echo $OUTPUT->header(); + echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($context)), + $confirmurl, $cancelurl); + echo $OUTPUT->footer(); + exit(); + } break; default: } +} else { + echo $OUTPUT->header(); } // Render the current subscriptions list. diff --git a/admin/tool/monitor/managerules.php b/admin/tool/monitor/managerules.php index bdafd03da76..d86a308e0f6 100644 --- a/admin/tool/monitor/managerules.php +++ b/admin/tool/monitor/managerules.php @@ -28,6 +28,7 @@ require_once($CFG->libdir.'/adminlib.php'); $courseid = optional_param('courseid', 0, PARAM_INT); $ruleid = optional_param('ruleid', 0, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); +$confirm = optional_param('confirm', false, PARAM_BOOL); // Validate course id. if (empty($courseid)) { @@ -62,12 +63,17 @@ if (empty($courseid)) { admin_externalpage_setup('toolmonitorrules', '', null, '', array('pagelayout' => 'report')); } -echo $OUTPUT->header(); - // Copy/delete rule if needed. if (!empty($action) && $ruleid) { require_sesskey(); - $rule = \tool_monitor\rule_manager::get_rule($ruleid); + + // If the rule does not exist, then redirect back as the rule must have already been deleted. + if (!$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleid), '*', IGNORE_MISSING)) { + redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid))); + } + + echo $OUTPUT->header(); + $rule = \tool_monitor\rule_manager::get_rule($rule); if ($rule->can_manage_rule()) { switch ($action) { case 'copy' : @@ -75,8 +81,20 @@ if (!empty($action) && $ruleid) { echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess'); break; case 'delete' : - $rule->delete_rule(); - echo $OUTPUT->notification(get_string('ruledeletesuccess', 'tool_monitor'), 'notifysuccess'); + $confirmurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', + array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete', + 'confirm' => true, 'sesskey' => sesskey())); + $cancelurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', + array('courseid' => $courseid)); + if ($confirm) { + $rule->delete_rule(); + echo $OUTPUT->notification(get_string('ruledeletesuccess', 'tool_monitor'), 'notifysuccess'); + } else { + echo $OUTPUT->confirm(get_string('ruleareyousure', 'tool_monitor', $rule->get_name($context)), + $confirmurl, $cancelurl); + echo $OUTPUT->footer(); + exit(); + } break; default: } @@ -84,6 +102,8 @@ if (!empty($action) && $ruleid) { // User doesn't have permissions. Should never happen for real users. throw new moodle_exception('rulenopermissions', 'tool_monitor', $manageurl, $action); } +} else { + echo $OUTPUT->header(); } // Render the rule list. From eb0aabde738f09cfe8984601f99777acf547cfdc Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 30 Oct 2014 21:13:51 -0700 Subject: [PATCH 2/4] MDL-47758 tool_monitor: altered behat tests so they pass --- admin/tool/monitor/tests/behat/rule.feature | 4 ++-- admin/tool/monitor/tests/behat/subscription.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/tool/monitor/tests/behat/rule.feature b/admin/tool/monitor/tests/behat/rule.feature index 33287a8946d..b0d19b58d5c 100644 --- a/admin/tool/monitor/tests/behat/rule.feature +++ b/admin/tool/monitor/tests/behat/rule.feature @@ -67,7 +67,7 @@ Feature: tool_monitor_rule And I navigate to "Event monitoring rules" node in "Course administration > Reports" When I click on "Delete rule" "link" Then I should see "Are you sure you want to delete rule \"New rule course level\"?" - And I press "Yes" + And I press "Continue" And I should see "Rule successfully deleted" And I should not see "New rule course level" @@ -127,7 +127,7 @@ Feature: tool_monitor_rule And I navigate to "Event monitoring rules" node in "Site administration > Reports" When I click on "Delete rule" "link" Then I should see "Are you sure you want to delete rule \"New rule site level\"?" - And I press "Yes" + And I press "Continue" And I should see "Rule successfully deleted" And I should not see "New rule site level" diff --git a/admin/tool/monitor/tests/behat/subscription.feature b/admin/tool/monitor/tests/behat/subscription.feature index f189a2a71d8..6481d903a92 100644 --- a/admin/tool/monitor/tests/behat/subscription.feature +++ b/admin/tool/monitor/tests/behat/subscription.feature @@ -58,7 +58,7 @@ Feature: tool_monitor_subscriptions And I should see "Subscription successfully created" When I click on "Delete subscription" "link" in the "New rule course level" "table_row" And I should see "Are you sure you want to delete this subscription for the rule \"New rule course level\"?" - And I press "Yes" + And I press "Continue" Then I should see "Subscription successfully removed" And "#toolmonitorsubs_r0" "css_element" should not exist @@ -79,7 +79,7 @@ Feature: tool_monitor_subscriptions And "#toolmonitorsubs_r0" "css_element" should exist When I click on "Delete subscription" "link" in the "New rule site level" "table_row" And I should see "Are you sure you want to delete this subscription for the rule \"New rule site level\"?" - And I press "Yes" + And I press "Continue" Then I should see "Subscription successfully removed" And "#toolmonitorsubs_r0" "css_element" should not exist From 7293e97162baa321101febcff2604730955adbd5 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 2 Oct 2014 16:44:39 -0700 Subject: [PATCH 3/4] MDL-47361 tooL_monitor: string and UI changes --- .../classes/output/helpicon/renderable.php | 93 -------------- .../classes/output/helpicon/renderer.php | 79 ------------ .../classes/output/managerules/renderable.php | 44 +++---- .../classes/output/managesubs/rules.php | 78 ++++++++---- .../classes/output/managesubs/subs.php | 114 +++++++++--------- admin/tool/monitor/classes/rule.php | 18 ++- admin/tool/monitor/classes/rule_form.php | 24 ++-- admin/tool/monitor/classes/subscription.php | 13 +- admin/tool/monitor/edit.php | 28 +++-- admin/tool/monitor/help.php | 62 ---------- admin/tool/monitor/help_ajax.php | 50 -------- admin/tool/monitor/index.php | 26 ++-- admin/tool/monitor/lang/en/tool_monitor.php | 58 ++++----- admin/tool/monitor/managerules.php | 11 +- 14 files changed, 224 insertions(+), 474 deletions(-) delete mode 100644 admin/tool/monitor/classes/output/helpicon/renderable.php delete mode 100644 admin/tool/monitor/classes/output/helpicon/renderer.php delete mode 100644 admin/tool/monitor/help.php delete mode 100644 admin/tool/monitor/help_ajax.php diff --git a/admin/tool/monitor/classes/output/helpicon/renderable.php b/admin/tool/monitor/classes/output/helpicon/renderable.php deleted file mode 100644 index 3cb0395ebde..00000000000 --- a/admin/tool/monitor/classes/output/helpicon/renderable.php +++ /dev/null @@ -1,93 +0,0 @@ -. - -/** - * The file for the renderable class for the tool_monitor help icon. - * - * @package tool_monitor - * @copyright 2014 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace tool_monitor\output\helpicon; - -defined('MOODLE_INTERNAL') || die; - -/** - * Renderable class for the tool_monitor help icon. - * - * @since Moodle 2.8 - * @package tool_monitor - * @copyright 2014 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class renderable implements \renderable { - - /** - * @var string $type the type we are displaying the help icon for (either rule or subscription). - */ - public $type; - - /** - * @var int $id the id of the type. - */ - public $id; - - /** - * The constructor. - * - * @param string $type the type we are displaying the help icon for (either rule or subscription). - * @param int $id the id of the type. - */ - public function __construct($type, $id) { - $this->type = $type; - $this->id = $id; - } - - /** - * Returns the string to display for the help icon. - * - * @param string $type the type we are displaying the help icon for (either rule or subscription). - * @param int $id the id of the type. - * @param boolean $ajax Whether this help is called from an AJAX script. - * This is used to influence text formatting and determines which format to output the doclink in. - * @return string|object|array $a An object, string or number that can be used within translation strings - */ - public static function get_help_string_parameters($type, $id, $ajax = false) { - if ($type == 'rule') { - $rule = \tool_monitor\rule_manager::get_rule($id); - - $langstring = new \stdClass(); - $langstring->eventname = $rule->get_event_name(); - $langstring->eventcomponent = $rule->get_plugin_name(); - $langstring->frequency = $rule->frequency; - $langstring->minutes = $rule->timewindow / MINSECS; - - return get_formatted_help_string('rulehelp', 'tool_monitor', $ajax, $langstring); - } - - // Must be a subscription. - $sub = \tool_monitor\subscription_manager::get_subscription($id); - - $langstring = new \stdClass(); - $langstring->eventname = $sub->get_event_name(); - $langstring->moduleinstance = $sub->get_instance_name(); - $langstring->frequency = $sub->frequency; - $langstring->minutes = $sub->timewindow / MINSECS; - - return get_formatted_help_string('subhelp', 'tool_monitor', $ajax, $langstring); - } -} diff --git a/admin/tool/monitor/classes/output/helpicon/renderer.php b/admin/tool/monitor/classes/output/helpicon/renderer.php deleted file mode 100644 index 99025f2fd6c..00000000000 --- a/admin/tool/monitor/classes/output/helpicon/renderer.php +++ /dev/null @@ -1,79 +0,0 @@ -. - -/** - * The file for the renderer class for the tool_monitor help icon. - * - * @package tool_monitor - * @copyright 2014 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace tool_monitor\output\helpicon; - -defined('MOODLE_INTERNAL') || die; - -/** - * Renderer class for tool_monitor help icons. - * - * @since Moodle 2.8 - * @package tool_monitor - * @copyright 2014 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class renderer extends \plugin_renderer_base { - - /** - * Get the HTML for the help icon. - * - * @param renderable $renderable renderable widget - * - * @return string the HTML of the help icon to display. - */ - protected function render_renderable(renderable $renderable) { - global $CFG; - - // First get the help image icon. - $src = $this->pix_url('help'); - - if ($renderable->type == 'rule') { - $title = get_string('rulehelp', 'tool_monitor'); - } else { // Must be a subscription. - $title = get_string('subhelp', 'tool_monitor'); - } - - $alt = get_string('helpwiththis'); - - $attributes = array('src' => $src, 'alt' => $alt, 'class' => 'iconhelp'); - $output = \html_writer::empty_tag('img', $attributes); - - // Now create the link around it - we need https on loginhttps pages. - $urlparams = array(); - $urlparams['type'] = $renderable->type; - $urlparams['id'] = $renderable->id; - $urlparams['lang'] = current_language(); - $url = new \moodle_url($CFG->httpswwwroot . '/admin/tool/monitor/help.php', $urlparams); - - // Note: this title is displayed only if JS is disabled, otherwise the link will have the new ajax tooltip. - $title = get_string('helpprefix2', '', trim($title, ". \t")); - - $attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target' => '_blank'); - $output = \html_writer::tag('a', $output, $attributes); - - // Now, finally the span. - return \html_writer::tag('span', $output, array('class' => 'helptooltip')); - } -} diff --git a/admin/tool/monitor/classes/output/managerules/renderable.php b/admin/tool/monitor/classes/output/managerules/renderable.php index 0d405e1cd6e..198a60654fe 100644 --- a/admin/tool/monitor/classes/output/managerules/renderable.php +++ b/admin/tool/monitor/classes/output/managerules/renderable.php @@ -66,13 +66,13 @@ class renderable extends \table_sql implements \renderable { $this->set_attribute('id', 'toolmonitorrules_table'); $this->set_attribute('class', 'toolmonitor managerules generaltable generalbox'); - $this->define_columns(array('name', 'description', 'context', 'plugin', 'eventname', 'filters', 'manage')); + $this->define_columns(array('name', 'description', 'course', 'plugin', 'eventname', 'filters', 'manage')); $this->define_headers(array( - get_string('name'), + get_string('rulename', 'tool_monitor'), get_string('description'), - get_string('context', 'tool_monitor'), - get_string('plugin'), - get_string('eventname'), + get_string('course'), + get_string('area', 'tool_monitor'), + get_string('event', 'tool_monitor'), get_string('frequency', 'tool_monitor'), get_string('manage', 'tool_monitor'), ) @@ -93,7 +93,6 @@ class renderable extends \table_sql implements \renderable { * Generate content for name column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the column field. */ public function col_name(\tool_monitor\rule $rule) { @@ -104,18 +103,33 @@ class renderable extends \table_sql implements \renderable { * Generate content for description column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the column field. */ public function col_description(\tool_monitor\rule $rule) { return $rule->get_description($this->context); } + /** + * Generate content for course column. + * + * @param \tool_monitor\rule $rule rule object + * @return string html used to display the context column field. + */ + public function col_course(\tool_monitor\rule $rule) { + $coursename = $rule->get_course_name($this->context); + + $courseid = $rule->courseid; + if (empty($courseid)) { + return $coursename; + } else { + return \html_writer::link(new \moodle_url('/course/view.php', array('id' => $this->courseid)), $coursename); + } + } + /** * Generate content for plugin column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the column field. */ public function col_plugin(\tool_monitor\rule $rule) { @@ -126,7 +140,6 @@ class renderable extends \table_sql implements \renderable { * Generate content for eventname column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the column field. */ public function col_eventname(\tool_monitor\rule $rule) { @@ -137,7 +150,6 @@ class renderable extends \table_sql implements \renderable { * Generate content for filters column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the filters column field. */ public function col_filters(\tool_monitor\rule $rule) { @@ -148,7 +160,6 @@ class renderable extends \table_sql implements \renderable { * Generate content for manage column. * * @param \tool_monitor\rule $rule rule object - * * @return string html used to display the manage column field. */ public function col_manage(\tool_monitor\rule $rule) { @@ -197,15 +208,4 @@ class renderable extends \table_sql implements \renderable { $this->initialbars($total > $pagesize); } } - - /** - * Generate content for context column. - * - * @param \tool_monitor\rule $rule rule object - * - * @return string html used to display the context column field. - */ - public function col_context(\tool_monitor\rule $rule) { - return ($rule->courseid == 0) ? get_string('system', 'tool_monitor') : get_string('course'); - } } diff --git a/admin/tool/monitor/classes/output/managesubs/rules.php b/admin/tool/monitor/classes/output/managesubs/rules.php index 6821583e6e2..70fd6af26ca 100644 --- a/admin/tool/monitor/classes/output/managesubs/rules.php +++ b/admin/tool/monitor/classes/output/managesubs/rules.php @@ -53,11 +53,6 @@ class rules extends \table_sql implements \renderable { */ protected $context; - /** - * @var \tool_monitor\output\helpicon\renderer the help icon renderer. - */ - protected $helpiconrenderer; - /** * Sets up the table_log parameters. * @@ -67,16 +62,18 @@ class rules extends \table_sql implements \renderable { * @param int $perpage Number of rules to display per page. */ public function __construct($uniqueid, \moodle_url $url, $courseid = 0, $perpage = 100) { - global $PAGE; - parent::__construct($uniqueid); $this->set_attribute('class', 'toolmonitor subscriberules generaltable generalbox'); - $this->define_columns(array('name', 'description', 'select')); + $this->define_columns(array('name', 'description', 'course', 'plugin', 'eventname', 'filters', 'select')); $this->define_headers(array( - get_string('name'), + get_string('rulename', 'tool_monitor'), get_string('description'), - get_string('select') + get_string('course'), + get_string('area', 'tool_monitor'), + get_string('event', 'tool_monitor'), + get_string('frequency', 'tool_monitor'), + '' ) ); $this->courseid = $courseid; @@ -88,7 +85,6 @@ class rules extends \table_sql implements \renderable { $this->pageable(true); $this->is_downloadable(false); $this->define_baseurl($url); - $this->helpiconrenderer = $PAGE->get_renderer('tool_monitor', 'helpicon'); $total = \tool_monitor\rule_manager::count_rules_by_courseid($this->courseid); $this->totalcount = $total; } @@ -97,34 +93,74 @@ class rules extends \table_sql implements \renderable { * Generate content for name column. * * @param \tool_monitor\rule $rule rule object - * - * @return string html used to display the column field. + * @return string html used to display the rule name. */ public function col_name(\tool_monitor\rule $rule) { - $name = $rule->get_name($this->context); - $helpicon = new \tool_monitor\output\helpicon\renderable('rule', $rule->id); - $helpicon = $this->helpiconrenderer->render($helpicon); - - return $name . $helpicon; + return $rule->get_name($this->context); } /** * Generate content for description column. * * @param \tool_monitor\rule $rule rule object - * - * @return string html used to display the column field. + * @return string html used to display the description. */ public function col_description(\tool_monitor\rule $rule) { return $rule->get_description($this->context); } + /** + * Generate content for course column. + * + * @param \tool_monitor\rule $rule rule object + * @return string html used to display the course name. + */ + public function col_course(\tool_monitor\rule $rule) { + $coursename = $rule->get_course_name($this->context); + + $courseid = $rule->courseid; + if (empty($courseid)) { + return $coursename; + } else { + return \html_writer::link(new \moodle_url('/course/view.php', array('id' => $this->courseid)), $coursename); + } + } + /** * Generate content for plugin column. * * @param \tool_monitor\rule $rule rule object + * @return string html used to display the plugin name. + */ + public function col_plugin(\tool_monitor\rule $rule) { + return $rule->get_plugin_name(); + } + + /** + * Generate content for eventname column. * - * @return string html used to display the column field. + * @param \tool_monitor\rule $rule rule object + * @return string html used to display the event name. + */ + public function col_eventname(\tool_monitor\rule $rule) { + return $rule->get_event_name(); + } + + /** + * Generate content for filters column. + * + * @param \tool_monitor\rule $rule rule object + * @return string html used to display the filters. + */ + public function col_filters(\tool_monitor\rule $rule) { + return $rule->get_filters_description(); + } + + /** + * Generate content for select column. + * + * @param \tool_monitor\rule $rule rule object + * @return string html used to display the select field. */ public function col_select(\tool_monitor\rule $rule) { global $OUTPUT; diff --git a/admin/tool/monitor/classes/output/managesubs/subs.php b/admin/tool/monitor/classes/output/managesubs/subs.php index 11c123137e7..b0403d8a097 100644 --- a/admin/tool/monitor/classes/output/managesubs/subs.php +++ b/admin/tool/monitor/classes/output/managesubs/subs.php @@ -48,11 +48,6 @@ class subs extends \table_sql implements \renderable { */ protected $context; - /** - * @var \tool_monitor\output\helpicon\renderer the help icon renderer. - */ - protected $helpiconrenderer; - /** * Sets up the table_log parameters. * @@ -62,18 +57,18 @@ class subs extends \table_sql implements \renderable { * @param int $perpage Number of rules to display per page. */ public function __construct($uniqueid, \moodle_url $url, $courseid = 0, $perpage = 100) { - global $PAGE; - parent::__construct($uniqueid); $this->set_attribute('class', 'toolmonitor subscriptions generaltable generalbox'); - $this->define_columns(array('name', 'course', 'instance', 'unsubscribe', 'editrule')); + $this->define_columns(array('name', 'description', 'course', 'plugin', 'eventname', 'filters', 'unsubscribe')); $this->define_headers(array( - get_string('name'), + get_string('rulename', 'tool_monitor'), + get_string('description'), get_string('course'), - get_string('moduleinstance', 'tool_monitor'), - get_string('unsubscribe', 'tool_monitor'), - get_string('editrule', 'tool_monitor') + get_string('area', 'tool_monitor'), + get_string('event', 'tool_monitor'), + get_string('frequency', 'tool_monitor'), + get_string('unsubscribe', 'tool_monitor') ) ); $this->courseid = $courseid; @@ -85,52 +80,80 @@ class subs extends \table_sql implements \renderable { $this->pageable(true); $this->is_downloadable(false); $this->define_baseurl($url); - $this->helpiconrenderer = $PAGE->get_renderer('tool_monitor', 'helpicon'); } /** * Generate content for name column. * * @param \tool_monitor\subscription $sub subscription object - * - * @return string html used to display the column field. + * @return string html used to display the rule name. */ public function col_name(\tool_monitor\subscription $sub) { - $name = $sub->get_name($this->context); - $helpicon = new \tool_monitor\output\helpicon\renderable('subscription', $sub->id); - $helpicon = $this->helpiconrenderer->render($helpicon); - - return $name . $helpicon; - } - - /** - * Generate content for course column. - * - * @param \tool_monitor\subscription $sub subscription object - * - * @return string html used to display the column field. - */ - public function col_course(\tool_monitor\subscription $sub) { - return $sub->get_course_name($this->context); + return $sub->get_name($this->context); } /** * Generate content for description column. * * @param \tool_monitor\subscription $sub subscription object - * - * @return string html used to display the column field. + * @return string html used to display the description. */ - public function col_instance(\tool_monitor\subscription $sub) { - return $sub->get_instance_name(); + public function col_description(\tool_monitor\subscription $sub) { + return $sub->get_description($this->context); } /** - * Generate content for manage column. + * Generate content for course column. * * @param \tool_monitor\subscription $sub subscription object + * @return string html used to display the course name. + */ + public function col_course(\tool_monitor\subscription $sub) { + $coursename = $sub->get_course_name($this->context); + + $courseid = $sub->courseid; + if (empty($courseid)) { + return $coursename; + } else { + return \html_writer::link(new \moodle_url('/course/view.php', array('id' => $this->courseid)), $coursename); + } + } + + /** + * Generate content for plugin column. * - * @return string html used to display the column field. + * @param \tool_monitor\subscription $sub subscription object + * @return string html used to display the plugin name. + */ + public function col_plugin(\tool_monitor\subscription $sub) { + return $sub->get_plugin_name(); + } + + /** + * Generate content for eventname column. + * + * @param \tool_monitor\subscription $sub subscription object + * @return string html used to display the event name. + */ + public function col_eventname(\tool_monitor\subscription $sub) { + return $sub->get_event_name(); + } + + /** + * Generate content for filters column. + * + * @param \tool_monitor\subscription $sub subscription object + * @return string html used to display the filters. + */ + public function col_filters(\tool_monitor\subscription $sub) { + return $sub->get_filters_description(); + } + + /** + * Generate content for unsubscribe column. + * + * @param \tool_monitor\subscription $sub subscription object + * @return string html used to display the unsubscribe field. */ public function col_unsubscribe(\tool_monitor\subscription $sub) { global $OUTPUT, $CFG; @@ -142,23 +165,6 @@ class subs extends \table_sql implements \renderable { return \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); } - /** - * Generate content for edit rule column. - * - * @param \tool_monitor\subscription $sub subscription object - * - * @return string html used to display the column field. - */ - public function col_editrule(\tool_monitor\subscription $sub) { - if ($sub->can_manage_rule()) { - // User can manage rule. - $editurl = new \moodle_url('/admin/tool/monitor/edit.php', array('ruleid' => $sub->ruleid, - 'courseid' => $sub->rulecourseid)); - return \html_writer::link($editurl, get_string('editrule', 'tool_monitor')); - } - return '-'; - } - /** * Query the reader. Store results in the object for use by build_table. * diff --git a/admin/tool/monitor/classes/rule.php b/admin/tool/monitor/classes/rule.php index 81b3aef94e1..df5d4b46113 100644 --- a/admin/tool/monitor/classes/rule.php +++ b/admin/tool/monitor/classes/rule.php @@ -207,11 +207,26 @@ class rule { return get_string('freqdesc', 'tool_monitor', $a); } + /** + * Get properly formatted name of the course associated. + * + * @param \context $context context where this name would be displayed. + * @return string The course fullname. + */ + public function get_course_name($context) { + $courseid = $this->courseid; + if (empty($courseid)) { + return get_string('site'); + } else { + $course = get_course($courseid); + return format_string($course->fullname, true, array('context' => $context)); + } + } + /** * Get properly formatted name of the rule associated. * * @param \context $context context where this name would be displayed. - * * @return string Formatted name of the rule. */ public function get_name(\context $context) { @@ -222,7 +237,6 @@ class rule { * Get properly formatted description of the rule associated. * * @param \context $context context where this description would be displayed. - * * @return string Formatted description of the rule. */ public function get_description(\context $context) { diff --git a/admin/tool/monitor/classes/rule_form.php b/admin/tool/monitor/classes/rule_form.php index a06977948a9..f059fcf486c 100644 --- a/admin/tool/monitor/classes/rule_form.php +++ b/admin/tool/monitor/classes/rule_form.php @@ -85,47 +85,41 @@ class rule_form extends \moodleform { ); // Name field. - $mform->addElement('text', 'name', get_string('name', 'tool_monitor'), 'size="50"'); + $mform->addElement('text', 'name', get_string('rulename', 'tool_monitor'), 'size="50"'); $mform->addRule('name', get_string('required'), 'required'); $mform->setType('name', PARAM_TEXT); - $mform->addHelpButton('name', 'name', 'tool_monitor'); // Plugin field. - $mform->addElement('select', 'plugin', get_string('selectplugin', 'tool_monitor'), $pluginlist); + $mform->addElement('select', 'plugin', get_string('areatomonitor', 'tool_monitor'), $pluginlist); $mform->addRule('plugin', get_string('required'), 'required'); - $mform->addHelpButton('plugin', 'selectplugin', 'tool_monitor'); // Event field. - $mform->addElement('select', 'eventname', get_string('selectevent', 'tool_monitor'), $eventlist); + $mform->addElement('select', 'eventname', get_string('event', 'tool_monitor'), $eventlist); $mform->addRule('eventname', get_string('required'), 'required'); - $mform->addHelpButton('eventname', 'selectevent', 'tool_monitor'); // Description field. - $mform->addElement('editor', 'description', get_string('description', 'tool_monitor'), $editoroptions); - $mform->addHelpButton('description', 'description', 'tool_monitor'); + $mform->addElement('editor', 'description', get_string('description'), $editoroptions); // Filters. - $mform->addElement('header', 'customisefilters', get_string('customisefilters', 'tool_monitor')); $freq = array(1 => 1, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100, 1000 => 1000); - $mform->addElement('select', 'frequency', get_string('selectfrequency', 'tool_monitor'), $freq); + $mform->addElement('select', 'frequency', get_string('frequency', 'tool_monitor'), $freq); $mform->addRule('frequency', get_string('required'), 'required'); - $mform->addHelpButton('frequency', 'selectfrequency', 'tool_monitor'); + $mform->addHelpButton('frequency', 'frequency', 'tool_monitor'); $mins = array(1 => 1, 5 => 5, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 45 => 45, 50 => 50, 55 => 55, 60 => 60); - $mform->addElement('select', 'minutes', get_string('selectminutes', 'tool_monitor'), $mins); + $mform->addElement('select', 'minutes', get_string('inminutes', 'tool_monitor'), $mins); $mform->addRule('minutes', get_string('required'), 'required'); // Message template. - $mform->addElement('header', 'customisemessage', get_string('customisemessage', 'tool_monitor')); $mform->addElement('editor', 'template', get_string('messagetemplate', 'tool_monitor'), $editoroptions); - $mform->setDefault('template', get_string('defaultmessagetpl', 'tool_monitor')); + $mform->setDefault('template', get_string('defaultmessagetemplate', 'tool_monitor')); $mform->addRule('template', get_string('required'), 'required'); $mform->addHelpButton('template', 'messagetemplate', 'tool_monitor'); // Action buttons. - $this->add_action_buttons(false, get_string('savechanges')); + $this->add_action_buttons(true, get_string('savechanges')); } /** diff --git a/admin/tool/monitor/classes/subscription.php b/admin/tool/monitor/classes/subscription.php index a729dc85469..6e25f6ed084 100644 --- a/admin/tool/monitor/classes/subscription.php +++ b/admin/tool/monitor/classes/subscription.php @@ -124,7 +124,6 @@ class subscription { * Get properly formatted name of the rule associated. * * @param \context $context context where this name would be displayed. - * * @return string Formatted name of the rule. */ public function get_name(\context $context) { @@ -135,7 +134,6 @@ class subscription { * Get properly formatted description of the rule associated. * * @param \context $context context where this description would be displayed. - * * @return string Formatted description of the rule. */ public function get_description(\context $context) { @@ -162,21 +160,16 @@ class subscription { * Get properly formatted name of the course associated. * * @param \context $context context where this name would be displayed. - * * @return string Formatted name of the rule. */ public function get_course_name(\context $context) { - global $SITE; $courseid = $this->courseid; if (empty($courseid)) { - $coursename = format_string($SITE->fullname, true, array('context' => $context)); + return get_string('site'); } else { - $course = get_course($this->courseid); - $link = new \moodle_url('/course/view.php', array('id' => $course->id)); - $coursename = format_string($course->fullname, true, array('context' => $context)); - $coursename = \html_writer::link($link, $coursename); + $course = get_course($courseid); + return format_string($course->fullname, true, array('context' => $context)); } - return $coursename; } /** diff --git a/admin/tool/monitor/edit.php b/admin/tool/monitor/edit.php index c69e92e0620..a20e1409b43 100644 --- a/admin/tool/monitor/edit.php +++ b/admin/tool/monitor/edit.php @@ -44,17 +44,12 @@ if (empty($courseid)) { require_capability('tool/monitor:managerules', $context); // Set up the page. -$a = new stdClass(); -$a->coursename = $coursename; -$a->reportname = get_string('pluginname', 'tool_monitor'); -$title = get_string('title', 'tool_monitor', $a); $url = new moodle_url("/admin/tool/monitor/edit.php", array('courseid' => $courseid, 'ruleid' => $ruleid)); $manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid)); - $PAGE->set_url($url); $PAGE->set_pagelayout('report'); -$PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_title($coursename); +$PAGE->set_heading($coursename); // Get data ready for mform. $eventlist = tool_monitor\eventlist::get_all_eventlist(true); @@ -85,6 +80,11 @@ if (!empty($ruleid)) { $mform = new tool_monitor\rule_form(null, array('eventlist' => $eventlist, 'pluginlist' => $pluginlist, 'rule' => $rule, 'courseid' => $courseid)); +if ($mform->is_cancelled()) { + redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid))); + exit(); +} + if ($mformdata = $mform->get_data()) { $rule = \tool_monitor\rule_manager::clean_ruledata_form($mformdata); @@ -95,10 +95,14 @@ if ($mformdata = $mform->get_data()) { } redirect($manageurl); -} else { - echo $OUTPUT->header(); - $mform->set_data($rule); - $mform->display(); - echo $OUTPUT->footer(); } +echo $OUTPUT->header(); +if (!empty($ruleid)) { + echo $OUTPUT->heading(get_string('editrule', 'tool_monitor')); +} else { + echo $OUTPUT->heading(get_string('addrule', 'tool_monitor')); +} +$mform->set_data($rule); +$mform->display(); +echo $OUTPUT->footer(); diff --git a/admin/tool/monitor/help.php b/admin/tool/monitor/help.php deleted file mode 100644 index 572b4bab20d..00000000000 --- a/admin/tool/monitor/help.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -/** - * Displays help on a new page. - * - * @copyright 2014 Mark Nelson - * @package tool_monitor - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -define('NO_MOODLE_COOKIES', true); - -require_once('../../../config.php'); - -$type = required_param('type', PARAM_ALPHA); -$id = required_param('id', PARAM_INT); -$lang = optional_param('lang', 'en', PARAM_LANG); - -// We don't actually modify the session here as we have NO_MOODLE_COOKIES set. -$SESSION->lang = $lang; - -$PAGE->set_url('/admin/tool/monitor/help.php'); -$PAGE->set_pagelayout('popup'); - -if ($type == 'rule') { - $item = \tool_monitor\rule_manager::get_rule($id); -} else { // Must be a subscription. - $item = \tool_monitor\subscription_manager::get_subscription($id); -} - -if ($item->courseid) { - $PAGE->set_context(context_course::instance($item->courseid)); -} else { // Must be system context. - $PAGE->set_context(context_system::instance()); -} - -// Get the help string data. -$data = tool_monitor\output\helpicon\renderable::get_help_string_parameters($type, $id); - -echo $OUTPUT->header(); -if (!empty($data->heading)) { - echo $OUTPUT->heading($data->heading, 1, 'helpheading'); -} -echo $data->text; -if (isset($data->completedoclink)) { - echo $data->completedoclink; -} -echo $OUTPUT->footer(); diff --git a/admin/tool/monitor/help_ajax.php b/admin/tool/monitor/help_ajax.php deleted file mode 100644 index 429ff3b06df..00000000000 --- a/admin/tool/monitor/help_ajax.php +++ /dev/null @@ -1,50 +0,0 @@ -. - -/** - * Displays help via AJAX call. - * - * @copyright 2014 Mark Nelson - * @package tool_monitor - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -define('NO_MOODLE_COOKIES', true); -define('AJAX_SCRIPT', true); - -require_once('../../../config.php'); - -$type = required_param('type', PARAM_ALPHA); -$id = required_param('id', PARAM_INT); -$lang = optional_param('lang', 'en', PARAM_LANG); - -// We don't actually modify the session here as we have NO_MOODLE_COOKIES set. -$SESSION->lang = $lang; -$PAGE->set_url('/admin/tool/monitor/help_ajax.php'); - -if ($type == 'rule') { - $item = \tool_monitor\rule_manager::get_rule($id); -} else { // Must be a subscription. - $item = \tool_monitor\subscription_manager::get_subscription($id); -} - -if ($item->courseid) { - $PAGE->set_context(context_course::instance($item->courseid)); -} else { // Must be system context. - $PAGE->set_context(context_system::instance()); -} - -echo json_encode(tool_monitor\output\helpicon\renderable::get_help_string_parameters($type, $id, true)); diff --git a/admin/tool/monitor/index.php b/admin/tool/monitor/index.php index 2983eade182..e6fd7d18e23 100644 --- a/admin/tool/monitor/index.php +++ b/admin/tool/monitor/index.php @@ -51,16 +51,11 @@ $sitename = format_string($SITE->fullname, true, array('context' => $context)); $PAGE->set_context($context); // Set up the page. -$a = new stdClass(); -$a->coursename = $sitename; -$a->reportname = get_string('pluginname', 'tool_monitor'); -$title = get_string('title', 'tool_monitor', $a); -$indexurl = new moodle_url("/admin/tool/monitor/index.php", array('courseid' => $courseid)); - +$indexurl = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid)); $PAGE->set_url($indexurl); $PAGE->set_pagelayout('report'); -$PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_title($sitename); +$PAGE->set_heading($sitename); // Create/delete subscription if needed. if (!empty($action)) { @@ -109,20 +104,27 @@ $renderer = $PAGE->get_renderer('tool_monitor', 'managesubs'); if (!empty($totalsubs)) { // Show the subscriptions section only if there are subscriptions. $subs = new \tool_monitor\output\managesubs\subs('toolmonitorsubs', $indexurl, $courseid); - echo $OUTPUT->heading(get_string('currentsubscriptions', 'tool_monitor')); + echo $OUTPUT->heading(get_string('currentsubscriptions', 'tool_monitor'), 3); echo $renderer->render($subs); } // Render the potential rules list. $totalrules = \tool_monitor\rule_manager::count_rules_by_courseid($courseid); -echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor')); +echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3); $rules = new \tool_monitor\output\managesubs\rules('toolmonitorrules', $indexurl, $courseid); echo $renderer->render($rules); + +// Check if the user can manage the course rules we are viewing. +if (empty($courseid)) { + $canmanagerules = has_capability('tool/monitor:managerules', $context); +} else { + $canmanagerules = has_capability('tool/monitor:managerules', $coursecontext); +} if (empty($totalrules)) { // No rules present. Show a link to manage rules page if permissions permit. echo html_writer::start_div(); echo html_writer::tag('span', get_string('norules', 'tool_monitor')); - if (has_capability('tool/monitor:managerules', $context)) { + if ($canmanagerules) { $manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid)); $a = html_writer::link($manageurl, get_string('managerules', 'tool_monitor')); $link = " "; @@ -130,7 +132,7 @@ if (empty($totalrules)) { echo $link; } echo html_writer::end_div(); -} else if (has_capability('tool/monitor:managerules', $context)) { +} else if ($canmanagerules) { $manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid)); echo $renderer->render_rules_link($manageurl); } diff --git a/admin/tool/monitor/lang/en/tool_monitor.php b/admin/tool/monitor/lang/en/tool_monitor.php index 5433d095eb1..dbf24540857 100644 --- a/admin/tool/monitor/lang/en/tool_monitor.php +++ b/admin/tool/monitor/lang/en/tool_monitor.php @@ -26,19 +26,17 @@ $string['addrule'] = 'Add a new rule'; $string['allevents'] = 'All events'; -$string['allmodules'] = 'All modules'; +$string['allmodules'] = 'All instances'; +$string['area'] = 'Area'; +$string['areatomonitor'] = 'Area to monitor'; $string['core'] = 'Core'; -$string['context'] = 'Context'; -$string['customisefilters'] = 'Select the frequency of the events'; -$string['customisemessage'] = 'Customise the notification message'; $string['currentsubscriptions'] = 'Your current subscriptions'; -$string['description_help'] = "Description is displayed to users when they want to subscribe to this rule. This helps them understand what the rule is about."; -$string['defaultmessagetpl'] = 'Rule "{rulename}" has happened. You can find further details at {link}'; +$string['defaultmessagetemplate'] = 'The rule "{rulename}" you have subscribed to has occurred - please find further details at {link}'; $string['deleterule'] = 'Delete rule'; $string['deletesubscription'] = 'Delete subscription'; -$string['description'] = 'Description:'; $string['duplicaterule'] = 'Duplicate rule'; $string['editrule'] = 'Edit rule'; +$string['event'] = 'Event'; $string['eventnotfound'] = 'Event not found'; $string['eventrulecreated'] = 'Rule created'; $string['eventruledeleted'] = 'Rule deleted'; @@ -47,31 +45,32 @@ $string['eventsubcreated'] = 'Subscription created'; $string['eventsubcriteriamet'] = 'Subscription criteria met'; $string['eventsubdeleted'] = 'Subscription deleted'; $string['errorincorrectevent'] = 'Please select an event related to the selected plugin'; -$string['freqdesc'] = '{$a->freq} times in {$a->mins} minutes'; -$string['frequency'] = 'Frequency'; +$string['freqdesc'] = '{$a->freq} time(s) in {$a->mins} minute(s)'; +$string['frequency'] = 'Notification threshold'; +$string['frequency_help'] = 'The number of events within a specified time period required for a notification message to be sent.'; +$string['inminutes'] = 'in minutes'; $string['invalidmodule'] = 'Invalid module'; -$string['norules'] = 'There are no rules you can subscribe to.'; -$string['manageruleslink'] = 'You can manage rules from {$a} page.'; +$string['manageruleslink'] = 'You can manage rules from the {$a} page.'; $string['managesubscriptionslink'] = 'You can subscribe to rules from the {$a} page.'; -$string['moduleinstance'] = 'Module instance'; $string['manage'] = 'Manage'; $string['managesubscriptions'] = 'Event monitoring'; $string['managerules'] = 'Event monitoring rules'; -$string['messageheader'] = 'Customise your notification message'; $string['messageprovider:notification'] = 'Notifications of rule subscriptions'; -$string['messagetemplate'] = 'Message template'; -$string['messagetemplate_help'] = 'This is the content of the message that will be sent to users, when the given conditions of the rule are met. You are allowed to use following templates in this. -
{link} - Link to the location where the event happened. -
{modulelink} - Link to the module where the event has happened. -
{rulename} - Name of this rule. -
{description} - Rule description. -
{eventname} - Name of the event associated with the rule.'; -$string['minutes'] = 'in minutes:'; -$string['name'] = 'Name of the rule: '; -$string['name_help'] = "Choose a name for the rule."; -$string['nopermission'] = "No permission"; +$string['nopermission'] = 'No permission'; +$string['messagetemplate'] = 'Notification message'; +$string['messagetemplate_help'] = 'A notification message is sent to subscribers once the notification threshold has been reached. It can include any or all of the following placeholders: +

+* Link to the location of the event {link}
+* Link to the area monitored {modulelink}
+* Rule name {rulename}
+* Description {description}
+* Event {eventname}'; +$string['monitor:managerules'] = 'Manage event monitor rules'; +$string['monitor:subscribe'] = 'Subscribe to event monitor rules'; +$string['norules'] = 'There are no event monitoring rules.'; $string['pluginname'] = 'Event monitor'; $string['processevents'] = 'Process events'; +$string['rulename'] = 'Rule name'; $string['ruleareyousure'] = 'Are you sure you want to delete rule "{$a}"?'; $string['rulecopysuccess'] = 'Rule successfully duplicated'; $string['ruledeletesuccess'] = 'Rule successfully deleted'; @@ -81,23 +80,12 @@ $string['rulenopermissions'] = 'You do not have permissions to "{$a} a rule"'; $string['rulescansubscribe'] = 'Rules you can subscribe to'; $string['selectacourse'] = 'Select a course'; $string['selectcourse'] = 'Visit this report at course level to get a list of possible modules'; -$string['selectevent'] = 'Select an event:'; -$string['selectevent_help'] = "Select an event to monitor. Please note that some events are only triggered for the entire site (e.g. 'course created') and will never trigger when subscribed to from within a course."; -$string['selectfrequency'] = 'Frequency of events:'; -$string['selectfrequency_help'] = "Frequency defines the denisty of the event occurrence. Select criterias to define how frequently the event should happen to trigger the notification."; -$string['selectminutes'] = 'in minutes:'; -$string['selectplugin'] = 'Select the plugin type:'; -$string['selectplugin_help'] = "Select a plugin that you are interested in monitoring. The event list below would be updated to display events from the selected plugin."; $string['subareyousure'] = 'Are you sure you want to delete this subscription for the rule "{$a}"?'; $string['subcreatesuccess'] = "Subscription successfully created"; $string['subdeletesuccess'] = "Subscription successfully removed"; $string['subhelp'] = 'Subscription details'; $string['subhelp_help'] = 'This subscription listens for when the event \'{$a->eventname}\' has been triggered in \'{$a->moduleinstance}\' {$a->frequency} time(s) in {$a->minutes} minute(s).'; $string['subscribeto'] = 'Subscribe to rule "{$a}"'; -$string['system'] = "System"; $string['taskcleanevents'] = 'Removes any unnecessary event monitor events'; -$string['title'] = '{$a->coursename} : {$a->reportname}'; -$string['monitor:managerules'] = 'Manage event monitor rules'; -$string['monitor:subscribe'] = 'Subscribe to event monitor rules'; $string['unsubscribe'] = 'Unsubscribe'; diff --git a/admin/tool/monitor/managerules.php b/admin/tool/monitor/managerules.php index d86a308e0f6..8a664b0f945 100644 --- a/admin/tool/monitor/managerules.php +++ b/admin/tool/monitor/managerules.php @@ -47,16 +47,11 @@ if (empty($courseid)) { require_capability('tool/monitor:managerules', $context); // Set up the page. -$a = new stdClass(); -$a->coursename = $coursename; -$a->reportname = get_string('pluginname', 'tool_monitor'); -$title = get_string('title', 'tool_monitor', $a); $manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid)); - $PAGE->set_url($manageurl); $PAGE->set_pagelayout('report'); -$PAGE->set_title($title); -$PAGE->set_heading($title); +$PAGE->set_title($coursename); +$PAGE->set_heading($coursename); // Site level report. if (empty($courseid)) { @@ -106,6 +101,8 @@ if (!empty($action) && $ruleid) { echo $OUTPUT->header(); } +echo $OUTPUT->heading(get_string('managerules', 'tool_monitor')); + // Render the rule list. $renderable = new \tool_monitor\output\managerules\renderable('toolmonitorrules', $manageurl, $courseid); $renderer = $PAGE->get_renderer('tool_monitor', 'managerules'); From 8ad2de40b19d440c0970d2c10a0dd362993cabcf Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 30 Oct 2014 18:05:44 -0700 Subject: [PATCH 4/4] MDL-47361 tool_monitor: altered behat tests so they pass --- admin/tool/monitor/tests/behat/rule.feature | 242 +++++++++--------- .../monitor/tests/behat/subscription.feature | 198 +++++++------- 2 files changed, 220 insertions(+), 220 deletions(-) diff --git a/admin/tool/monitor/tests/behat/rule.feature b/admin/tool/monitor/tests/behat/rule.feature index b0d19b58d5c..14581338fda 100644 --- a/admin/tool/monitor/tests/behat/rule.feature +++ b/admin/tool/monitor/tests/behat/rule.feature @@ -14,148 +14,148 @@ Feature: tool_monitor_rule And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - And I press "Add a new rule" - And I set the following fields to these values: - | name | New rule course level | - | plugin | Forum | - | eventname | Post created | - | id_description | I want a rule to monitor posts created on a forum | - | frequency | 1 | - | minutes | 1 | - | Message template | The forum post was created. {modulelink} | - And I press "Save changes" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - And I press "Add a new rule" - And I set the following fields to these values: - | name | New rule site level | - | plugin | Forum | - | eventname | Post created | - | id_description | I want a rule to monitor posts created on a forum | - | frequency | 1 | - | minutes | 1 | - | Message template | The forum post was created. {modulelink} | - And I press "Save changes" - And I log out + And I log in as "admin" + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + And I press "Add a new rule" + And I set the following fields to these values: + | name | New rule course level | + | plugin | Forum | + | eventname | Post created | + | id_description | I want a rule to monitor posts created on a forum | + | frequency | 1 | + | minutes | 1 | + | Notification message | The forum post was created. {modulelink} | + And I press "Save changes" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + And I press "Add a new rule" + And I set the following fields to these values: + | name | New rule site level | + | plugin | Forum | + | eventname | Post created | + | id_description | I want a rule to monitor posts created on a forum | + | frequency | 1 | + | minutes | 1 | + | Notification message | The forum post was created. {modulelink} | + And I press "Save changes" + And I log out Scenario: Add a rule on course level Given I log in as "teacher1" - And I am on homepage - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - When I press "Add a new rule" - And I set the following fields to these values: - | name | New rule | - | plugin | Forum | - | eventname | Post created | - | id_description | I want a rule to monitor posts created on a forum | - | frequency | 1 | - | minutes | 1 | - | Message template | The forum post was created. {modulelink} | - And I press "Save changes" - Then "New rule" row "Context" column of "toolmonitorrules_table" table should contain "Course" - And I should see "I want a rule to monitor posts created on a forum" - And I should see "Forum" - And I should see "Post created" - And I should see "1 times in 1 minutes" + And I am on homepage + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + When I press "Add a new rule" + And I set the following fields to these values: + | name | New rule | + | plugin | Forum | + | eventname | Post created | + | id_description | I want a rule to monitor posts created on a forum | + | frequency | 1 | + | minutes | 1 | + | Notification message | The forum post was created. {modulelink} | + And I press "Save changes" + Then "New rule" row "Course" column of "toolmonitorrules_table" table should contain "Course 1" + And I should see "I want a rule to monitor posts created on a forum" + And I should see "Forum" + And I should see "Post created" + And I should see "1 time(s) in 1 minute(s)" Scenario: Delete a rule on course level Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - When I click on "Delete rule" "link" - Then I should see "Are you sure you want to delete rule \"New rule course level\"?" - And I press "Continue" - And I should see "Rule successfully deleted" - And I should not see "New rule course level" + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + When I click on "Delete rule" "link" + Then I should see "Are you sure you want to delete rule \"New rule course level\"?" + And I press "Continue" + And I should see "Rule successfully deleted" + And I should not see "New rule course level" Scenario: Edit a rule on course level Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - When I click on "Edit rule" "link" - And I set the following fields to these values: - | name | New rule quiz | - | plugin | Quiz | - | eventname | Quiz attempt deleted | - | id_description | I want a rule to monitor quiz attempts deleted | - | frequency | 5 | - | minutes | 5 | - | Message template | Quiz attempt deleted. {modulelink} | - And I press "Save changes" - Then I should see "New rule quiz" - And I should see "I want a rule to monitor quiz attempts deleted" - And I should see "Quiz attempt deleted" - And I should see "5 times in 5 minutes" + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + When I click on "Edit rule" "link" + And I set the following fields to these values: + | name | New rule quiz | + | plugin | Quiz | + | eventname | Quiz attempt deleted | + | id_description | I want a rule to monitor quiz attempts deleted | + | frequency | 5 | + | minutes | 5 | + | Notification message | Quiz attempt deleted. {modulelink} | + And I press "Save changes" + Then I should see "New rule quiz" + And I should see "I want a rule to monitor quiz attempts deleted" + And I should see "Quiz attempt deleted" + And I should see "5 time(s) in 5 minute(s)" Scenario: Duplicate a rule on course level Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - When I click on "Duplicate rule" "link" - Then I should see "Rule successfully duplicated" - And "#toolmonitorrules_r1" "css_element" should appear before "#toolmonitorrules_r2" "css_element" - And I should see "New rule" - And I should see "I want a rule to monitor posts created on a forum" - And I should see "Forum" - And I should see "Post created" - And I should see "1 times in 1 minutes" + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + When I click on "Duplicate rule" "link" + Then I should see "Rule successfully duplicated" + And "#toolmonitorrules_r1" "css_element" should appear before "#toolmonitorrules_r2" "css_element" + And I should see "New rule" + And I should see "I want a rule to monitor posts created on a forum" + And I should see "Forum" + And I should see "Post created" + And I should see "1 time(s) in 1 minute(s)" Scenario: Add a rule on site level Given I log in as "admin" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - When I press "Add a new rule" - And I set the following fields to these values: - | name | New rule | - | plugin | Forum | - | eventname | Post created | - | id_description | I want a rule to monitor posts created on a forum | - | frequency | 1 | - | minutes | 1 | - | Message template | The forum post was created. {modulelink} | - And I press "Save changes" - Then "New rule" row "Context" column of "toolmonitorrules_table" table should contain "System" - And I should see "I want a rule to monitor posts created on a forum" - And I should see "Forum" - And I should see "Post created" - And I should see "1 times in 1 minutes" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + When I press "Add a new rule" + And I set the following fields to these values: + | name | New rule | + | plugin | Forum | + | eventname | Post created | + | id_description | I want a rule to monitor posts created on a forum | + | frequency | 1 | + | minutes | 1 | + | Notification message | The forum post was created. {modulelink} | + And I press "Save changes" + Then "New rule" row "Course" column of "toolmonitorrules_table" table should contain "Site" + And I should see "I want a rule to monitor posts created on a forum" + And I should see "Forum" + And I should see "Post created" + And I should see "1 time(s) in 1 minute(s)" Scenario: Delete a rule on site level Given I log in as "admin" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - When I click on "Delete rule" "link" - Then I should see "Are you sure you want to delete rule \"New rule site level\"?" - And I press "Continue" - And I should see "Rule successfully deleted" - And I should not see "New rule site level" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + When I click on "Delete rule" "link" + Then I should see "Are you sure you want to delete rule \"New rule site level\"?" + And I press "Continue" + And I should see "Rule successfully deleted" + And I should not see "New rule site level" Scenario: Edit a rule on site level Given I log in as "admin" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - When I click on "Edit rule" "link" - And I set the following fields to these values: - | name | New Rule Quiz | - | plugin | Quiz | - | eventname | Quiz attempt deleted | - | id_description | I want a rule to monitor quiz attempts deleted | - | frequency | 5 | - | minutes | 5 | - | Message template | Quiz attempt deleted. {modulelink} | - And I press "Save changes" - Then I should see "New Rule Quiz" - And I should see "I want a rule to monitor quiz attempts deleted" - And I should see "Quiz attempt deleted" - And I should see "5 times in 5 minutes" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + When I click on "Edit rule" "link" + And I set the following fields to these values: + | name | New Rule Quiz | + | plugin | Quiz | + | eventname | Quiz attempt deleted | + | id_description | I want a rule to monitor quiz attempts deleted | + | frequency | 5 | + | minutes | 5 | + | Notification message | Quiz attempt deleted. {modulelink} | + And I press "Save changes" + Then I should see "New Rule Quiz" + And I should see "I want a rule to monitor quiz attempts deleted" + And I should see "Quiz attempt deleted" + And I should see "5 time(s) in 5 minute(s)" Scenario: Duplicate a rule on site level Given I log in as "admin" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - When I click on "Duplicate rule" "link" - Then I should see "Rule successfully duplicated" - And "#toolmonitorrules_r2" "css_element" should appear after "#toolmonitorrules_r1" "css_element" - And I should see "I want a rule to monitor posts created on a forum" - And I should see "Forum" - And I should see "Post created" - And I should see "1 times in 1 minutes" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + When I click on "Duplicate rule" "link" + Then I should see "Rule successfully duplicated" + And "#toolmonitorrules_r2" "css_element" should appear after "#toolmonitorrules_r1" "css_element" + And I should see "I want a rule to monitor posts created on a forum" + And I should see "Forum" + And I should see "Post created" + And I should see "1 time(s) in 1 minute(s)" diff --git a/admin/tool/monitor/tests/behat/subscription.feature b/admin/tool/monitor/tests/behat/subscription.feature index 6481d903a92..826cd30b020 100644 --- a/admin/tool/monitor/tests/behat/subscription.feature +++ b/admin/tool/monitor/tests/behat/subscription.feature @@ -14,123 +14,123 @@ Feature: tool_monitor_subscriptions And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I follow "Course 1" - And I navigate to "Event monitoring rules" node in "Course administration > Reports" - And I press "Add a new rule" - And I set the following fields to these values: - | name | New rule course level | - | plugin | Core | - | eventname | Course viewed | - | id_description | I want a rule to monitor when a course is viewed. | - | frequency | 1 | - | minutes | 1 | - | Message template | The course was viewed. {modulelink} | - And I press "Save changes" - And I navigate to "Event monitoring rules" node in "Site administration > Reports" - And I press "Add a new rule" - And I set the following fields to these values: - | name | New rule site level | - | plugin | Core | - | eventname | Course viewed | - | id_description | I want a rule to monitor when a course is viewed. | - | frequency | 1 | - | minutes | 1 | - | Message template | The course was viewed. {modulelink} | - And I press "Save changes" - And I log out + And I log in as "admin" + And I follow "Course 1" + And I navigate to "Event monitoring rules" node in "Course administration > Reports" + And I press "Add a new rule" + And I set the following fields to these values: + | name | New rule course level | + | plugin | Core | + | eventname | Course viewed | + | id_description | I want a rule to monitor when a course is viewed. | + | frequency | 1 | + | minutes | 1 | + | Notification message | The course was viewed. {modulelink} | + And I press "Save changes" + And I navigate to "Event monitoring rules" node in "Site administration > Reports" + And I press "Add a new rule" + And I set the following fields to these values: + | name | New rule site level | + | plugin | Core | + | eventname | Course viewed | + | id_description | I want a rule to monitor when a course is viewed. | + | frequency | 1 | + | minutes | 1 | + | Notification message | The course was viewed. {modulelink} | + And I press "Save changes" + And I log out Scenario: Subscribe to a rule on course level Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Course 1" - When I set the field "Subscribe to rule \"New rule course level\"" to "All events" - Then I should see "Subscription successfully created" - And "#toolmonitorsubs_r0" "css_element" should exist + And I follow "Course 1" + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Course 1" + When I set the field "Subscribe to rule \"New rule course level\"" to "All events" + Then I should see "Subscription successfully created" + And "#toolmonitorsubs_r0" "css_element" should exist Scenario: Delete a subscription on course level Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Course 1" - And I set the field "Subscribe to rule \"New rule course level\"" to "All events" - And I should see "Subscription successfully created" - When I click on "Delete subscription" "link" in the "New rule course level" "table_row" - And I should see "Are you sure you want to delete this subscription for the rule \"New rule course level\"?" - And I press "Continue" - Then I should see "Subscription successfully removed" - And "#toolmonitorsubs_r0" "css_element" should not exist + And I follow "Course 1" + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Course 1" + And I set the field "Subscribe to rule \"New rule course level\"" to "All events" + And I should see "Subscription successfully created" + When I click on "Delete subscription" "link" in the "New rule course level" "table_row" + And I should see "Are you sure you want to delete this subscription for the rule \"New rule course level\"?" + And I press "Continue" + Then I should see "Subscription successfully removed" + And "#toolmonitorsubs_r0" "css_element" should not exist Scenario: Subscribe to a rule on site level Given I log in as "admin" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Site" - When I set the field "Subscribe to rule \"New rule site level\"" to "All events" - Then I should see "Subscription successfully created" - And "#toolmonitorsubs_r0" "css_element" should exist + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Site" + When I set the field "Subscribe to rule \"New rule site level\"" to "All events" + Then I should see "Subscription successfully created" + And "#toolmonitorsubs_r0" "css_element" should exist Scenario: Delete a subscription on site level Given I log in as "admin" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Site" - And I set the field "Subscribe to rule \"New rule site level\"" to "All events" - And I should see "Subscription successfully created" - And "#toolmonitorsubs_r0" "css_element" should exist - When I click on "Delete subscription" "link" in the "New rule site level" "table_row" - And I should see "Are you sure you want to delete this subscription for the rule \"New rule site level\"?" - And I press "Continue" - Then I should see "Subscription successfully removed" - And "#toolmonitorsubs_r0" "css_element" should not exist + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Site" + And I set the field "Subscribe to rule \"New rule site level\"" to "All events" + And I should see "Subscription successfully created" + And "#toolmonitorsubs_r0" "css_element" should exist + When I click on "Delete subscription" "link" in the "New rule site level" "table_row" + And I should see "Are you sure you want to delete this subscription for the rule \"New rule site level\"?" + And I press "Continue" + Then I should see "Subscription successfully removed" + And "#toolmonitorsubs_r0" "css_element" should not exist Scenario: Receiving notification on site level Given I log in as "admin" - And I navigate to "Messaging" node in "My profile settings" - And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element" - And I press "Update profile" - And I am on homepage - And I follow "Course 1" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Site" - And I set the field "Subscribe to rule \"New rule site level\"" to "All events" - And I should see "Subscription successfully created" - And "#toolmonitorsubs_r0" "css_element" should exist - And I am on homepage - And I trigger cron - And I am on homepage - When I navigate to "Messages" node in "My profile" - And I follow "Do not reply to this email (1)" - Then I should see "The course was viewed." + And I navigate to "Messaging" node in "My profile settings" + And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element" + And I press "Update profile" + And I am on homepage + And I follow "Course 1" + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Site" + And I set the field "Subscribe to rule \"New rule site level\"" to "All events" + And I should see "Subscription successfully created" + And "#toolmonitorsubs_r0" "css_element" should exist + And I am on homepage + And I trigger cron + And I am on homepage + When I navigate to "Messages" node in "My profile" + And I follow "Do not reply to this email (1)" + Then I should see "The course was viewed." Scenario: Receiving notification on course level Given I log in as "teacher1" - And I navigate to "Messaging" node in "My profile settings" - And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element" - And I press "Update profile" - And I am on homepage - And I follow "Course 1" - And I navigate to "Event monitoring" node in "My profile settings" - And I set the field "Select a course" to "Course 1" - And I set the field "Subscribe to rule \"New rule course level\"" to "All events" - And I should see "Subscription successfully created" - And "#toolmonitorsubs_r0" "css_element" should exist - And I am on homepage - And I follow "Course 1" - And I trigger cron - And I am on homepage - When I navigate to "Messages" node in "My profile" - And I follow "Do not reply to this email (1)" - Then I should see "The course was viewed." + And I navigate to "Messaging" node in "My profile settings" + And I click on "input[name^=tool_monitor_notification_loggedin]" "css_element" + And I press "Update profile" + And I am on homepage + And I follow "Course 1" + And I navigate to "Event monitoring" node in "My profile settings" + And I set the field "Select a course" to "Course 1" + And I set the field "Subscribe to rule \"New rule course level\"" to "All events" + And I should see "Subscription successfully created" + And "#toolmonitorsubs_r0" "css_element" should exist + And I am on homepage + And I follow "Course 1" + And I trigger cron + And I am on homepage + When I navigate to "Messages" node in "My profile" + And I follow "Do not reply to this email (1)" + Then I should see "The course was viewed." Scenario: Navigating via quick link to rules Given I log in as "admin" - And I navigate to "Event monitoring" node in "My profile settings" - Then I should see "You can manage rules from Event monitoring rules page." - And I follow "Event monitoring rules" - And I should see "Event monitor" - And I should see "You can subscribe to rules from the Event monitoring page." - And I log out - And I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Event monitoring" node in "My profile settings" - Then I should not see "You can manage rules from Event monitoring rules page." + When I navigate to "Event monitoring" node in "My profile settings" + Then I should see "You can manage rules from the Event monitoring rules page." + And I follow "Event monitoring rules" + And I should see "Event monitor" + And I should see "You can subscribe to rules from the Event monitoring page." + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I navigate to "Event monitoring" node in "My profile settings" + And I should see "You can manage rules from the Event monitoring rules page."