Skip to content

Commit

Permalink
MDL-58523 mod_feedback: deleting response should reset completion
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jun 13, 2017
1 parent 4c6063b commit c3c97e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion mod/feedback/classes/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 10 additions & 8 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c3c97e2

Please sign in to comment.