Permalink
Browse files

Merge branch 'w41_MDL-28980_m24_expirywarning' of git://github.com/sk…

…odak/moodle
  • Loading branch information...
2 parents 2beba29 + 70cae08 commit 49b1c61e5edba7dcc79a1c1d37f6687a659c17f0 @stronk7 stronk7 committed Oct 9, 2012
@@ -42,7 +42,7 @@
if ($options['help']) {
$help =
- "Execute manual enrolments expiration sync.
+ "Execute manual enrolments expiration sync and send notifications.
Options:
-v, --verbose Print verbose progress information
@@ -62,4 +62,6 @@
$result = $plugin->sync(null, $verbose);
+$plugin->send_notifications($verbose);
+
exit($result);
@@ -0,0 +1,29 @@
+<?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/>.
+
+/**
+ * Defines message providers for manual enrolments.
+ *
+ * @package enrol_manual
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$messageproviders = array (
+
+ 'expiry_notification' => array(),
+
+);
@@ -0,0 +1,44 @@
+<?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 file keeps track of upgrades to the manual enrolment plugin
+ *
+ * @package enrol_manual
+ * @copyright 2012 Petr Skoda {@link http://skodak.org
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+function xmldb_enrol_manual_upgrade($oldversion) {
+ global $CFG, $DB, $OUTPUT;
+
+ $dbman = $DB->get_manager();
+
+ // Moodle v2.3.0 release upgrade line
+ // Put any upgrade step following this
+
+ if ($oldversion < 2012100702) {
+ // Set default expiry threshold to 1 day.
+ $DB->execute("UPDATE {enrol} SET expirythreshold = 86400 WHERE enrol = 'manual' AND expirythreshold = 0");
+ upgrade_plugin_savepoint(true, 2012100702, 'enrol', 'manual');
+ }
+
+ return true;
+}
+
+
View
@@ -52,36 +52,64 @@
$plugin->delete_instance($del);
}
}
+ // Merge these two settings to one value for the single selection element.
+ if ($instance->notifyall and $instance->expirynotify) {
+ $instance->expirynotify = 2;
+ }
+ unset($instance->notifyall);
+
} else {
require_capability('moodle/course:enrolconfig', $context);
// No instance yet, we have to add new instance.
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
$instance = new stdClass();
- $instance->id = null;
- $instance->courseid = $course->id;
+ $instance->id = null;
+ $instance->courseid = $course->id;
+ $instance->expirynotify = $plugin->get_config('expirynotify');
+ $instance->expirythreshold = $plugin->get_config('expirythreshold');
}
-$mform = new enrol_manual_edit_form(NULL, array($instance, $plugin, $context));
+$mform = new enrol_manual_edit_form(null, array($instance, $plugin, $context));
if ($mform->is_cancelled()) {
redirect($return);
} else if ($data = $mform->get_data()) {
+ if ($data->expirynotify == 2) {
+ $data->expirynotify = 1;
+ $data->notifyall = 1;
+ } else {
+ $data->notifyall = 0;
+ }
+ if (!$data->expirynotify) {
+ // Keep previous/default value of disabled expirythreshold option.
+ $data->expirythreshold = $instance->expirythreshold;
+ }
if ($instance->id) {
- $reset = ($instance->status != $data->status);
+ $instance->roleid = $data->roleid;
+ $instance->enrolperiod = $data->enrolperiod;
+ $instance->expirynotify = $data->expirynotify;
+ $instance->notifyall = $data->notifyall;
+ $instance->expirythreshold = $data->expirythreshold;
+ $instance->timemodified = time();
- $instance->status = $data->status;
- $instance->enrolperiod = $data->enrolperiod;
- $instance->roleid = $data->roleid;
- $instance->timemodified = time();
$DB->update_record('enrol', $instance);
- if ($reset) {
+ // Use standard API to update instance status.
+ if ($instance->status != $data->status) {
+ $instance = $DB->get_record('enrol', array('id'=>$instance->id));
+ $plugin->update_status($instance, $data->status);
$context->mark_dirty();
}
} else {
- $fields = array('status'=>$data->status, 'enrolperiod'=>$data->enrolperiod, 'roleid'=>$data->roleid);
+ $fields = array(
+ 'status' => $data->status,
+ 'roleid' => $data->roleid,
+ 'enrolperiod' => $data->enrolperiod,
+ 'expirynotify' => $data->expirynotify,
+ 'notifyall' => $data->notifyall,
+ 'expirythreshold' => $data->expirythreshold);
$plugin->add_instance($course, $fields);
}
View
@@ -42,10 +42,6 @@ function definition() {
$mform->addHelpButton('status', 'status', 'enrol_manual');
$mform->setDefault('status', $plugin->get_config('status'));
- $mform->addElement('duration', 'enrolperiod', get_string('defaultperiod', 'enrol_manual'), array('optional' => true, 'defaultunit' => 86400));
- $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
- $mform->addHelpButton('enrolperiod', 'defaultperiod', 'enrol_manual');
-
if ($instance->id) {
$roles = get_default_enrol_roles($context, $instance->roleid);
} else {
@@ -54,10 +50,34 @@ function definition() {
$mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles);
$mform->setDefault('roleid', $plugin->get_config('roleid'));
+ $mform->addElement('duration', 'enrolperiod', get_string('defaultperiod', 'enrol_manual'), array('optional' => true, 'defaultunit' => 86400));
+ $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
+ $mform->addHelpButton('enrolperiod', 'defaultperiod', 'enrol_manual');
+
+ $options = array(0 => get_string('no'), 1 => get_string('expirynotifyteacher', 'enrol_manual'), 2 => get_string('expirynotifyall', 'enrol_manual'));
+ $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'enrol_manual'), $options);
+ $mform->addHelpButton('expirynotify', 'expirynotify', 'enrol_manual');
+
+ $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'enrol_manual'), array('optional' => false, 'defaultunit' => 86400));
+ $mform->addHelpButton('expirythreshold', 'expirythreshold', 'enrol_manual');
+ $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0);
+
$mform->addElement('hidden', 'courseid');
$this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
$this->set_data($instance);
}
+
+ function validation($data, $files) {
+ global $DB;
+
+ $errors = parent::validation($data, $files);
+
+ if ($data['expirynotify'] > 0 and $data['expirythreshold'] < 86400) {
+ $errors['expirythreshold'] = get_string('errorthresholdlow', 'enrol_manual');
+ }
+
+ return $errors;
+ }
}
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -16,10 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Strings for component 'enrol_manual', language 'en', branch 'MOODLE_20_STABLE'
+ * Strings for component 'enrol_manual', language 'en'.
*
- * @package enrol
- * @subpackage manual
+ * @package enrol_manual
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -37,13 +35,35 @@
$string['editselectedusers'] = 'Edit selected user enrolments';
$string['enrolledincourserole'] = 'Enrolled in "{$a->course}" as "{$a->role}"';
$string['enrolusers'] = 'Enrol users';
+$string['errorthresholdlow'] = 'Notification threshold must be at least 1 day.';
$string['expiredaction'] = 'Enrolment expiration action';
$string['expiredaction_help'] = 'Select action to carry out when user enrolment expires. Please note that some user data and settings are purged from course during course unenrolment.';
+$string['expirymessageenrollersubject'] = 'Enrolment expiry notification';
+$string['expirymessageenrollerbody'] = 'Enrolment in the course \'{$a->course}\' will expire within the next {$a->threshold} for the following users:
+
+{$a->users}
+
+To extend their enrolment, go to {$a->extendurl}';
+$string['expirymessageenrolledsubject'] = 'Enrolment expiry notification';
+$string['expirymessageenrolledbody'] = 'Dear {$a->user},
+
+This is a notification that your enrolment in the course \'{$a->course}\' is due to expire on {$a->timeend}.
+
+If you need help, please contact {$a->enroller}.';
+$string['expirynotify'] = 'Notify before enrolment expires';
+$string['expirynotify_help'] = 'This setting determines whether enrolment expiry notification messages are sent.';
+$string['expirynotifyall'] = 'Enroller and enrolled user';
+$string['expirynotifyteacher'] = 'Enroller only';
+$string['expirythreshold'] = 'Notification threshold';
+$string['expirythreshold_help'] = 'This setting specifies the number of days before enrolment expiry that a notification message is sent.';
+$string['expirythreshold_help'] = 'How long before expiration should be users notified?';
$string['manual:config'] = 'Configure manual enrol instances';
$string['manual:enrol'] = 'Enrol users';
$string['manual:manage'] = 'Manage user enrolments';
$string['manual:unenrol'] = 'Unenrol users from the course';
$string['manual:unenrolself'] = 'Unenrol self from the course';
+$string['messageprovider:expiry_notification'] = 'Manual enrolment expiry notifications';
+$string['notifyhour'] = 'Hour to send enrolment expiry notifications';
$string['pluginname'] = 'Manual enrolments';
$string['pluginname_desc'] = 'The manual enrolments plugin allows users to be enrolled manually via a link in the course administration settings, by a user with appropriate permissions such as a teacher. The plugin should normally be enabled, since certain other enrolment plugins, such as self enrolment, require it.';
$string['status'] = 'Enable manual enrolments';
Oops, something went wrong.

0 comments on commit 49b1c61

Please sign in to comment.