示例#1
0
文件: lib.php 项目: nuckey/moodle
    /**
     * Reset all submissions
     */
    function reset_userdata($data) {
        global $CFG, $DB;

        if (!$DB->count_records('assignment', array('course'=>$data->courseid, 'assignmenttype'=>$this->type))) {
            return array(); // no assignments of this type present
        }

        $componentstr = get_string('modulenameplural', 'assignment');
        $status = array();

        $typestr = get_string('type'.$this->type, 'assignment');
        // ugly hack to support pluggable assignment type titles...
        if($typestr === '[[type'.$this->type.']]'){
            $typestr = get_string('type'.$this->type, 'assignment_'.$this->type);
        }

        if (!empty($data->reset_assignment_submissions)) {
            $assignmentssql = "SELECT a.id
                                 FROM {assignment} a
                                WHERE a.course=? AND a.assignmenttype=?";
            $params = array($data->courseid, $this->type);

            // now get rid of all submissions and responses
            $fs = get_file_storage();
            if ($assignments = $DB->get_records_sql($assignmentssql, $params)) {
                foreach ($assignments as $assignmentid=>$unused) {
                    if (!$cm = get_coursemodule_from_instance('assignment', $assignmentid)) {
                        continue;
                    }
                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $fs->delete_area_files($context->id, 'mod_assignment', 'submission');
                    $fs->delete_area_files($context->id, 'mod_assignment', 'response');
                }
            }

            $DB->delete_records_select('assignment_submissions', "assignment IN ($assignmentssql)", $params);

            $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallsubmissions','assignment').': '.$typestr, 'error'=>false);

            if (empty($data->reset_gradebook_grades)) {
                // remove all grades from gradebook
                assignment_reset_gradebook($data->courseid, $this->type);
            }
        }

        /// updating dates - shift may be negative too
        if ($data->timeshift) {
            shift_course_mod_dates('assignment', array('timedue', 'timeavailable'), $data->timeshift, $data->courseid);
            $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged').': '.$typestr, 'error'=>false);
        }

        return $status;
    }
示例#2
0
 /**
  * Reset all submissions
  */
 function reset_userdata($data)
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if (!count_records('assignment', 'course', $data->courseid, 'assignmenttype', $this->type)) {
         return array();
         // no assignments of this type present
     }
     $componentstr = get_string('modulenameplural', 'assignment');
     $status = array();
     $typestr = get_string('type' . $this->type, 'assignment');
     if (!empty($data->reset_assignment_submissions)) {
         $assignmentssql = "SELECT a.id\n                                 FROM {$CFG->prefix}assignment a\n                                WHERE a.course={$data->courseid} AND a.assignmenttype='{$this->type}'";
         delete_records_select('assignment_submissions', "assignment IN ({$assignmentssql})");
         if ($assignments = get_records_sql($assignmentssql)) {
             foreach ($assignments as $assignmentid => $unused) {
                 fulldelete($CFG->dataroot . '/' . $data->courseid . '/moddata/assignment/' . $assignmentid);
             }
         }
         $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assignment') . ': ' . $typestr, 'error' => false);
         if (empty($data->reset_gradebook_grades)) {
             // remove all grades from gradebook
             assignment_reset_gradebook($data->courseid, $this->type);
         }
     }
     /// updating dates - shift may be negative too
     if ($data->timeshift) {
         shift_course_mod_dates('assignment', array('timedue', 'timeavailable'), $data->timeshift, $data->courseid);
         $status[] = array('component' => $componentstr, 'item' => get_string('datechanged') . ': ' . $typestr, 'error' => false);
     }
     return $status;
 }