Skip to content

Commit

Permalink
MDL-35843 prepare fox expiry refactoring to core enrol feature
Browse files Browse the repository at this point in the history
AMOS BEGIN
  MOV [errorthresholdlow,enrol_manual],[errorthresholdlow,core_enrol]
  MOV [expirynotify,enrol_manual],[expirynotify,core_enrol]
  MOV [expirynotify_help,enrol_manual],[expirynotify_help,core_enrol]
  MOV [expirynotifyall,enrol_manual],[expirynotifyall,core_enrol]
  MOV [expirynotifyteacher,enrol_manual],[expirynotifyenroller,core_enrol]
  MOV [notifyhour,enrol_manual],[expirynotifyhour,core_enrol]
  MOV [expirythreshold,enrol_manual],[expirythreshold,core_enrol]
  MOV [expirythreshold_help,enrol_manual],[expirythreshold_help,core_enrol]
AMOS END
  • Loading branch information
skodak committed Oct 19, 2012
1 parent 7e8ae12 commit 8e94120
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 58 deletions.
2 changes: 1 addition & 1 deletion enrol/manual/cli/sync.php
Expand Up @@ -63,6 +63,6 @@

$result = $plugin->sync(null, $verbose);

$plugin->send_notifications($verbose);
$plugin->send_expiry_notifications($verbose);

exit($result);
8 changes: 8 additions & 0 deletions enrol/manual/db/upgrade.php
Expand Up @@ -38,6 +38,14 @@ function xmldb_enrol_manual_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2012100702, 'enrol', 'manual');
}

if ($oldversion < 2012101400) {
// Delete obsoleted settings, now using expiry* prefix to make them more consistent.
unset_config('notifylast', 'enrol_manual');
unset_config('notifyhour', 'enrol_manual');
upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'manual');
}


return true;
}

Expand Down
12 changes: 6 additions & 6 deletions enrol/manual/edit_form.php
Expand Up @@ -54,12 +54,12 @@ function definition() {
$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');
$options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
$mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options);
$mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol');

$mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'enrol_manual'), array('optional' => false, 'defaultunit' => 86400));
$mform->addHelpButton('expirythreshold', 'expirythreshold', 'enrol_manual');
$mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), array('optional' => false, 'defaultunit' => 86400));
$mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol');
$mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0);

$mform->addElement('hidden', 'courseid');
Expand All @@ -75,7 +75,7 @@ function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['expirynotify'] > 0 and $data['expirythreshold'] < 86400) {
$errors['expirythreshold'] = get_string('errorthresholdlow', 'enrol_manual');
$errors['expirythreshold'] = get_string('errorthresholdlow', 'core_enrol');
}

