Skip to content
Browse files

MDL-20992 workshop supports course reset

  • Loading branch information...
1 parent 0cd77e5 commit ed55d692f3011665ab35118b80ac9547d2952198 @mudrd8mz mudrd8mz committed Dec 4, 2009
Showing with 55 additions and 0 deletions.
  1. +1 −0 lang/en_utf8/workshop.php
  2. +54 −0 mod/workshop/lib.php
View
1 lang/en_utf8/workshop.php
@@ -223,6 +223,7 @@
$string['removeallattachments'] = 'Remove All Attachments';
$string['repeatanalysis'] = 'Repeat Analysis';
$string['reply'] = 'Reply';
+$string['resetworkshopall'] ='Delete submissions, grades and assessments';
$string['returnto'] = 'Return to';
$string['returntosubmissionpage'] = 'Return to Submission Page';
$string['rubric'] = 'Rubric';
View
54 mod/workshop/lib.php
@@ -1869,4 +1869,58 @@ function workshop_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
+/**
+ * Called by course/reset.php
+ * @param $mform form passed by reference
+ */
+function workshop_reset_course_form_definition(&$mform) {
+
+ $mform->addElement('header', ' workshopheader', get_string('modulenameplural', 'workshop'));
+ $mform->addElement('checkbox', 'reset_workshop_all', get_string('resetworkshopall','workshop'));
+}
+
+/**
+ * Course reset form defaults.
+ */
+function workshop_reset_course_form_defaults($course) {
+ return array('reset_workshop_all'=>1);
+}
+
+/**
+ * This function is used by the reset_course_userdata function in moodlelib.
+ * This function will remove all issued certificates from the specified course
+ * @param $data the data submitted from the reset course.
+ * @return array status array
+ */
+function workshop_reset_userdata($data) {
+ global $CFG;
+
+ $status = array();
+
+ if (!empty($data->reset_workshop_all)) {
+ $workshopids = get_records('workshop', 'course', $data->courseid, '', 'id');
+ if (!empty($workshopids)) {
+ $workshopidslist = implode(',', array_keys($workshopids));
+ // delete all students participation info, keep assessment forms elements and stock comments
+ delete_records_select('workshop_submissions', "workshopid IN ($workshopidslist)");
+ delete_records_select('workshop_grades', "workshopid IN ($workshopidslist)");
+ delete_records_select('workshop_comments', "workshopid IN ($workshopidslist)");
+ delete_records_select('workshop_assessments', "workshopid IN ($workshopidslist)");
+
+ set_field_select('workshop_elements', 'stddev', 0, "workshopid IN ($workshopidslist)");
+ set_field_select('workshop_elements', 'totalassessments', 0, "workshopid IN ($workshopidslist)");
+ }
+
+ // delete module data (submissions)
+ $basedir = $CFG->dataroot.'/'.$data->courseid.'/'.$CFG->moddata.'/workshop/';
+ remove_dir("$basedir");
+
+ // fill return info
+ $status[] = array('component' => get_string('modulenameplural', 'workshop'),
+ 'item' => get_string('resetworkshopall', 'workshop'), 'error' => false);
+ }
+
+ return $status;
+}
+
?>

0 comments on commit ed55d69

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