Skip to content
Browse files

MDL-31957 Course reset: Does not erase activity completion data

  • Loading branch information...
1 parent 76c9fcc commit eaead2aea85c90a18e4977101f06a673b3d4929c @sammarshallou sammarshallou committed Aug 17, 2012
Showing with 32 additions and 5 deletions.
  1. +1 −1 course/reset_form.php
  2. +1 −0 lang/en/completion.php
  3. +25 −0 lib/completionlib.php
  4. +5 −4 lib/moodlelib.php
View
2 course/reset_form.php
@@ -19,7 +19,7 @@ function definition (){
$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');
View
1 lang/en/completion.php
@@ -71,6 +71,7 @@
$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.)';
View
25 lib/completionlib.php
@@ -710,6 +710,31 @@ public function delete_course_completion_data() {
}
/**
+ * 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.
*
* Intended for use only when the activity itself is deleted.
View
9 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');

0 comments on commit eaead2a

Please sign in to comment.
Something went wrong with that request. Please try again.