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

Delete old calendar events before creating new ones #786

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1790,3 +1790,21 @@ function turnitintooltwo_update_event($turnitintooltwo, $part, $courseparam = fa
turnitintooltwo_comms::handle_exceptions($e, 'turnitintooltwoupdateerror', false);
}
}


/**
* Delete a Moodle event based on passed in details.
*
* @param object $turnitintooltwo The turnitintooltwo assignment object.
* @param object $part The name of the part we are deleting.
*/
function turnitintooltwo_delete_event($turnitintooltwo, $part) {
global $DB, $USER;

try {
$DB->delete_records_select("event", "modulename = ? AND userid = ? AND name = ?",
[ "turnitintooltwo", $USER->id, $turnitintooltwo->name." - ".$part->partname ]);
} catch (Exception $e) {
turnitintooltwo_comms::handle_exceptions($e, 'turnitintooltwoupdateerror', false);
}
}
5 changes: 5 additions & 0 deletions turnitintooltwo_assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ public function edit_part_field($partid, $fieldname, $fieldvalue) {
$partdetails = $this->get_part_details($partid);
$return["partid"] = $partid;

// Delete existing events for this assignment part if title or due date changed.
if ($fieldname == "partname" || $fieldname == "dtdue") {
turnitintooltwo_delete_event($this->turnitintooltwo, $partdetails);
}

// Update Turnitin Assignment.
$assignment = new TiiAssignment();
$assignment->setAssignmentId($partdetails->tiiassignid);
Expand Down