Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollover - set dates further into the future #743

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,10 @@ function turnitintooltwo_duplicate_recycle($courseid, $action, $renewdates = nul
$assignment->setEraterHandbook($eraterhandbook);

// Generate the assignment dates depending on whether we are renewing them or not.
$datestart = turnitintooltwo_generate_part_dates($renewdates, "start", $turnitintooltwoassignment->turnitintooltwo, $i);
$datedue = turnitintooltwo_generate_part_dates($renewdates, "due", $turnitintooltwoassignment->turnitintooltwo, $i);
$datepost = turnitintooltwo_generate_part_dates($renewdates, "post", $turnitintooltwoassignment->turnitintooltwo, $i);
// UCL: Added in $currentcourse to turnitintooltwo_generate_part_dates() method,
$datestart = turnitintooltwo_generate_part_dates($renewdates, "start", $turnitintooltwoassignment->turnitintooltwo, $i, $currentcourse);
$datedue = turnitintooltwo_generate_part_dates($renewdates, "due", $turnitintooltwoassignment->turnitintooltwo, $i, $currentcourse);
$datepost = turnitintooltwo_generate_part_dates($renewdates, "post", $turnitintooltwoassignment->turnitintooltwo, $i, $currentcourse);

$assignment->setStartDate($datestart);
$assignment->setDueDate($datedue);
Expand Down Expand Up @@ -552,16 +553,38 @@ function turnitintooltwo_duplicate_recycle($courseid, $action, $renewdates = nul
* @param string $datetype "start", "due" or "post" - Determines the kind of date we need to return.
* @param object $part The assignment in which we need dates for.
* @param int The counter used during the part creation.
* @param stdClass|null $currentcourse - UCL - Added variable for course
* @return int A timestamp for the date we requested.
*/
function turnitintooltwo_generate_part_dates($renewdates, $datetype, $part, $i) {
function turnitintooltwo_generate_part_dates($renewdates, $datetype, $part, $i, $currentcourse = null) {
if ($renewdates) {
switch ($datetype) {
case 'start':
return gmdate("Y-m-d\TH:i:s\Z", time());
// UCL: Changed start date to use course start date, instead of current date.
if (!is_null($currentcourse)) {
return gmdate("Y-m-d\TH:i:s\Z", $currentcourse->startdate);
} else {
return gmdate("Y-m-d\TH:i:s\Z", time());
}
case 'due':
case 'post':
return gmdate("Y-m-d\TH:i:s\Z", strtotime("+1 week"));
// UCL: Changed post/due dates to use course end date, instead of current date.
if (!empty($currentcourse->startdate)) {
if (!empty($currentcourse->enddate)) {
// Using course end date
$enddate = $currentcourse->enddate;
} else {
// Course end date is empty, add one week to start date
$enddate = $currentcourse->startdate + (7 * 24 * 60 * 60);
}
// Make sure the end date used is in the future
if ($enddate < time()) {
$enddate = strtotime("+1 week");
}
return gmdate("Y-m-d\TH:i:s\Z", $enddate);
} else {
return gmdate("Y-m-d\TH:i:s\Z", strtotime("+1 week"));
}
default:
return NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion turnitintooltwo_assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ public function edit_tii_course($course, $coursetype = "TT") {
// account for the Turnitin viewer becoming read-only once the class end date passes.
if (!empty($course->enddate)) {
$enddate = strtotime('+1 month', $course->enddate);
$class->setEndDate(gmdate("Y-m-d\TH:i:s\Z", $enddate));
if ($enddate > time()) {
$class->setEndDate(gmdate("Y-m-d\TH:i:s\Z", $enddate));
}
}

try {
Expand Down