Skip to content

Commit

Permalink
MDL-30157 enrol_manual: New option to enrol from now
Browse files Browse the repository at this point in the history
We set the new now option as the default one, as other enrol
plugins use it as the default enrolment start date. We are keeping
the default to today on upgrades.
  • Loading branch information
David Monllao committed Sep 15, 2015
1 parent 32f1e17 commit d005d71
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
10 changes: 10 additions & 0 deletions enrol/manual/ajax.php
Expand Up @@ -128,10 +128,20 @@
$roleid = null;
}

if (empty($startdate)) {
if (!$startdate = get_config('enrol_manual', 'enrolstart')) {
// Default to now if there is no system setting.
$startdate = 4;
}
}

switch($startdate) {
case 2:
$timestart = $course->startdate;
break;
case 4:
$timestart = time();
break;
case 3:
default:
$today = time();
Expand Down
6 changes: 6 additions & 0 deletions enrol/manual/db/upgrade.php
Expand Up @@ -66,6 +66,12 @@ function xmldb_enrol_manual_upgrade($oldversion) {
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2015091500) {
// We keep today as default enrolment start time on upgrades.
set_config('enrolstart', 3, 'enrol_manual');
upgrade_plugin_savepoint(true, 2015091500, 'enrol', 'manual');
}

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion enrol/manual/lang/en/enrol_manual.php
Expand Up @@ -29,6 +29,7 @@
$string['browseusers'] = 'Browse users';
$string['browsecohorts'] = 'Browse cohorts';
$string['confirmbulkdeleteenrolment'] = 'Are you sure you want to delete these users enrolments?';
$string['defaultstart'] = 'Default enrolment start';
$string['defaultperiod'] = 'Default enrolment duration';
$string['defaultperiod_desc'] = 'Default length of time that the enrolment is valid. If set to zero, the enrolment duration will be unlimited by default.';
$string['defaultperiod_help'] = 'Default length of time that the enrolment is valid, starting with the moment the user is enrolled. If disabled, the enrolment duration will be unlimited by default.';
Expand Down Expand Up @@ -56,6 +57,7 @@
$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['now'] = 'Now';
$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 All @@ -71,4 +73,4 @@
$string['wscannotenrol'] = 'Plugin instance cannot manually enrol a user in the course id = {$a->courseid}';
$string['wsnoinstance'] = 'Manual enrolment plugin instance doesn\'t exist or is disabled for the course (id = {$a->courseid})';
$string['wsusercannotassign'] = 'You don\'t have the permission to assign this role ({$a->roleid}) to this user ({$a->userid}) in this course({$a->courseid}).';
$string['manualpluginnotinstalled'] = 'The "Manual" plugin has not yet been installed';
$string['manualpluginnotinstalled'] = 'The "Manual" plugin has not yet been installed';
16 changes: 11 additions & 5 deletions enrol/manual/lib.php
Expand Up @@ -226,14 +226,19 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {
$button->class .= ' enrol_manual_plugin';

$startdate = $manager->get_course()->startdate;
if (!$defaultstart = get_config('enrol_manual', 'enrolstart')) {
// Default to now if there is no system setting.
$defaultstart = 4;
}
$startdateoptions = array();
$timeformat = get_string('strftimedatefullshort');
$dateformat = get_string('strftimedatefullshort');
if ($startdate > 0) {
$startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $timeformat) . ')';
$startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $dateformat) . ')';
}
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
$startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
$now = time();
$today = make_timestamp(date('Y', $now), date('m', $now), date('d', $now), 0, 0, 0);
$startdateoptions[3] = get_string('today') . ' (' . userdate($today, $dateformat) . ')';
$startdateoptions[4] = get_string('now', 'enrol_manual') . ' (' . userdate($now, get_string('strftimedatetimeshort')) . ')';
$defaultduration = $instance->enrolperiod > 0 ? $instance->enrolperiod / 86400 : '';

