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');