MDL-45758 tool_monitor: Add a UI page to manage subscriptions

Original issue - MDL-46111
This commit is contained in:
Ankit Agarwal 2014-09-09 09:52:51 +05:30
parent ac0e4dad7f
commit 044503e33d
2 changed files with 120 additions and 2 deletions

View File

@ -0,0 +1,110 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page lets users to manage rules for a given course.
*
* @package tool_monitor
* @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
$courseid = optional_param('courseid', 0, PARAM_INT);
$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);
// Validate course id.
if (empty($courseid)) {
require_login();
$context = context_system::instance();
$coursename = format_string($SITE->fullname, true, array('context' => $context));
$PAGE->set_context($context);
} else {
$course = get_course($courseid);
require_login($course);
$context = context_course::instance($course->id);
$coursename = format_string($course->fullname, true, array('context' => $context));
}
// Check for caps.
require_capability('tool/monitor:subscribe', $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);
$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);
// Site level report.
if (empty($courseid)) {
admin_externalpage_setup('toolmonitorsubscriptions', '', null, '', array('pagelayout' => 'report'));
}
echo $OUTPUT->header();
// Create/delete subscription if needed.
if (!empty($action)) {
switch ($action) {
case 'subscribe' :
$rule = \tool_monitor\rule_manager::get_rule($ruleid);
$rule->subscribe_user($courseid, $cmid);
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');
break;
default:
}
}
// Render the current subscriptions list.
$totalsubs = \tool_monitor\subscription_manager::count_user_subscriptions_for_course($courseid);
$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 $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'));
if (!empty($totalrules)) {
$rules = new \tool_monitor\output\managesubs\rules('toolmonitorrules', $indexurl, $courseid);
echo $renderer->render($rules);
} else {
// No rules present. Show a link to manage rules page if permissions permit.
echo html_writer::tag('span', get_string('norules', 'tool_monitor'));
if (has_capability('tool/monitor:managerules', $context)) {
$manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid));
$a = html_writer::link($manageurl, get_string('managerules', 'tool_monitor'));
echo html_writer::tag('span', get_string('manageruleslink', 'tool_monitor', $a));
}
}
echo $OUTPUT->footer();

View File

@ -30,13 +30,18 @@ $string['allmodules'] = 'All modules';
$string['core'] = 'Core';
$string['customizefilters'] = 'Select the frequency of the events';
$string['customizemessage'] = 'Cutomize the notification message';
$string['currentsubscriptions'] = 'Your current subscriptions';
$string['description'] = 'Description:';
$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['eventnotfound'] = 'Event not found';
$string['errorincorrectevent'] = 'Please select an event related to the selected plugin';
$string['freqdesc'] = '{$a->freq} times in {$a->mins} minutes';
$string['frequency'] = 'Frequency';
$string['invalidmodule'] = 'Invalid module';
$string['norules'] = 'There are no rules you can subscribe to.';
$string['manageruleslink'] = 'You can manage rules from {$a} page.';
$string['moduleinstance'] = 'Module instance';
$string['manage'] = 'Manage';
$string['managesubscriptions'] = 'Manage subscriptions';
$string['managerules'] = 'Manage rules';
@ -51,14 +56,13 @@ $string['messagetemplate_help'] = 'This is the content of the message that will
$string['minutes'] = 'in minutes:';
$string['name'] = 'Name of the rule: ';
$string['name_help'] = "Choose a name for the rule.";
$string['norules'] = 'There are no rules you can subscribe to.';
$string['manageruleslink'] = 'You can manage rules from {$a} page.';
$string['pluginname'] = 'Event monitor';
$string['processevents'] = 'Process events';
$string['ruleareyousure'] = 'Are you sure you want to delete rule "{$a}"?';
$string['rulecopysuccess'] = 'Rule successfully copied';
$string['ruledeletesuccess'] = 'Rule successfully deleted';
$string['rulenopermissions'] = 'You do not have permissions to "{$a} a rule"';
$string['rulescansubscribe'] = 'Rules you can subscribe to';
$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.";
@ -67,7 +71,11 @@ $string['selectfrequency_help'] = "Frequency defines the denisty of the event oc
$string['selectminutes'] = 'in minutes:';
$string['selectplugin'] = 'Select the plugin type:';
$string['selectplugin_help'] = "Select a plugin that you are interested in monitoring.";
$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['title'] = '{$a->coursename} : {$a->reportname}';
$string['tool/monitor:managerules'] = 'Manage event monitor rules';
$string['tool/monitor:subscribe'] = 'Subscribe to event monitor rules';
$string['unsubscribe'] = 'Unsubscribe';