diff --git a/course/reset_form.php b/course/reset_form.php index f3407253998..751c0c74f8e 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 8b73c59733c..a488b9dabd6 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -70,7 +70,7 @@ $string['completionview'] = 'Require view'; $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 f30b4f0399e..4f152633694 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -711,6 +711,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 a1856fa5f0e..3d8ee4fbe26 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4850,12 +4850,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');