Skip to content

Commit

Permalink
MDL-61161 course: grace period for classifying in progress courses
Browse files Browse the repository at this point in the history
  • Loading branch information
mackensen committed Sep 25, 2018
1 parent 6902f39 commit 3b31d8c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
5 changes: 4 additions & 1 deletion admin/settings/appearance.php
Expand Up @@ -227,6 +227,10 @@
new lang_string('configcourseoverviewfileslimit', 'admin'), 1, PARAM_INT));
$temp->add(new admin_setting_configtext('courseoverviewfilesext', new lang_string('courseoverviewfilesext'),
new lang_string('configcourseoverviewfilesext', 'admin'), '.jpg,.gif,.png'));
$temp->add(new admin_setting_configtext('coursegraceperiodbefore', new lang_string('coursegraceperiodbefore', 'admin'),
new lang_string('configcoursegraceperiodbefore', 'admin'), 0, PARAM_INT));
$temp->add(new admin_setting_configtext('coursegraceperiodafter', new lang_string('coursegraceperiodafter', 'admin'),
new lang_string('configcoursegraceperiodafter', 'admin'), 0, PARAM_INT));
$ADMIN->add('appearance', $temp);

$temp = new admin_settingpage('ajax', new lang_string('ajaxuse'));
Expand All @@ -252,4 +256,3 @@
$ADMIN->add('appearance', $temp);

} // end of speedup

32 changes: 30 additions & 2 deletions course/lib.php
Expand Up @@ -4066,7 +4066,7 @@ function course_classify_for_timeline($course, $user = null, $completioninfo = n

$today = time();
// End date past.
if (!empty($course->enddate) && $course->enddate < $today) {
if (!empty($course->enddate) && (course_classify_end_date($course) < $today)) {
return COURSE_TIMELINE_PAST;
}

Expand All @@ -4080,14 +4080,42 @@ function course_classify_for_timeline($course, $user = null, $completioninfo = n
}

// Start date not reached.
if (!empty($course->startdate) && $course->startdate > $today) {
if (!empty($course->startdate) && (course_classify_start_date($course) > $today)) {
return COURSE_TIMELINE_FUTURE;
}

// Everything else is in progress.
return COURSE_TIMELINE_INPROGRESS;
}

/**
* This function calculates the end date to use for display classification purposes,
* incorporating the grace period, if any.
*
* @param stdClass $course The course record.
* @return int The new enddate.
*/
function course_classify_end_date($course) {
global $CFG;
$coursegraceperiodafter = (empty($CFG->coursegraceperiodafter)) ? 0 : $CFG->coursegraceperiodafter;
$enddate = (new \DateTimeImmutable())->setTimestamp($course->enddate)->modify("+{$coursegraceperiodafter} days");
return $enddate->getTimestamp();
}

/**
* This function calculates the start date to use for display classification purposes,
* incorporating the grace period, if any.
*
* @param stdClass $course The course record.
* @return int The new startdate.
*/
function course_classify_start_date($course) {
global $CFG;
$coursegraceperiodbefore = (empty($CFG->coursegraceperiodbefore)) ? 0 : $CFG->coursegraceperiodbefore;
$startdate = (new \DateTimeImmutable())->setTimestamp($course->startdate)->modify("-{$coursegraceperiodbefore} days");
return $startdate->getTimestamp();
}

/**
* Check module updates since a given time.
* This function checks for updates in the module config, file areas, completion, grades, comments and ratings.
Expand Down
10 changes: 10 additions & 0 deletions course/tests/courselib_test.php
Expand Up @@ -3807,6 +3807,8 @@ public function test_classify_course_for_timeline() {
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_self.php');

set_config('enablecompletion', COMPLETION_ENABLED);
set_config('coursegraceperiodbefore', 0);
set_config('coursegraceperiodafter', 0);

$this->resetAfterTest(true);
$this->setAdminUser();
Expand Down Expand Up @@ -3847,6 +3849,14 @@ public function test_classify_course_for_timeline() {
$this->assertEquals(COURSE_TIMELINE_FUTURE, course_classify_for_timeline($futurecourse));
$this->assertEquals(COURSE_TIMELINE_PAST, course_classify_for_timeline($completedcourse));
$this->assertEquals(COURSE_TIMELINE_INPROGRESS, course_classify_for_timeline($inprogresscourse));

// Test grace period.
set_config('coursegraceperiodafter', 1);
set_config('coursegraceperiodbefore', 1);
$this->assertEquals(COURSE_TIMELINE_INPROGRESS, course_classify_for_timeline($pastcourse));
$this->assertEquals(COURSE_TIMELINE_INPROGRESS, course_classify_for_timeline($futurecourse));
$this->assertEquals(COURSE_TIMELINE_PAST, course_classify_for_timeline($completedcourse));
$this->assertEquals(COURSE_TIMELINE_INPROGRESS, course_classify_for_timeline($inprogresscourse));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lang/en/admin.php
Expand Up @@ -171,6 +171,8 @@
$string['configcookiehttponly'] = 'Enables new PHP 5.2.0 feature - browsers are instructed to send cookie with real http requests only, cookies should not be accessible by scripting languages. This is not supported in all browsers and it may not be fully compatible with current code. It helps to prevent some types of XSS attacks.';
$string['configcookiesecure'] = 'If server is accepting only https connections it is recommended to enable sending of secure cookies. If enabled please make sure that web server is not accepting http:// or set up permanent redirection to https:// address and ideally send HSTS headers. When <em>wwwroot</em> address does not start with https:// this setting is ignored.';
$string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.';
$string['configcoursegraceperiodafter'] = 'Classify past courses as in progress for these many days after the course end date.';
$string['configcoursegraceperiodbefore'] = 'Classify future courses as in progress for these many days prior to the course start date.';
$string['configcourseoverviewfilesext'] = 'A comma-separated list of allowed course summary files extensions.';
$string['configcourseoverviewfileslimit'] = 'The maximum number of files that can be attached to a course summary.';
$string['configcourserequestnotify'] = 'Type username of user to be notified when new course requested.';
Expand Down Expand Up @@ -380,6 +382,8 @@
$string['country'] = 'Default country';
$string['coursecontact'] = 'Course contacts';
$string['coursecontact_desc'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.';
$string['coursegraceperiodafter'] = 'Grace period for past courses';
$string['coursegraceperiodbefore'] = 'Grace period for future courses';
$string['courselistshortnames'] = 'Display extended course names';
$string['courselistshortnames_desc'] = 'If enabled, course short names will be displayed in addition to full names in course lists. If required, extended course names may be customised by editing the \'courseextendednamedisplay\' language string using the language customisation feature.';
$string['coursemgmt'] = 'Manage courses and categories';
Expand Down

0 comments on commit 3b31d8c

Please sign in to comment.