MDL-47892 tool_monitor: disable plugin and event fields if theres subscriptions for the rule

This commit is contained in:
Simey Lameze 2014-10-31 14:41:24 +08:00
parent 32a69a7d7a
commit 107b55bd74
3 changed files with 17 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class rule_form extends \moodleform {
$pluginlist = $this->_customdata['pluginlist'];
$rule = $this->_customdata['rule'];
$courseid = $this->_customdata['courseid'];
$subscriptioncount = $this->_customdata['subscriptioncount'];
// General section header.
$mform->addElement('header', 'general', get_string('general'));
@ -100,6 +101,14 @@ class rule_form extends \moodleform {
$mform->addRule('eventname', get_string('required'), 'required');
$mform->addHelpButton('eventname', 'selectevent', 'tool_monitor');
// Freeze plugin and event fields for editing if there's a subscription for this rule.
if ($subscriptioncount > 0) {
$mform->freeze('plugin');
$mform->setConstant('plugin', $rule->plugin);
$mform->freeze('eventname');
$mform->setConstant('eventname', $rule->eventname);
}
// Description field.
$mform->addElement('editor', 'description', get_string('description', 'tool_monitor'), $editoroptions);
$mform->addHelpButton('description', 'description', 'tool_monitor');

View File

@ -78,12 +78,14 @@ if (empty($courseid)) {
if (!empty($ruleid)) {
$rule = \tool_monitor\rule_manager::get_rule($ruleid)->get_mform_set_data();
$rule->minutes = $rule->timewindow / MINSECS;
$subscriptioncount = \tool_monitor\subscription_manager::count_rule_subscriptions($ruleid);
} else {
$rule = new stdClass();
$subscriptioncount = 0;
}
$mform = new tool_monitor\rule_form(null, array('eventlist' => $eventlist, 'pluginlist' => $pluginlist, 'rule' => $rule,
'courseid' => $courseid));
'courseid' => $courseid, 'subscriptioncount' => $subscriptioncount));
if ($mformdata = $mform->get_data()) {
$rule = \tool_monitor\rule_manager::clean_ruledata_form($mformdata);
@ -98,6 +100,10 @@ if ($mformdata = $mform->get_data()) {
} else {
echo $OUTPUT->header();
$mform->set_data($rule);
// If there's any subscription for this rule, display an information message.
if ($subscriptioncount > 0) {
echo $OUTPUT->notification(get_string('disablefieldswarning', 'tool_monitor'), 'notifyproblem');
}
$mform->display();
echo $OUTPUT->footer();
}

View File

@ -37,6 +37,7 @@ $string['defaultmessagetpl'] = 'Rule "{rulename}" has happened. You can find fur
$string['deleterule'] = 'Delete rule';
$string['deletesubscription'] = 'Delete subscription';
$string['description'] = 'Description:';
$string['disablefieldswarning'] = 'Plugin and events fields can not be edited because this rule already has subscriptions.';
$string['duplicaterule'] = 'Duplicate rule';
$string['editrule'] = 'Edit rule';
$string['eventnotfound'] = 'Event not found';