Skip to content

Commit

Permalink
Changes for improved incomplete date support
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill committed Apr 19, 2020
1 parent f32c9f2 commit 7e5ab72
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 21 deletions.
2 changes: 1 addition & 1 deletion amd/build/page_info.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/row_control.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions amd/src/page_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ define([], function() {
this.failGrades = failGrades;
this.incompleteGrades = incompleteGrades;
this.defaultIncomplete = defaultIncomplete;
this.incompleteDeadlineDates = {start: new Date(deadlineDates.start),

var start = deadlineDates.start;
if (start !== false) {
start = new Date(start);
}
var end = deadlineDates.end;
if (end !== false) {
end = new Date(end);
}

this.incompleteDeadlineDates = {start: start,
userstart: deadlineDates.userstart,
end: new Date(deadlineDates.end),
end: end,
userend: deadlineDates.userend};
this.lastAttendDates = {start: new Date(lastAttendDates.start),
userstart: lastAttendDates.userstart,
Expand Down Expand Up @@ -72,13 +82,14 @@ define([], function() {
},

isAllowedIncompleteDeadline: function(value) {
var date = new Date(value);
var date = new Date(value).getTime();
var st = this.incompleteDeadlineDates.start.getTime();

if (date < this.incompleteDeadlineDates.start) {
if ((this.incompleteDeadlineDates.start !== false) && (date < st)) {
return false;
}

if (date > this.incompleteDeadlineDates.end) {
if ((this.incompleteDeadlineDates.end !== false) && (date > this.incompleteDeadlineDates.end.getTime())) {
return false;
}

Expand All @@ -104,6 +115,20 @@ define([], function() {
end: this.lastAttendDates.userend};
},

getIncompleteDeadlineStringName: function() {
if (this.incompleteDeadlineDates.start === false) {
return 'invalid_incomplete_date_end';
}
if (this.incompleteDeadlineDates.end === false) {
return 'invalid_incomplete_date_start';
}
if (this.incompleteDeadlineDates.start.getTime() === this.incompleteDeadlineDates.end.getTime()) {
return 'invalid_incomplete_date_single';
}

return 'invalid_incomplete_date_range';
},

getStringIncompleteDeadline: function() {
return {start: this.incompleteDeadlineDates.userstart,
end: this.incompleteDeadlineDates.userend};
Expand Down
3 changes: 3 additions & 0 deletions amd/src/row_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ define(['jquery', 'gradeexport_ilp_push/page_info', 'core/ajax', 'core/notificat
errorCode = 'invalid_incomplete_date';
}

if (errorCode != '') {
errorCode = pageInfo.getIncompleteDeadlineStringName();
}
RowController.updateFormWarning(row, '.incompletedateerror', errorCode, pageInfo.getStringIncompleteDeadline());

var incompleteSelect = row.find('.incompletegradeselect').eq(0);
Expand Down
56 changes: 44 additions & 12 deletions classes/banner_grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use stdClass;
use gradeexport_ilp_push\local\data\grade_mode;
use gradeexport_ilp_push\local\sis_interface;

/**
* Deals with the interaction of banner grading.
Expand Down Expand Up @@ -219,30 +220,61 @@ public static function get_allowed_last_attend_dates($course, $format = false, $
return $dates;
}

/**
* Return the earliest and latest valid incomplete dates for the provided course.
*
* @param object $course The course object to reference.
* @param string $format The strftime format string to use.
* @param int $tz The timezone number to use.
* @return object The return object with keys of 'start' and 'end' timestamps.
* Start set to 'false' will indicate before end (inclusive)
* End set to 'false' will indicate after start (inclusive)
*/
public static function get_allowed_last_incomplete_deadline_dates($course, $format = false, $tz = 99) {
$dates = new stdClass();
$sis = sis_interface\factory::instance();

if (empty($course->enddate)) {
// We just have to guess. TODO better.
$courseend = $course->startdate + (3600 * 24 * 7 * 16);
} else {
$courseend = $course->enddate;
// First see if there are SIS dates.
$dates = $sis->get_allowed_last_incomplete_deadline_dates($course);

// If that didn't return anything, then get settings date.
if ($dates === false) {
$dates = new stdClass();

// Temp placeholder for 4/27/2020.
$dates->start = 1587988800;
$dates->end = 1587988800;
}

// The day after the end of the course is the first allowed date (I think TODO).
$courseend += 3600 * 24;
// If we still don't have dates, we are going to make them up.
if ($dates === false) {
$dates = new stdClass();

if (empty($course->enddate)) {
// We just have to guess. TODO better.
$courseend = $course->startdate + (3600 * 24 * 7 * 16);
} else {
$courseend = $course->enddate;
}

// The day after the end of the course is the first allowed date (I think TODO).
$courseend += 3600 * 24;

$dates->start = $courseend;
$dates->start = $courseend;

$dates->end = $courseend + (3600 * 24 * 380);
$dates->end = $courseend + (3600 * 24 * 380);
}

if (!$format) {
return $dates;
}

// Convert to a format.
$dates->start = date_format_string($dates->start, $format, $tz);
$dates->end = date_format_string($dates->end, $format, $tz);
if ($dates->start !== false) {
$dates->start = date_format_string($dates->start, $format, $tz);
}
if ($dates->end !== false) {
$dates->end = date_format_string($dates->end, $format, $tz);
}

return $dates;
}
Expand Down
14 changes: 14 additions & 0 deletions classes/local/sis_interface/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public function teacher_allowed_to_grade_course($user, $course) {
return true;
}

/**
* A function that allows the SIS to override the allowed incomplete dates for a course.
*
* Override to implement.
*
* @param object $course The course object to reference.
* @return object The return object with keys of 'start' and 'end' timestamps.
* Start set to 'false' will indicate before end (inclusive)
* End set to 'false' will indicate after start (inclusive)
*/
public function get_allowed_last_incomplete_deadline_dates($course) {
return false;
}

}


5 changes: 3 additions & 2 deletions classes/rule_validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ public static function validate_row(saved_grade $grade, grade_exporter $exporter
if (is_null($grade->incompletedeadline)) {
// TODO - this might not be required...
$results['errors']['incompletedeadline'] = get_string('invalid_incomplete_date_missing', 'gradeexport_ilp_push');
} else if ($grade->incompletedeadline < $incompletedeadline->start) {
} else if (($incompletedeadline->start !== false) && ($grade->incompletedeadline < $incompletedeadline->start)) {
// If present, the incomplete date must be within a certain timeline (settings dependent).
// TODO better date ranges and error messages...
$results['errors']['incompletedeadline'] = get_string('invalid_incomplete_date_early', 'gradeexport_ilp_push');
} else if ($grade->incompletedeadline > $incompletedeadline->end) {
} else if (($incompletedeadline->end !== false) && ($grade->incompletedeadline > $incompletedeadline->end)) {
$results['errors']['incompletedeadline'] = get_string('invalid_incomplete_date_late', 'gradeexport_ilp_push');
}

}

return $results;
Expand Down
8 changes: 8 additions & 0 deletions classes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class settings {

protected $settings = null;

protected $termid = null;

protected $termsettings = null;

/**
* A static factory for the settings object.
*
Expand All @@ -54,6 +58,10 @@ public static function get_settings() {
return static::$settingobj;
}

protected function set_term_id($termid) {

}

protected function __construct() {
$this->settings = get_config('gradeexport_ilp_push');
}
Expand Down
Loading

0 comments on commit 7e5ab72

Please sign in to comment.