$modules = array('moodle-enrol_manual-quickenrolment', 'moodle-enrol_manual-quickenrolment-skin');
Expand All @@ -245,6 +250,7 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {
'optionsStartDate' => $startdateoptions,
'defaultRole' => $instance->roleid,
'defaultDuration' => $defaultduration,
'defaultStartDate' => (int)$defaultstart,
'disableGradeHistory' => $CFG->disablegradehistory,
'recoverGradesDefault'=> '',
'cohortsAvailable' => cohort_get_available_cohorts($manager->get_context(), COHORT_WITH_NOTENROLLED_MEMBERS_ONLY, 0, 1) ? true : false
Expand Down
24 changes: 17 additions & 7 deletions enrol/manual/manage.php
Expand Up @@ -28,7 +28,7 @@
$enrolid = required_param('enrolid', PARAM_INT);
$roleid = optional_param('roleid', -1, PARAM_INT);
$extendperiod = optional_param('extendperiod', 0, PARAM_INT);
$extendbase = optional_param('extendbase', 3, PARAM_INT);
$extendbase = optional_param('extendbase', 0, PARAM_INT);

$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
Expand Down Expand Up @@ -83,24 +83,31 @@
$seconds = $i * 86400;
$periodmenu[$seconds] = get_string('numdays', '', $i);
}
// Work out the apropriate default setting.
// Work out the apropriate default settings.
if ($extendperiod) {
$defaultperiod = $extendperiod;
} else {
$defaultperiod = $instance->enrolperiod;
}
if (empty($extendbase)) {
if (!$extendbase = get_config('enrol_manual', 'enrolstart')) {
// Default to now if there is no system setting.
$extendbase = 4;
}
}

// Build the list of options for the starting from dropdown.
$timeformat = get_string('strftimedatefullshort');
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
$now = time();
$today = make_timestamp(date('Y', $now), date('m', $now), date('d', $now), 0, 0, 0);
$dateformat = get_string('strftimedatefullshort');

// Enrolment start.
$basemenu = array();
if ($course->startdate > 0) {
$basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
$basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $dateformat) . ')';
}
$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
$basemenu[3] = get_string('today') . ' (' . userdate($today, $dateformat) . ')';
$basemenu[4] = get_string('now', 'enrol_manual') . ' (' . userdate($now, get_string('strftimedatetimeshort')) . ')';

// Process add and removes.
if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
Expand All @@ -111,6 +118,9 @@
case 2:
$timestart = $course->startdate;
break;
case 4:
$timestart = $now;
break;
case 3:
default:
$timestart = $today;
Expand Down
5 changes: 5 additions & 0 deletions enrol/manual/settings.php
Expand Up @@ -66,6 +66,11 @@
get_string('defaultrole', 'role'), '', $student->id, $options));
}

$options = array(2 => get_string('coursestart'), 3 => get_string('today'), 4 => get_string('now', 'enrol_manual'));
$settings->add(
new admin_setting_configselect('enrol_manual/enrolstart', get_string('defaultstart', 'enrol_manual'), '', 4, $options)
);

$settings->add(new admin_setting_configduration('enrol_manual/enrolperiod',
get_string('defaultperiod', 'enrol_manual'), get_string('defaultperiod_desc', 'enrol_manual'), 0));

Expand Down
2 changes: 1 addition & 1 deletion enrol/manual/version.php
Expand Up @@ -24,7 +24,7 @@

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

$plugin->version = 2015051100; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2015091500; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015050500; // Requires this Moodle version
$plugin->component = 'enrol_manual'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 600;
2 changes: 1 addition & 1 deletion enrol/manual/yui/quickenrolment/quickenrolment.js
Expand Up @@ -608,7 +608,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
value : 0
},
defaultStartDate : {
value : 3,
value : 4,
validator : Y.Lang.isNumber
},
defaultDuration : {
Expand Down

0 comments on commit d005d71

Please sign in to comment.