From eaead2aea85c90a18e4977101f06a673b3d4929c Mon Sep 17 00:00:00 2001 From: sam marshall Date: Fri, 17 Aug 2012 10:39:38 +0100 Subject: [PATCH] MDL-31957 Course reset: Does not erase activity completion data --- course/reset_form.php | 2 +- lang/en/completion.php | 1 + lib/completionlib.php | 25 +++++++++++++++++++++++++ lib/moodlelib.php | 9 +++++---- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/course/reset_form.php b/course/reset_form.php index ce8b0f708b6..fdb56ebb940 100644 --- a/course/reset_form.php +++ b/course/reset_form.php @@ -19,7 +19,7 @@ class course_reset_form extends moodleform { $mform->addElement('checkbox', 'reset_logs', get_string('deletelogs')); $mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes')); $mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle')); - $mform->addElement('checkbox', 'reset_course_completion', get_string('deletecoursecompletiondata', 'completion')); + $mform->addElement('checkbox', 'reset_completion', get_string('deletecompletiondata', 'completion')); $mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog')); $mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog'); diff --git a/lang/en/completion.php b/lang/en/completion.php index 255ab12e9e6..63ca26e231d 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -71,6 +71,7 @@ $string['completionview_desc'] = 'Student must view this activity to complete it $string['configenablecompletion'] = 'When enabled, this lets you turn on completion tracking (progress) features at course level.'; $string['csvdownload'] = 'Download in spreadsheet format (UTF-8 .csv)'; $string['deletecoursecompletiondata'] = 'Delete course completion data'; +$string['deletecompletiondata'] = 'Delete completion data'; $string['enablecompletion'] = 'Enable completion tracking'; $string['err_noactivities'] = 'Completion information is not enabled for any activity, so none can be displayed. You can enable completion information by editing the settings for an activity.'; $string['err_nousers'] = 'There are no students on this course or group for whom completion information is displayed. (By default, completion information is displayed only for students, so if there are no students, you will see this error. Administrators can alter this option via the admin screens.)'; diff --git a/lib/completionlib.php b/lib/completionlib.php index f1ffb58c782..fc3d02c3949 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -709,6 +709,31 @@ class completion_info { $DB->delete_records('course_completion_crit_compl', array('course' => $this->course_id)); } + /** + * Deletes all activity and course completion data for an entire course + * (the below delete_all_state function does this for a single activity). + * + * Used by course reset page. + */ + public function delete_all_completion_data() { + global $DB; + + // Delete from database. + $DB->delete_records_select('course_modules_completion', + 'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=?)', + array($this->course_id)); + + // Reset cache for current user. + if (isset($SESSION->completioncache) && + array_key_exists($this->course_id, $SESSION->completioncache)) { + + unset($SESSION->completioncache[$this->course_id]); + } + + // Wipe course completion data too. + $this->delete_course_completion_data(); + } + /** * Deletes completion state related to an activity for all users. * diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 9936112ae76..5f864ed611f 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4746,12 +4746,13 @@ function reset_course_userdata($data) { $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteblogassociations', 'blog'), 'error'=>false); } - if (!empty($data->reset_course_completion)) { - // Delete course completion information + if (!empty($data->reset_completion)) { + // Delete course and activity completion information. $course = $DB->get_record('course', array('id'=>$data->courseid)); $cc = new completion_info($course); - $cc->delete_course_completion_data(); - $status[] = array('component'=>$componentstr, 'item'=>get_string('deletecoursecompletiondata', 'completion'), 'error'=>false); + $cc->delete_all_completion_data(); + $status[] = array('component' => $componentstr, + 'item' => get_string('deletecompletiondata', 'completion'), 'error' => false); } $componentstr = get_string('roles');