From c3c97e2ee2302971136e10f7dedb59f95e7d46d8 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 7 Apr 2017 08:08:23 +0800 Subject: [PATCH] MDL-58523 mod_feedback: deleting response should reset completion --- mod/feedback/classes/completion.php | 3 ++- mod/feedback/lib.php | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mod/feedback/classes/completion.php b/mod/feedback/classes/completion.php index 4cf34b17a1af0..2289840815216 100644 --- a/mod/feedback/classes/completion.php +++ b/mod/feedback/classes/completion.php @@ -561,7 +561,8 @@ public function save_response() { // Update completion state. $completion = new completion_info($this->cm->get_course()); - if (isloggedin() && !isguestuser() && $completion->is_enabled($this->cm) && $this->feedback->completionsubmit) { + if (isloggedin() && !isguestuser() && $completion->is_enabled($this->cm) && + $this->cm->completion == COMPLETION_TRACKING_AUTOMATIC && $this->feedback->completionsubmit) { $completion->update_state($this->cm, COMPLETION_COMPLETE); } } diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 5fdca5a874a2a..d242b1973ddf5 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -1372,11 +1372,12 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false if ($completeds = $DB->get_records('feedback_completed', $params)) { $completion = new completion_info($course); foreach ($completeds as $completed) { + $DB->delete_records('feedback_completed', array('id' => $completed->id)); // Update completion state - if ($completion->is_enabled($cm) && $feedback->completionsubmit) { + if ($completion->is_enabled($cm) && $cm->completion == COMPLETION_TRACKING_AUTOMATIC && + $feedback->completionsubmit) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $completed->userid); } - $DB->delete_records('feedback_completed', array('id'=>$completed->id)); } } $DB->delete_records('feedback_completedtmp', array('feedback'=>$feedback->id)); @@ -1730,11 +1731,12 @@ function feedback_delete_all_items($feedbackid) { if ($completeds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id))) { $completion = new completion_info($course); foreach ($completeds as $completed) { + $DB->delete_records('feedback_completed', array('id' => $completed->id)); // Update completion state - if ($completion->is_enabled($cm) && $feedback->completionsubmit) { + if ($completion->is_enabled($cm) && $cm->completion == COMPLETION_TRACKING_AUTOMATIC && + $feedback->completionsubmit) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $completed->userid); } - $DB->delete_records('feedback_completed', array('id'=>$completed->id)); } } @@ -2759,14 +2761,14 @@ function feedback_delete_completed($completed, $feedback = null, $cm = null, $co //first we delete all related values $DB->delete_records('feedback_value', array('completed' => $completed->id)); + // Delete the completed record. + $return = $DB->delete_records('feedback_completed', array('id' => $completed->id)); + // Update completion state $completion = new completion_info($course); - if ($completion->is_enabled($cm) && $feedback->completionsubmit) { + if ($completion->is_enabled($cm) && $cm->completion == COMPLETION_TRACKING_AUTOMATIC && $feedback->completionsubmit) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $completed->userid); } - // Last we delete the completed-record. - $return = $DB->delete_records('feedback_completed', array('id' => $completed->id)); - // Trigger event for the delete action we performed. $event = \mod_feedback\event\response_deleted::create_from_record($completed, $cm, $feedback); $event->trigger();