return $errors;
Expand Down
9 changes: 0 additions & 9 deletions enrol/manual/lang/en/enrol_manual.php
Expand Up @@ -35,7 +35,6 @@
$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';
Expand All @@ -50,20 +49,12 @@
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';
Expand Down
16 changes: 8 additions & 8 deletions enrol/manual/lib.php
Expand Up @@ -280,7 +280,7 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {
*/
public function cron() {
$this->sync(null, true);
$this->send_notifications(true);
$this->send_expiry_notifications(true);
}

/**
Expand Down Expand Up @@ -380,7 +380,7 @@ public function sync($courseid = null, $verbose = false) {
*
* @param bool $verbose verbose CLI output
*/
public function send_notifications($verbose = false) {
public function send_expiry_notifications($verbose = false) {
global $DB, $CFG;

// Unfortunately this may take a long time, it should not be interrupted,
Expand All @@ -389,15 +389,15 @@ public function send_notifications($verbose = false) {
@set_time_limit(0);
raise_memory_limit(MEMORY_HUGE);

$notifylast = $this->get_config('notifylast', 0);
$notifyhour = $this->get_config('notifyhour', 6);
$expirynotifylast = $this->get_config('expirynotifylast', 0);
$expirynotifyhour = $this->get_config('expirynotifyhour', 6);
$timenow = time();

$notifytime = usergetmidnight($timenow, $CFG->timezone) + ($notifyhour * 3600);
$notifytime = usergetmidnight($timenow, $CFG->timezone) + ($expirynotifyhour * 3600);

if ($notifylast > $notifytime) {
if ($expirynotifylast > $notifytime) {
if ($verbose) {
mtrace('Manual enrolment notifications were already sent today at '.userdate($notifylast, '', $CFG->timezone).'.');
mtrace('Manual enrolment notifications were already sent today at '.userdate($expirynotifylast, '', $CFG->timezone).'.');
}
return;
} else if ($timenow < $notifytime) {
Expand Down Expand Up @@ -463,7 +463,7 @@ public function send_notifications($verbose = false) {
if ($verbose) {
mtrace('...notification processing finished.');
}
$this->set_config('notifylast', $timenow);
$this->set_config('expirynotifylast', $timenow);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions enrol/manual/settings.php
Expand Up @@ -42,7 +42,7 @@
for ($i=0; $i<24; $i++) {
$options[$i] = $i;
}
$settings->add(new admin_setting_configselect('enrol_manual/notifyhour', get_string('notifyhour', 'enrol_manual'), '', 6, $options));
$settings->add(new admin_setting_configselect('enrol_manual/expirynotifyhour', get_string('expirynotifyhour', 'core_enrol'), '', 6, $options));


//--- enrol instance defaults ----------------------------------------------------------------------------
Expand All @@ -68,11 +68,11 @@
$settings->add(new admin_setting_configduration('enrol_manual/enrolperiod',
get_string('defaultperiod', 'enrol_manual'), get_string('defaultperiod_desc', 'enrol_manual'), 0));

$options = array(0 => get_string('no'), 1 => get_string('expirynotifyteacher', 'enrol_manual'), 2 => get_string('expirynotifyall', 'enrol_manual'));
$options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
$settings->add(new admin_setting_configselect('enrol_manual/expirynotify',
get_string('expirynotify', 'enrol_manual'), get_string('expirynotify_help', 'enrol_manual'), 0, $options));
get_string('expirynotify', 'core_enrol'), get_string('expirynotify_help', 'core_enrol'), 0, $options));

$settings->add(new admin_setting_configduration('enrol_manual/expirythreshold',
get_string('expirythreshold', 'enrol_manual'), get_string('expirythreshold_help', 'enrol_manual'), 86400, 86400));
get_string('expirythreshold', 'core_enrol'), get_string('expirythreshold_help', 'core_enrol'), 86400, 86400));

}
18 changes: 9 additions & 9 deletions enrol/manual/tests/lib_test.php
Expand Up @@ -316,8 +316,8 @@ public function test_send_expiry_notifications() {

// Note: hopefully nobody executes the unit tests the last second before midnight...

$manualplugin->set_config('notifylast', $now - 60*60*24);
$manualplugin->set_config('notifyhour', 0);
$manualplugin->set_config('expirynotifylast', $now - 60*60*24);
$manualplugin->set_config('expirynotifyhour', 0);

$studentrole = $DB->get_record('role', array('shortname'=>'student'));
$this->assertNotEmpty($studentrole);
Expand Down Expand Up @@ -394,7 +394,7 @@ public function test_send_expiry_notifications() {

$sink = $this->redirectMessages();

$manualplugin->send_notifications(false);
$manualplugin->send_expiry_notifications(false);

$messages = $sink->get_messages();

Expand Down Expand Up @@ -451,18 +451,18 @@ public function test_send_expiry_notifications() {
// Make sure that notifications are not repeated.
$sink->clear();

$manualplugin->send_notifications(false);
$manualplugin->send_expiry_notifications(false);
$this->assertEquals(0, $sink->count());

// use invalid notification hour to verify that before the hour the notifications are not sent.
$manualplugin->set_config('notifylast', time() - 60*60*24);
$manualplugin->set_config('notifyhour', '24');
$manualplugin->set_config('expirynotifylast', time() - 60*60*24);
$manualplugin->set_config('expirynotifyhour', '24');

$manualplugin->send_notifications(false);
$manualplugin->send_expiry_notifications(false);
$this->assertEquals(0, $sink->count());

$manualplugin->set_config('notifyhour', '0');
$manualplugin->send_notifications(false);
$manualplugin->set_config('expirynotifyhour', '0');
$manualplugin->send_expiry_notifications(false);
$this->assertEquals(6, $sink->count());
}
}
2 changes: 1 addition & 1 deletion enrol/manual/version.php
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2012100705; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2012101400; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012100500; // Requires this Moodle version
$plugin->component = 'enrol_manual'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 600;
8 changes: 8 additions & 0 deletions lang/en/enrol.php
Expand Up @@ -66,7 +66,15 @@
$string['erroreditenrolment'] = 'An error occurred while trying to edit a users enrolment';
$string['errorenrolcohort'] = 'Error creating cohort sync enrolment instance in this course.';
$string['errorenrolcohortusers'] = 'Error enrolling cohort members in this course.';
$string['errorthresholdlow'] = 'Notification threshold must be at least 1 day.';
$string['errorwithbulkoperation'] = 'There was an error while processing your bulk enrolment change.';
$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['expirynotifyenroller'] = 'Enroller only';
$string['expirynotifyhour'] = 'Hour to send enrolment expiry notifications';
$string['expirythreshold'] = 'Notification threshold';
$string['expirythreshold_help'] = 'How long before expiration should be users notified?';
$string['finishenrollingusers'] = 'Finish enrolling users';
$string['invalidenrolinstance'] = 'Invalid enrolment instance';
$string['invalidrole'] = 'Invalid role';
Expand Down
20 changes: 0 additions & 20 deletions lang/en/moodle.php
Expand Up @@ -659,26 +659,6 @@
$string['existingstudents'] = 'Enrolled students';
$string['existingteachers'] = 'Existing teachers';
$string['expandall'] = 'Expand all';
$string['expirynotify'] = 'Enrolment expiry notification';
$string['expirynotifyemail'] = 'The following students in this course are expiring after exactly {$a->threshold} days:
{$a->current}
The following students in this course are expiring in less than {$a->threshold} days:
{$a->past}
You may go to the following page to extend their enrolment period:
{$a->extendurl}';
$string['expirynotifystudents'] = 'Notify students';
$string['expirynotifystudents_help'] = 'If an enrolment duration has been specified, then this setting determines whether students receive email notification when they are about to be unenrolled from the course.';
$string['expirynotifystudentsemail'] = 'Dear {$a->studentstr}:
This is a notification that your enrolment in the course {$a->course} will expire in {$a->threshold} days.
Please contact {$a->teacherstr} for any further enquiries.';
$string['expirythreshold'] = 'Threshold';
$string['expirythreshold_help'] = 'If an enrolment duration has been specified, then this setting determines the number of days notice given before students are unenrolled from the course.';
$string['explanation'] = 'Explanation';
$string['extendenrol'] = 'Extend enrolment (individual)';
$string['extendperiod'] = 'Extended period';
Expand Down

0 comments on commit 8e94120

Please sign in to comment.