コード例 #1
0
ファイル: lib.php プロジェクト: evltuma/moodle
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all responses from the specified feedback
 * and clean up any related data.
 *
 * @global object
 * @global object
 * @uses FEEDBACK_RESETFORM_RESET
 * @uses FEEDBACK_RESETFORM_DROP
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function feedback_reset_userdata($data)
{
    global $CFG, $DB;
    $resetfeedbacks = array();
    $dropfeedbacks = array();
    $status = array();
    $componentstr = get_string('modulenameplural', 'feedback');
    //get the relevant entries from $data
    foreach ($data as $key => $value) {
        switch (true) {
            case substr($key, 0, strlen(FEEDBACK_RESETFORM_RESET)) == FEEDBACK_RESETFORM_RESET:
                if ($value == 1) {
                    $templist = explode('_', $key);
                    if (isset($templist[3])) {
                        $resetfeedbacks[] = intval($templist[3]);
                    }
                }
                break;
            case substr($key, 0, strlen(FEEDBACK_RESETFORM_DROP)) == FEEDBACK_RESETFORM_DROP:
                if ($value == 1) {
                    $templist = explode('_', $key);
                    if (isset($templist[3])) {
                        $dropfeedbacks[] = intval($templist[3]);
                    }
                }
                break;
        }
    }
    //reset the selected feedbacks
    foreach ($resetfeedbacks as $id) {
        $feedback = $DB->get_record('feedback', array('id' => $id));
        feedback_delete_all_completeds($feedback);
        $status[] = array('component' => $componentstr . ':' . $feedback->name, 'item' => get_string('resetting_data', 'feedback'), 'error' => false);
    }
    // Updating dates - shift may be negative too.
    if ($data->timeshift) {
        $shifterror = !shift_course_mod_dates('feedback', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => $shifterror);
    }
    return $status;
}
コード例 #2
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;
    }
コード例 #3
0
ファイル: lib.php プロジェクト: ajv/Offline-Caching
/**
 * Actual implementation of the rest coures functionality, delete all the
 * chat messages for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function chat_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'chat');
    $status = array();
    if (!empty($data->reset_chat)) {
        $chatessql = "SELECT ch.id\n                        FROM {chat} ch\n                       WHERE ch.course=?";
        $params = array($data->courseid);
        $DB->delete_records_select('chat_messages', "chatid IN ({$chatessql})", $params);
        $DB->delete_records_select('chat_messages_current', "chatid IN ({$chatessql})", $params);
        $DB->delete_records_select('chat_users', "chatid IN ({$chatessql})", $params);
        $status[] = array('component' => $componentstr, 'item' => get_string('removemessages', 'chat'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('chat', array('chattime'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #4
0
ファイル: locallib.php プロジェクト: mercysmart/naikelas
 /**
  * Actual implementation of the reset course functionality, delete all the
  * assignment submissions for course $data->courseid.
  *
  * @param stdClass $data the data submitted from the reset course.
  * @return array status array
  */
 public function reset_userdata($data)
 {
     global $CFG, $DB;
     $componentstr = get_string('modulenameplural', 'assign');
     $status = array();
     $fs = get_file_storage();
     if (!empty($data->reset_assign_submissions)) {
         // Delete files associated with this assignment.
         foreach ($this->submissionplugins as $plugin) {
             $fileareas = array();
             $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
             $fileareas = $plugin->get_file_areas();
             foreach ($fileareas as $filearea => $notused) {
                 $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
             }
             if (!$plugin->delete_instance()) {
                 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => $plugin->get_error());
             }
         }
         foreach ($this->feedbackplugins as $plugin) {
             $fileareas = array();
             $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
             $fileareas = $plugin->get_file_areas();
             foreach ($fileareas as $filearea => $notused) {
                 $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
             }
             if (!$plugin->delete_instance()) {
                 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => $plugin->get_error());
             }
         }
         $assignids = $DB->get_records('assign', array('course' => $data->courseid), '', 'id');
         list($sql, $params) = $DB->get_in_or_equal(array_keys($assignids));
         $DB->delete_records_select('assign_submission', "assignment {$sql}", $params);
         $DB->delete_records_select('assign_user_flags', "assignment {$sql}", $params);
         $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => false);
         if (!empty($data->reset_gradebook_grades)) {
             $DB->delete_records_select('assign_grades', "assignment {$sql}", $params);
             // Remove all grades from gradebook.
             require_once $CFG->dirroot . '/mod/assign/lib.php';
             assign_reset_gradebook($data->courseid);
             // Reset revealidentities if both submissions and grades have been reset.
             if ($this->get_instance()->blindmarking && $this->get_instance()->revealidentities) {
                 $DB->set_field('assign', 'revealidentities', 0, array('id' => $this->get_instance()->id));
             }
         }
     }
     // Updating dates - shift may be negative too.
     if ($data->timeshift) {
         shift_course_mod_dates('assign', array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'), $data->timeshift, $data->courseid, $this->get_instance()->id);
         $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
     }
     return $status;
 }
コード例 #5
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;
 }
コード例 #6
0
/**
 * Actual implementation of the rest coures functionality, delete all the
 * lesson attempts for course $data->courseid.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function lesson_reset_userdata($data)
{
    global $CFG;
    $componentstr = get_string('modulenameplural', 'lesson');
    $status = array();
    if (!empty($data->reset_lesson)) {
        $lessonssql = "SELECT l.id\n                         FROM {$CFG->prefix}lesson l\n                        WHERE l.course={$data->courseid}";
        delete_records_select('lesson_timer', "lessonid IN ({$lessonssql})");
        delete_records_select('lesson_high_scores', "lessonid IN ({$lessonssql})");
        delete_records_select('lesson_grades', "lessonid IN ({$lessonssql})");
        delete_records_select('lesson_attempts', "lessonid IN ({$lessonssql})");
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            lesson_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallattempts', 'lesson'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('lesson', array('available', 'deadline'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #7
0
ファイル: lib.php プロジェクト: nanda555/TestAppFromAWS
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified assignment
 * and clean up any related data.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function assignment_reset_userdata($data)
{
    global $CFG;
    $status = array();
    foreach (core_component::get_plugin_list('assignment') as $type => $dir) {
        require_once "{$dir}/assignment.class.php";
        $assignmentclass = "assignment_{$type}";
        $ass = new $assignmentclass();
        $status = array_merge($status, $ass->reset_userdata($data));
    }
    // 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' => get_string('modulenameplural', 'assignment'), 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #8
0
ファイル: lib.php プロジェクト: ndunand/moodle-mod_opencast
/**
 * Actual implementation of the reset course functionality, delete all the
 * opencast clip members for course $data->courseid.
 *
 * @param object $data the data submitted from the reset course.
 *
 * @return array status array
 */
function opencast_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'opencast');
    $status = [];
    if (!empty($data->reset_opencast)) {
        $DB->delete_records('opencast_cmember', ['courseid' => $data->courseid]);
        $status[] = ['component' => $componentstr, 'item' => get_string('removeclipmembers', 'opencast'), 'error' => false];
    }
    // updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('opencast', ['timeopen', 'timeclose'], $data->timeshift, $data->courseid);
        $status[] = ['component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false];
    }
    return $status;
}
コード例 #9
0
ファイル: lib.php プロジェクト: nfreear/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is
 * set and true.
 *
 * Also, move the quiz open and close dates, if the course start date is changing.
 *
 * @global stdClass
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function quiz_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/questionlib.php');

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

    /// Delete attempts.
    if (!empty($data->reset_quiz_attempts)) {
        $quizzes = $DB->get_records('quiz', array('course' => $data->courseid));
        foreach ($quizzes as $quiz) {
            quiz_delete_all_attempts($quiz);
        }

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            quiz_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), 'error' => false);
    }

    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('quiz', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('openclosedatesupdated', 'quiz'), 'error' => false);
    }

    return $status;
}
コード例 #10
0
ファイル: lib.php プロジェクト: nadavkav/MoodleTAO
/**
 * Actual implementation of the rest coures functionality, delete all the
 * glossary responses for course $data->courseid.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function glossary_reset_userdata($data)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $componentstr = get_string('modulenameplural', 'glossary');
    $status = array();
    $allentriessql = "SELECT e.id\n                        FROM {$CFG->prefix}glossary_entries e\n                             INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id\n                       WHERE g.course = {$data->courseid}";
    $allglossariessql = "SELECT g.id\n                            FROM {$CFG->prefix}glossary g\n                           WHERE g.course={$data->courseid}";
    // delete entries if requested
    if (!empty($data->reset_glossary_all) or !empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types)) {
        delete_records_select('glossary_ratings', "entryid IN ({$allentriessql})");
        delete_records_select('glossary_comments', "entryid IN ({$allentriessql})");
        delete_records_select('glossary_entries', "glossaryid IN ({$allglossariessql})");
        if ($glossaries = get_records_sql($allglossariessql)) {
            foreach ($glossaries as $glossaryid => $unused) {
                fulldelete($CFG->dataroot . "/{$data->courseid}/moddata/glossary/{$glossaryid}");
            }
        }
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            glossary_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('resetglossariesall', 'glossary'), 'error' => false);
    } else {
        if (!empty($data->reset_glossary_types)) {
            $mainentriessql = "{$allentries} AND g.mainglossary=1";
            $secondaryentriessql = "{$allentries} AND g.mainglossary=0";
            $mainglossariessql = "{$allglossariessql} AND g.mainglossary=1";
            $secondaryglossariessql = "{$allglossariessql} AND g.mainglossary=0";
            if (in_array('main', $data->reset_glossary_types)) {
                delete_records_select('glossary_ratings', "entryid IN ({$mainentriessql})");
                delete_records_select('glossary_comments', "entryid IN ({$mainentriessql})");
                delete_records_select('glossary_entries', "glossaryid IN ({$mainglossariessql})");
                if ($glossaries = get_records_sql($mainglossariessql)) {
                    foreach ($glossaries as $glossaryid => $unused) {
                        fulldelete("{$CFG->dataroot}/{$data->courseid}/moddata/glossary/{$glossaryid}");
                    }
                }
                // remove all grades from gradebook
                if (empty($data->reset_gradebook_grades)) {
                    glossary_reset_gradebook($data->courseid, 'main');
                }
                $status[] = array('component' => $componentstr, 'item' => get_string('resetglossaries', 'glossary'), 'error' => false);
            } else {
                if (in_array('secondary', $data->reset_glossary_types)) {
                    delete_records_select('glossary_ratings', "entryid IN ({$secondaryentriessql})");
                    delete_records_select('glossary_comments', "entryid IN ({$secondaryentriessql})");
                    delete_records_select('glossary_entries', "glossaryid IN ({$secondaryglossariessql})");
                    // remove exported source flag from entries in main glossary
                    execute_sql("UPDATE {$CFG->prefix}glossary_entries\n                            SET sourceglossaryid=0\n                          WHERE glossaryid IN ({$mainglossariessql})", false);
                    if ($glossaries = get_records_sql($secondaryglossariessql)) {
                        foreach ($glossaries as $glossaryid => $unused) {
                            fulldelete("{$CFG->dataroot}/{$data->courseid}/moddata/glossary/{$glossaryid}");
                        }
                    }
                    // remove all grades from gradebook
                    if (empty($data->reset_gradebook_grades)) {
                        glossary_reset_gradebook($data->courseid, 'secondary');
                    }
                    $status[] = array('component' => $componentstr, 'item' => get_string('resetglossaries', 'glossary') . ': ' . get_string('secondaryglossary', 'glossary'), 'error' => false);
                }
            }
        }
    }
    // remove entries by users not enrolled into course
    if (!empty($data->reset_glossary_notenrolled)) {
        $entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted\n                         FROM {$CFG->prefix}glossary_entries e\n                              INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id\n                              LEFT OUTER JOIN {$CFG->prefix}user u ON e.userid = u.id\n                        WHERE g.course = {$data->courseid} AND e.userid > 0";
        $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
        $notenrolled = array();
        if ($rs = get_recordset_sql($entriessql)) {
            while ($entry = rs_fetch_next_record($rs)) {
                if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted or !has_capability('moodle/course:view', $course_context, $entry->userid)) {
                    delete_records('glossary_ratings', 'entryid', $entry->id);
                    delete_records('glossary_comments', 'entryid', $entry->id);
                    delete_records('glossary_entries', 'id', $entry->id);
                    fulldelete("{$CFG->dataroot}/{$data->courseid}/moddata/glossary/{$entry->glossaryid}");
                    $notenrolled[$entry->userid] = true;
                }
            }
            rs_close($rs);
            $status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'glossary'), 'error' => false);
        }
    }
    // remove all ratings
    if (!empty($data->reset_glossary_ratings)) {
        delete_records_select('glossary_ratings', "entryid IN ({$allentriessql})");
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            glossary_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallratings'), 'error' => false);
    }
    // remove all comments
    if (!empty($data->reset_glossary_comments)) {
        delete_records_select('glossary_comments', "entryid IN ({$allentriessql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('glossary', array('assesstimestart', 'assesstimefinish'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #11
0
ファイル: lib.php プロジェクト: alanaipe2015/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * lesson attempts for course $data->courseid.
 *
 * @global stdClass
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function lesson_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'lesson');
    $status = array();
    if (!empty($data->reset_lesson)) {
        $lessonssql = "SELECT l.id\n                         FROM {lesson} l\n                        WHERE l.course=:course";
        $params = array("course" => $data->courseid);
        $lessons = $DB->get_records_sql($lessonssql, $params);
        // Get rid of attempts files.
        $fs = get_file_storage();
        if ($lessons) {
            foreach ($lessons as $lessonid => $unused) {
                if (!($cm = get_coursemodule_from_instance('lesson', $lessonid))) {
                    continue;
                }
                $context = context_module::instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses');
            }
        }
        $DB->delete_records_select('lesson_timer', "lessonid IN ({$lessonssql})", $params);
        $DB->delete_records_select('lesson_grades', "lessonid IN ({$lessonssql})", $params);
        $DB->delete_records_select('lesson_attempts', "lessonid IN ({$lessonssql})", $params);
        $DB->delete_records_select('lesson_branch', "lessonid IN ({$lessonssql})", $params);
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            lesson_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallattempts', 'lesson'), 'error' => false);
    }
    // Remove user overrides.
    if (!empty($data->reset_lesson_user_overrides)) {
        $DB->delete_records_select('lesson_overrides', 'lessonid IN (SELECT id FROM {lesson} WHERE course = ?) AND userid IS NOT NULL', array($data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('useroverridesdeleted', 'lesson'), 'error' => false);
    }
    // Remove group overrides.
    if (!empty($data->reset_lesson_group_overrides)) {
        $DB->delete_records_select('lesson_overrides', 'lessonid IN (SELECT id FROM {lesson} WHERE course = ?) AND groupid IS NOT NULL', array($data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('groupoverridesdeleted', 'lesson'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        $DB->execute("UPDATE {lesson_overrides}\n                         SET available = available + ?\n                       WHERE lessonid IN (SELECT id FROM {lesson} WHERE course = ?)\n                         AND available <> 0", array($data->timeshift, $data->courseid));
        $DB->execute("UPDATE {lesson_overrides}\n                         SET deadline = deadline + ?\n                       WHERE lessonid IN (SELECT id FROM {lesson} WHERE course = ?)\n                         AND deadline <> 0", array($data->timeshift, $data->courseid));
        shift_course_mod_dates('lesson', array('available', 'deadline'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #12
0
ファイル: lib.php プロジェクト: miotto/moodle-mod_organizer
function organizer_reset_userdata($data)
{
    global $DB;
    if (!$DB->count_records('organizer', array('course' => $data->courseid))) {
        return array();
    }
    $componentstr = get_string('modulenameplural', 'organizer');
    $status = array();
    if (isset($data->reset_organizer_all)) {
        $params = array('courseid' => $data->courseid);
        $slotquery = 'SELECT s.*
                    FROM {organizer_slots} s
                    INNER JOIN {organizer} m ON s.organizerid = m.id
                    WHERE m.course = :courseid';
        $appquery = 'SELECT a.*
                    FROM {organizer_slot_appointments} a
                    INNER JOIN {organizer_slots} s ON a.slotid = s.id
                    INNER JOIN {organizer} m ON s.organizerid = m.id
                    WHERE m.course = :courseid';
        $slots = $DB->get_records_sql($slotquery, $params);
        $appointments = $DB->get_records_sql($appquery, $params);
        $ok = true;
        foreach ($slots as $slot) {
            $DB->delete_records('event', array('id' => $slot->eventid));
            //tscpr: Petr Skoda told us that $DB->delete_records will throw an exeption if it fails, otherwise it always succeeds...
            $ok &= $DB->delete_records('organizer_slots', array('id' => $slot->id));
        }
        foreach ($appointments as $appointment) {
            $DB->delete_records('event', array('id' => $appointment->eventid));
            //tscpr: Petr Skoda told us that $DB->delete_records will throw an exeption if it fails, otherwise it always succeeds...
            $ok &= $DB->delete_records('organizer_slot_appointments', array('id' => $appointment->id));
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('reset_organizer_all', 'organizer'), 'error' => !$ok);
    }
    if (isset($data->delete_organizer_grades)) {
        $ok = organizer_reset_gradebook($data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('delete_organizer_grades', 'organizer'), 'error' => !$ok);
    }
    if ($data->timeshift) {
        $ok = shift_course_mod_dates('organizer', array('allowregistrationsfromdate', 'duedate'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('timeshift', 'organizer'), 'error' => !$ok);
    }
    return $status;
}
コード例 #13
0
ファイル: lib.php プロジェクト: verbazend/AWFA
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all assignment submissions and feedbacks in the database
 * and clean up any related data.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function assign_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->dirroot . '/mod/assign/locallib.php');

    $status = array();
    $params = array('courseid'=>$data->courseid);
    $sql = "SELECT a.id FROM {assign} a WHERE a.course=:courseid";
    $course = $DB->get_record('course', array('id'=>$data->courseid), '*', MUST_EXIST);
    if ($assigns = $DB->get_records_sql($sql, $params)) {
        foreach ($assigns as $assign) {
            $cm = get_coursemodule_from_instance('assign',
                                                 $assign->id,
                                                 $data->courseid,
                                                 false,
                                                 MUST_EXIST);
            $context = context_module::instance($cm->id);
            $assignment = new assign($context, $cm, $course);
            $status = array_merge($status, $assignment->reset_userdata($data));
        }
    }
    // Updating dates - shift may be negative too.
    if ($data->timeshift) {
        shift_course_mod_dates('assign',
                                array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'),
                                $data->timeshift,
                                $data->courseid);

        $status[] = array('component' => get_string('modulenameplural', 'assign'),
                          'item' => get_string('datechanged'),
                          'error' => false);
    }
    return $status;
}
コード例 #14
0
ファイル: lib.php プロジェクト: ccle/moodle-mod_certificate
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified certificate
 * and clean up any related data.
 *
 * Written by Jean-Michel Vedrine
 *
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function certificate_reset_userdata($data)
{
    global $DB;
    $componentstr = get_string('modulenameplural', 'certificate');
    $status = array();
    if (!empty($data->reset_certificate)) {
        $sql = "SELECT cert.id\n                  FROM {certificate} cert\n                 WHERE cert.course = :courseid";
        $params = array('courseid' => $data->courseid);
        $certificates = $DB->get_records_sql($sql, $params);
        $fs = get_file_storage();
        if ($certificates) {
            foreach ($certificates as $certid => $unused) {
                if (!($cm = get_coursemodule_from_instance('certificate', $certid))) {
                    continue;
                }
                $context = context_module::instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_certificate', 'issue');
            }
        }
        $DB->delete_records_select('certificate_issues', "certificateid IN ({$sql})", $params);
        $status[] = array('component' => $componentstr, 'item' => get_string('removecert', 'certificate'), 'error' => false);
    }
    // Updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('certificate', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #15
0
ファイル: lib.php プロジェクト: rolandovanegas/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * glossary responses for course $data->courseid.
 *
 * @global object
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function glossary_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->dirroot.'/rating/lib.php');

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

    $allentriessql = "SELECT e.id
                        FROM {glossary_entries} e
                             JOIN {glossary} g ON e.glossaryid = g.id
                       WHERE g.course = ?";

    $allglossariessql = "SELECT g.id
                           FROM {glossary} g
                          WHERE g.course = ?";

    $params = array($data->courseid);

    $fs = get_file_storage();

    $rm = new rating_manager();
    $ratingdeloptions = new stdClass;
    $ratingdeloptions->component = 'mod_glossary';
    $ratingdeloptions->ratingarea = 'entry';

    // delete entries if requested
    if (!empty($data->reset_glossary_all)
         or (!empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types))) {

        $params[] = 'glossary_entry';
        $DB->delete_records_select('comments', "itemid IN ($allentriessql) AND commentarea=?", $params);
        $DB->delete_records_select('glossary_alias',    "entryid IN ($allentriessql)", $params);
        $DB->delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)", $params);

        // now get rid of all attachments
        if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
            foreach ($glossaries as $glossaryid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                $fs->delete_area_files($context->id, 'mod_glossary', 'attachment');

                //delete ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            glossary_reset_gradebook($data->courseid);
        }

        $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossariesall', 'glossary'), 'error'=>false);

    } else if (!empty($data->reset_glossary_types)) {
        $mainentriessql         = "$allentries AND g.mainglossary=1";
        $secondaryentriessql    = "$allentries AND g.mainglossary=0";

        $mainglossariessql      = "$allglossariessql AND g.mainglossary=1";
        $secondaryglossariessql = "$allglossariessql AND g.mainglossary=0";

        if (in_array('main', $data->reset_glossary_types)) {
            $params[] = 'glossary_entry';
            $DB->delete_records_select('comments', "itemid IN ($mainentriessql) AND commentarea=?", $params);
            $DB->delete_records_select('glossary_entries', "glossaryid IN ($mainglossariessql)", $params);

            if ($glossaries = $DB->get_records_sql($mainglossariessql, $params)) {
                foreach ($glossaries as $glossaryid=>$unused) {
                    if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                        continue;
                    }
                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $fs->delete_area_files($context->id, 'mod_glossary', 'attachment');

                    //delete ratings
                    $ratingdeloptions->contextid = $context->id;
                    $rm->delete_ratings($ratingdeloptions);
                }
            }

            // remove all grades from gradebook
            if (empty($data->reset_gradebook_grades)) {
                glossary_reset_gradebook($data->courseid, 'main');
            }

            $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary'), 'error'=>false);

        } else if (in_array('secondary', $data->reset_glossary_types)) {
            $params[] = 'glossary_entry';
            $DB->delete_records_select('comments', "itemid IN ($secondaryentriessql) AND commentarea=?", $params);
            $DB->delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)", $params);
            // remove exported source flag from entries in main glossary
            $DB->execute("UPDATE {glossary_entries
                             SET sourceglossaryid=0
                           WHERE glossaryid IN ($mainglossariessql)", $params);

            if ($glossaries = $DB->get_records_sql($secondaryglossariessql, $params)) {
                foreach ($glossaries as $glossaryid=>$unused) {
                    if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                        continue;
                    }
                    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                    $fs->delete_area_files($context->id, 'mod_glossary', 'attachment');

                    //delete ratings
                    $ratingdeloptions->contextid = $context->id;
                    $rm->delete_ratings($ratingdeloptions);
                }
            }

            // remove all grades from gradebook
            if (empty($data->reset_gradebook_grades)) {
                glossary_reset_gradebook($data->courseid, 'secondary');
            }

            $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary').': '.get_string('secondaryglossary', 'glossary'), 'error'=>false);
        }
    }

    // remove entries by users not enrolled into course
    if (!empty($data->reset_glossary_notenrolled)) {
        $entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted
                         FROM {glossary_entries} e
                              JOIN {glossary} g ON e.glossaryid = g.id
                              LEFT JOIN {user} u ON e.userid = u.id
                        WHERE g.course = ? AND e.userid > 0";

        $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
        $notenrolled = array();
        $rs = $DB->get_recordset_sql($entriessql, $params);
        if ($rs->valid()) {
            foreach ($rs as $entry) {
                if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
                  or !is_enrolled($course_context , $entry->userid)) {
                    $DB->delete_records('comments', array('commentarea'=>'glossary_entry', 'itemid'=>$entry->id));
                    $DB->delete_records('glossary_entries', array('id'=>$entry->id));

                    if ($cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
                        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                        $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);

                        //delete ratings
                        $ratingdeloptions->contextid = $context->id;
                        $rm->delete_ratings($ratingdeloptions);
                    }
                }
            }
            $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false);
        }
        $rs->close();
    }

    // remove all ratings
    if (!empty($data->reset_glossary_ratings)) {
        //remove ratings
        if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
            foreach ($glossaries as $glossaryid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);

                //delete ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            glossary_reset_gradebook($data->courseid);
        }
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
    }

    // remove comments
    if (!empty($data->reset_glossary_comments)) {
        $params[] = 'glossary_entry';
        $DB->delete_records_select('comments', "itemid IN ($allentriessql) AND commentarea= ? ", $params);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
    }

    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('glossary', array('assesstimestart', 'assesstimefinish'), $data->timeshift, $data->courseid);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
    }

    return $status;
}
コード例 #16
0
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified certificate
 * and clean up any related data.
 * Written by Jean-Michel Vedrine
 * 
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function simplecertificate_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'simplecertificate');
    $status = array();
    if (!empty($data->reset_certificate)) {
        $timedeleted = time();
        $certificates = $DB->get_records('simplecertificate', array('course' => $data->courseid));
        foreach ($certificates as $certificate) {
            $issuecertificates = $DB->get_records('simplecertificate_issues', array('certificateid' => $certificate->id, 'timedeleted' => null));
            foreach ($issuecertificates as $issuecertificate) {
                $issuecertificate->timedeleted = $timedeleted;
                if (!$DB->update_record('simplecertificate_issues', $issuecertificate)) {
                    print_error(get_string('cantdeleteissue', 'simplecertificate'));
                }
            }
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('modulenameplural', 'simplecertificate'), 'error' => false);
    }
    // Updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('simplecertificate', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #17
0
ファイル: lib.php プロジェクト: e-rasvet/reader
/**
 * Actual implementation of the rest coures functionality, delete all the
 * quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is
 * set and true.
 *
 * Also, move the quiz open and close dates, if the course start date is changing.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function quiz_reset_userdata($data)
{
    global $CFG, $QTYPES;
    // TODO: this should use the delete_attempt($attempt->uniqueid) function in questionlib.php
    // require_once($CFG->libdir.'/questionlib.php');
    $componentstr = get_string('modulenameplural', 'quiz');
    $status = array();
    /// Delete attempts.
    if (!empty($data->reset_quiz_attempts)) {
        $stateslistsql = "SELECT s.id\n                            FROM {$CFG->prefix}question_states s\n                                 INNER JOIN {$CFG->prefix}quiz_attempts qza ON s.attempt=qza.uniqueid\n                                 INNER JOIN {$CFG->prefix}quiz q ON qza.quiz=q.id\n                           WHERE q.course={$data->courseid}";
        $attemptssql = "SELECT a.uniqueid\n                            FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}quiz q\n                           WHERE q.course={$data->courseid} AND a.quiz=q.id";
        $quizessql = "SELECT q.id\n                            FROM {$CFG->prefix}quiz q\n                           WHERE q.course={$data->courseid}";
        if ($states = get_records_sql($stateslistsql)) {
            //TODO: not sure if this works
            $stateslist = implode(',', array_keys($states));
            foreach ($QTYPES as $qtype) {
                $qtype->delete_states($stateslist);
            }
        }
        delete_records_select('question_states', "attempt IN ({$attemptssql})");
        delete_records_select('question_sessions', "attemptid IN ({$attemptssql})");
        delete_records_select('question_attempts', "id IN ({$attemptssql})");
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            quiz_reset_gradebook($data->courseid);
        }
        delete_records_select('quiz_grades', "quiz IN ({$quizessql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('gradesdeleted', 'quiz'), 'error' => false);
        delete_records_select('quiz_attempts', "quiz IN ({$quizessql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('quiz', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('openclosedatesupdated', 'quiz'), 'error' => false);
    }
    return $status;
}
コード例 #18
0
ファイル: lib.php プロジェクト: rohitshriwas/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * choice responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function choice_reset_userdata($data) {
    global $CFG, $DB;

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

    if (!empty($data->reset_choice)) {
        $choicessql = "SELECT ch.id
                       FROM {choice} ch
                       WHERE ch.course=?";

        $DB->delete_records_select('choice_answers', "choiceid IN ($choicessql)", array($data->courseid));
        $status[] = array('component'=>$componentstr, 'item'=>get_string('removeresponses', 'choice'), 'error'=>false);
    }

    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('choice', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
    }

    return $status;
}
コード例 #19
0
ファイル: lib.php プロジェクト: MoodleMetaData/MoodleMetaData
function respondusws_reset_userdata($data)
{
    $component = get_string("modulenameplural", "respondusws");
    $status = array();
    if ($data->timeshift) {
        shift_course_mod_dates("respondusws", array("timecreated", "timemodified"), $data->timeshift, $data->courseid);
        $status[] = array("component" => $component, "item" => get_string("datechanged"), "error" => false);
    }
    return $status;
}
コード例 #20
0
ファイル: lib.php プロジェクト: parksandwildlife/learning
/**
 * Actual implementation of the rest coures functionality, delete all the
 * data responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function dataform_reset_userdata($data)
{
    global $DB;
    $componentstr = get_string('modulenameplural', 'dataform');
    $entriesdeleteallstr = get_string('entriesdeleteall', 'dataform');
    $deletenotenrolledstr = get_string('deletenotenrolled', 'dataform');
    $datachangedstr = get_string('datechanged');
    $status = array();
    if (!($dataforms = $DB->get_records('dataform', array('dataid' => $data->courseid), '', 'id'))) {
        return $status;
    }
    foreach (array_keys($dataforms) as $dataformid) {
        $df = mod_dataform_dataform::instance($dataformid);
        // Delete all user data.
        if (!empty($data->reset_dataform_data)) {
            $df->reset_user_data();
            $status['entriesdeleteall'] = array('component' => $componentstr, 'item' => $entriesdeleteallstr, 'error' => false);
        }
        // Delete user data for not enrolled users.
        if (!empty($data->reset_dataform_notenrolled)) {
            $sql = "\n                SELECT\n                    e.id,\n                    e.userid,\n                    e.dataid,\n                    u.id AS userexists,\n                    u.deleted AS userdeleted\n                FROM\n                    {dataform_entries} e\n                    LEFT JOIN {user} u ON e.userid = u.id\n                WHERE\n                    e.dataid = ?\n            ";
            $coursecontext = context_course::instance($this->course->id);
            $skipped = array();
            $notenrolled = array();
            $entries = $DB->get_records_sql($sql, array($dataformid));
            foreach ($entries as $entry) {
                if (array_key_exists($entry->userid, $notenrolled)) {
                    continue;
                }
                if (array_key_exists($entry->userid, $skipped)) {
                    continue;
                }
                if (!$entry->userexists or $entry->userdeleted or !is_enrolled($coursecontext, $entry->userid)) {
                    $df->reset_user_data($entry->userid);
                    $notenrolled[$entry->userid] = true;
                    continue;
                }
                $skipped[$entry->userid] = true;
                $status['deletenotenrolled'] = array('component' => $componentstr, 'item' => $deletenotenrolledstr, 'error' => false);
            }
        }
        // Updating dates - shift may be negative too.
        if ($data->timeshift) {
            shift_course_mod_dates('dataform', array('timeavailable', 'timedue'), $data->timeshift, $data->courseid);
            $status['datechanged'] = array('component' => $componentstr, 'item' => $datechangedstr, 'error' => false);
        }
    }
    return $status;
}
コード例 #21
0
ファイル: lib.php プロジェクト: gabrielrosset/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * data responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function data_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/filelib.php';
    require_once $CFG->dirroot . '/rating/lib.php';
    $componentstr = get_string('modulenameplural', 'data');
    $status = array();
    $allrecordssql = "SELECT r.id\n                        FROM {data_records} r\n                             INNER JOIN {data} d ON r.dataid = d.id\n                       WHERE d.course = ?";
    $alldatassql = "SELECT d.id\n                      FROM {data} d\n                     WHERE d.course=?";
    $rm = new rating_manager();
    $ratingdeloptions = new stdClass();
    $ratingdeloptions->component = 'mod_data';
    $ratingdeloptions->ratingarea = 'entry';
    // Set the file storage - may need it to remove files later.
    $fs = get_file_storage();
    // delete entries if requested
    if (!empty($data->reset_data)) {
        $DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
        $DB->delete_records_select('data_content', "recordid IN ({$allrecordssql})", array($data->courseid));
        $DB->delete_records_select('data_records', "dataid IN ({$alldatassql})", array($data->courseid));
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid => $unused) {
                if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                // Delete any files that may exist.
                $fs->delete_area_files($datacontext->id, 'mod_data', 'content');
                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallentries', 'data'), 'error' => false);
    }
    // remove entries by users not enrolled into course
    if (!empty($data->reset_data_notenrolled)) {
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted\n                         FROM {data_records} r\n                              JOIN {data} d ON r.dataid = d.id\n                              LEFT JOIN {user} u ON r.userid = u.id\n                        WHERE d.course = ? AND r.userid > 0";
        $course_context = context_course::instance($data->courseid);
        $notenrolled = array();
        $fields = array();
        $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
        foreach ($rs as $record) {
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted or !is_enrolled($course_context, $record->userid)) {
                //delete ratings
                if (!($cm = get_coursemodule_from_instance('data', $record->dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $ratingdeloptions->itemid = $record->id;
                $rm->delete_ratings($ratingdeloptions);
                // Delete any files that may exist.
                if ($contents = $DB->get_records('data_content', array('recordid' => $record->id), '', 'id')) {
                    foreach ($contents as $content) {
                        $fs->delete_area_files($datacontext->id, 'mod_data', 'content', $content->id);
                    }
                }
                $notenrolled[$record->userid] = true;
                $DB->delete_records('comments', array('itemid' => $record->id, 'commentarea' => 'database_entry'));
                $DB->delete_records('data_content', array('recordid' => $record->id));
                $DB->delete_records('data_records', array('id' => $record->id));
            }
        }
        $rs->close();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'data'), 'error' => false);
    }
    // remove all ratings
    if (!empty($data->reset_data_ratings)) {
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid => $unused) {
                if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
                    continue;
                }
                $datacontext = context_module::instance($cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallratings'), 'error' => false);
    }
    // remove all comments
    if (!empty($data->reset_data_comments)) {
        $DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
    }
    // updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('data', array('timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #22
0
ファイル: lib.php プロジェクト: edwinphillips/moodle-485cb39
/**
 * Actual implementation of the rest coures functionality, delete all the
 * data responses for course $data->courseid.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function data_reset_userdata($data)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $componentstr = get_string('modulenameplural', 'data');
    $status = array();
    $allrecordssql = "SELECT r.id\n                        FROM {$CFG->prefix}data_records r\n                             INNER JOIN {$CFG->prefix}data d ON r.dataid = d.id\n                       WHERE d.course = {$data->courseid}";
    $alldatassql = "SELECT d.id\n                      FROM {$CFG->prefix}data d\n                     WHERE d.course={$data->courseid}";
    // delete entries if requested
    if (!empty($data->reset_data)) {
        delete_records_select('data_ratings', "recordid IN ({$allrecordssql})");
        delete_records_select('data_comments', "recordid IN ({$allrecordssql})");
        delete_records_select('data_content', "recordid IN ({$allrecordssql})");
        delete_records_select('data_records', "dataid IN ({$alldatassql})");
        if ($datas = get_records_sql($alldatassql)) {
            foreach ($datas as $dataid => $unused) {
                fulldelete("{$CFG->dataroot}/{$data->courseid}/moddata/data/{$dataid}");
            }
        }
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallentries', 'data'), 'error' => false);
    }
    // remove entries by users not enrolled into course
    if (!empty($data->reset_data_notenrolled)) {
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted\n                         FROM {$CFG->prefix}data_records r\n                              INNER JOIN {$CFG->prefix}data d ON r.dataid = d.id\n                              LEFT OUTER JOIN {$CFG->prefix}user u ON r.userid = u.id\n                        WHERE d.course = {$data->courseid} AND r.userid > 0";
        $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
        $notenrolled = array();
        $fields = array();
        if ($rs = get_recordset_sql($recordssql)) {
            while ($record = rs_fetch_next_record($rs)) {
                if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted or !has_capability('moodle/course:view', $course_context, $record->userid)) {
                    delete_records('data_ratings', 'recordid', $record->id);
                    delete_records('data_comments', 'recordid', $record->id);
                    delete_records('data_content', 'recordid', $record->id);
                    delete_records('data_records', 'id', $record->id);
                    // HACK: this is ugly - the recordid should be before the fieldid!
                    if (!array_key_exists($record->dataid, $fields)) {
                        if ($fs = get_records('data_fields', 'dataid', $record->dataid)) {
                            $fields[$record->dataid] = array_keys($fs);
                        } else {
                            $fields[$record->dataid] = array();
                        }
                    }
                    foreach ($fields[$record->dataid] as $fieldid) {
                        fulldelete("{$CFG->dataroot}/{$data->courseid}/moddata/data/{$record->dataid}/{$fieldid}/{$record->id}");
                    }
                    $notenrolled[$record->userid] = true;
                }
            }
            rs_close($rs);
            $status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'data'), 'error' => false);
        }
    }
    // remove all ratings
    if (!empty($data->reset_data_ratings)) {
        delete_records_select('data_ratings', "recordid IN ({$allrecordssql})");
        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallratings'), 'error' => false);
    }
    // remove all comments
    if (!empty($data->reset_data_comments)) {
        delete_records_select('data_comments', "recordid IN ({$allrecordssql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
    }
    // updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('data', array('timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #23
0
ファイル: lib.php プロジェクト: nottmoo/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * data responses for course $data->courseid.
 *
 * @global object
 * @global object
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function data_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/filelib.php');
    require_once($CFG->dirroot.'/rating/lib.php');

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

    $allrecordssql = "SELECT r.id
                        FROM {data_records} r
                             INNER JOIN {data} d ON r.dataid = d.id
                       WHERE d.course = ?";

    $alldatassql = "SELECT d.id
                      FROM {data} d
                     WHERE d.course=?";

    $rm = new rating_manager();
    $ratingdeloptions = new stdClass;
    $ratingdeloptions->component = 'mod_data';
    $ratingdeloptions->ratingarea = 'entry';

    // delete entries if requested
    if (!empty($data->reset_data)) {
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
        $DB->delete_records_select('data_content', "recordid IN ($allrecordssql)", array($data->courseid));
        $DB->delete_records_select('data_records', "dataid IN ($alldatassql)", array($data->courseid));

        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid=>$unused) {
                fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$dataid");

                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
                    continue;
                }
                $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);

                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallentries', 'data'), 'error'=>false);
    }

    // remove entries by users not enrolled into course
    if (!empty($data->reset_data_notenrolled)) {
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted
                         FROM {data_records} r
                              JOIN {data} d ON r.dataid = d.id
                              LEFT JOIN {user} u ON r.userid = u.id
                        WHERE d.course = ? AND r.userid > 0";

        $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
        $notenrolled = array();
        $fields = array();
        $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
        foreach ($rs as $record) {
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
              or !is_enrolled($course_context, $record->userid)) {
                //delete ratings
                if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
                    continue;
                }
                $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
                $ratingdeloptions->contextid = $datacontext->id;
                $ratingdeloptions->itemid = $record->id;
                $rm->delete_ratings($ratingdeloptions);

                $DB->delete_records('comments', array('itemid'=>$record->id, 'commentarea'=>'database_entry'));
                $DB->delete_records('data_content', array('recordid'=>$record->id));
                $DB->delete_records('data_records', array('id'=>$record->id));
                // HACK: this is ugly - the recordid should be before the fieldid!
                if (!array_key_exists($record->dataid, $fields)) {
                    if ($fs = $DB->get_records('data_fields', array('dataid'=>$record->dataid))) {
                        $fields[$record->dataid] = array_keys($fs);
                    } else {
                        $fields[$record->dataid] = array();
                    }
                }
                foreach($fields[$record->dataid] as $fieldid) {
                    fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$record->dataid/$fieldid/$record->id");
                }
                $notenrolled[$record->userid] = true;
            }
        }
        $rs->close();
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
    }

    // remove all ratings
    if (!empty($data->reset_data_ratings)) {
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
            foreach ($datas as $dataid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
                    continue;
                }
                $datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);

                $ratingdeloptions->contextid = $datacontext->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        if (empty($data->reset_gradebook_grades)) {
            // remove all grades from gradebook
            data_reset_gradebook($data->courseid);
        }

        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
    }

    // remove all comments
    if (!empty($data->reset_data_comments)) {
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
    }

    // updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('data', array('timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto'), $data->timeshift, $data->courseid);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
    }

    return $status;
}
コード例 #24
0
ファイル: lib.php プロジェクト: r007/PMoodle
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified forum
 * and clean up any related data.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function forum_reset_userdata($data)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $componentstr = get_string('modulenameplural', 'forum');
    $status = array();
    $removeposts = false;
    if (!empty($data->reset_forum_all)) {
        $removeposts = true;
        $typesql = "";
        $typesstr = get_string('resetforumsall', 'forum');
        $types = array();
    } else {
        if (!empty($data->reset_forum_types)) {
            $removeposts = true;
            $typesql = "";
            $types = array();
            $forum_types_all = forum_get_forum_types_all();
            foreach ($data->reset_forum_types as $type) {
                if (!array_key_exists($type, $forum_types_all)) {
                    continue;
                }
                $typesql .= " AND f.type='{$type}'";
                $types[] = $forum_types_all[$type];
            }
            $typesstr = get_string('resetforums', 'forum') . ': ' . implode(', ', $types);
        }
    }
    $alldiscussionssql = "SELECT fd.id\n                            FROM {$CFG->prefix}forum_discussions fd, {$CFG->prefix}forum f\n                           WHERE f.course={$data->courseid} AND f.id=fd.forum";
    $allforumssql = "SELECT f.id\n                            FROM {$CFG->prefix}forum f\n                           WHERE f.course={$data->courseid}";
    $allpostssql = "SELECT fp.id\n                            FROM {$CFG->prefix}forum_posts fp, {$CFG->prefix}forum_discussions fd, {$CFG->prefix}forum f\n                           WHERE f.course={$data->courseid} AND f.id=fd.forum AND fd.id=fp.discussion";
    if ($removeposts) {
        $discussionssql = "{$alldiscussionssql} {$typesql}";
        $forumssql = "{$allforumssql} {$typesql}";
        $postssql = "{$allpostssql} {$typesql}";
        // first delete all read flags
        delete_records_select('forum_read', "forumid IN ({$forumssql})");
        // remove tracking prefs
        delete_records_select('forum_track_prefs', "forumid IN ({$forumssql})");
        // remove posts from queue
        delete_records_select('forum_queue', "discussionid IN ({$discussionssql})");
        // remove ratings
        delete_records_select('forum_ratings', "post IN ({$postssql})");
        // all posts
        delete_records_select('forum_posts', "discussion IN ({$discussionssql})");
        // finally all discussions
        delete_records_select('forum_discussions', "forum IN ({$forumssql})");
        // now get rid of all attachments
        if ($forums = get_records_sql($forumssql)) {
            foreach ($forums as $forumid => $unused) {
                fulldelete($CFG->dataroot . '/' . $data->courseid . '/moddata/forum/' . $forumid);
            }
        }
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            if (empty($types)) {
                forum_reset_gradebook($data->courseid);
            } else {
                foreach ($types as $type) {
                    forum_reset_gradebook($data->courseid, $type);
                }
            }
        }
        $status[] = array('component' => $componentstr, 'item' => $typesstr, 'error' => false);
    }
    // remove all ratings
    if (!empty($data->reset_forum_ratings)) {
        delete_records_select('forum_ratings', "post IN ({$allpostssql})");
        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            forum_reset_gradebook($data->courseid);
        }
    }
    // remove all subscriptions unconditionally - even for users still enrolled in course
    if (!empty($data->reset_forum_subscriptions)) {
        delete_records_select('forum_subscriptions', "forum IN ({$allforumssql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('resetsubscriptions', 'forum'), 'error' => false);
    }
    // remove all tracking prefs unconditionally - even for users still enrolled in course
    if (!empty($data->reset_forum_track_prefs)) {
        delete_records_select('forum_track_prefs', "forumid IN ({$allforumssql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('resettrackprefs', 'forum'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('forum', array('assesstimestart', 'assesstimefinish'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #25
0
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified certificate
 * and clean up any related data.
 *
 * Written by Jean-Michel Vedrine
 *
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function certificate_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'certificate');
    $status = array();
    if (!empty($data->reset_certificate)) {
        $sql = "SELECT cert.id\n                FROM {certificate} cert\n                WHERE cert.course = :courseid";
        $DB->delete_records_select('certificate_issues', "certificateid IN ({$sql})", array('courseid' => $data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('certificateremoved', 'certificate'), 'error' => false);
    }
    // Updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('certificate', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #26
0
/**
 * Actual implementation of the rest coures functionality, delete all the
 * booking responses for course $data->courseid.
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function booking_reset_userdata($data)
{
    global $CFG, $DB;
    $componentstr = get_string('modulenameplural', 'booking');
    $status = array();
    if (!empty($data->reset_booking)) {
        $bookingssql = "SELECT ch.id\n\t\tFROM {$CFG->prefix}booking ch\n\t\tWHERE ch.course={$data->courseid}";
        $DB->delete_records_select('booking_answers', "bookingid IN ({$bookingssql})");
        $status[] = array('component' => $componentstr, 'item' => get_string('removeresponses', 'booking'), 'error' => false);
    }
    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('booking', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}
コード例 #27
0
ファイル: locallib.php プロジェクト: covex-nn/moodle
 /**
  * Actual implementation of the reset course functionality, delete all the
  * assignment submissions for course $data->courseid.
  *
  * @param stdClass $data the data submitted from the reset course.
  * @return array status array
  */
 public function reset_userdata($data)
 {
     global $CFG, $DB;
     $componentstr = get_string('modulenameplural', 'assign');
     $status = array();
     $fs = get_file_storage();
     if (!empty($data->reset_assign_submissions)) {
         // Delete files associated with this assignment.
         foreach ($this->submissionplugins as $plugin) {
             $fileareas = array();
             $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
             $fileareas = $plugin->get_file_areas();
             foreach ($fileareas as $filearea) {
                 $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
             }
             if (!$plugin->delete_instance()) {
                 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => $plugin->get_error());
             }
         }
         foreach ($this->feedbackplugins as $plugin) {
             $fileareas = array();
             $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
             $fileareas = $plugin->get_file_areas();
             foreach ($fileareas as $filearea) {
                 $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
             }
             if (!$plugin->delete_instance()) {
                 $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => $plugin->get_error());
             }
         }
         $assignssql = 'SELECT a.id
                          FROM {assign} a
                        WHERE a.course=:course';
         $params = array('course' => $data->courseid);
         $DB->delete_records_select('assign_submission', "assignment IN ({$assignssql})", $params);
         $status[] = array('component' => $componentstr, 'item' => get_string('deleteallsubmissions', 'assign'), 'error' => false);
         if (!empty($data->reset_gradebook_grades)) {
             $DB->delete_records_select('assign_grades', "assignment IN ({$assignssql})", $params);
             // Remove all grades from gradebook.
             require_once $CFG->dirroot . '/mod/assign/lib.php';
             assign_reset_gradebook($data->courseid);
         }
     }
     // Updating dates - shift may be negative too.
     if ($data->timeshift) {
         shift_course_mod_dates('assign', array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'), $data->timeshift, $data->courseid, $this->get_instance()->id);
         $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
     }
     return $status;
 }
コード例 #28
0
ファイル: lib.php プロジェクト: nutanrajmalanai/moodle
/**
 * Actual implementation of the reset course functionality, delete all the
 * quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is
 * set and true.
 *
 * Also, move the quiz open and close dates, if the course start date is changing.
 *
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function quiz_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->libdir . '/questionlib.php');

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

    // Delete attempts.
    if (!empty($data->reset_quiz_attempts)) {
        question_engine::delete_questions_usage_by_activities(new qubaid_join(
                '{quiz_attempts} quiza JOIN {quiz} quiz ON quiza.quiz = quiz.id',
                'quiza.uniqueid', 'quiz.course = :quizcourseid',
                array('quizcourseid' => $data->courseid)));

        $DB->delete_records_select('quiz_attempts',
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid));
        $status[] = array(
            'component' => $componentstr,
            'item' => get_string('attemptsdeleted', 'quiz'),
            'error' => false);

        // Remove all grades from gradebook.
        $DB->delete_records_select('quiz_grades',
                'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid));
        if (empty($data->reset_gradebook_grades)) {
            quiz_reset_gradebook($data->courseid);
        }
        $status[] = array(
            'component' => $componentstr,
            'item' => get_string('gradesdeleted', 'quiz'),
            'error' => false);
    }

    // Updating dates - shift may be negative too.
    if ($data->timeshift) {
        $DB->execute("UPDATE {quiz_overrides}
                         SET timeopen = timeopen + ?
                       WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?)
                         AND timeopen <> 0", array($data->timeshift, $data->courseid));
        $DB->execute("UPDATE {quiz_overrides}
                         SET timeclose = timeclose + ?
                       WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?)
                         AND timeclose <> 0", array($data->timeshift, $data->courseid));

        shift_course_mod_dates('quiz', array('timeopen', 'timeclose'),
                $data->timeshift, $data->courseid);

        $status[] = array(
            'component' => $componentstr,
            'item' => get_string('openclosedatesupdated', 'quiz'),
            'error' => false);
    }

    return $status;
}
コード例 #29
0
ファイル: lib.php プロジェクト: Jtgadbois/Pedadida
/**
 * This function is used by the reset_course_userdata function in moodlelib.
 * This function will remove all posts from the specified forum
 * and clean up any related data.
 *
 * @global object
 * @global object
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function forum_reset_userdata($data) {
    global $CFG, $DB;
    require_once($CFG->dirroot.'/rating/lib.php');

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

    $params = array($data->courseid);

    $removeposts = false;
    $typesql     = "";
    if (!empty($data->reset_forum_all)) {
        $removeposts = true;
        $typesstr    = get_string('resetforumsall', 'forum');
        $types       = array();
    } else if (!empty($data->reset_forum_types)){
        $removeposts = true;
        $typesql     = "";
        $types       = array();
        $forum_types_all = forum_get_forum_types_all();
        foreach ($data->reset_forum_types as $type) {
            if (!array_key_exists($type, $forum_types_all)) {
                continue;
            }
            $typesql .= " AND f.type=?";
            $types[] = $forum_types_all[$type];
            $params[] = $type;
        }
        $typesstr = get_string('resetforums', 'forum').': '.implode(', ', $types);
    }
    $alldiscussionssql = "SELECT fd.id
                            FROM {forum_discussions} fd, {forum} f
                           WHERE f.course=? AND f.id=fd.forum";

    $allforumssql      = "SELECT f.id
                            FROM {forum} f
                           WHERE f.course=?";

    $allpostssql       = "SELECT fp.id
                            FROM {forum_posts} fp, {forum_discussions} fd, {forum} f
                           WHERE f.course=? AND f.id=fd.forum AND fd.id=fp.discussion";

    $forumssql = $forums = $rm = null;

    if( $removeposts || !empty($data->reset_forum_ratings) ) {
        $forumssql      = "$allforumssql $typesql";
        $forums = $forums = $DB->get_records_sql($forumssql, $params);
        $rm = new rating_manager();
        $ratingdeloptions = new stdClass;
        $ratingdeloptions->component = 'mod_forum';
        $ratingdeloptions->ratingarea = 'post';
    }

    if ($removeposts) {
        $discussionssql = "$alldiscussionssql $typesql";
        $postssql       = "$allpostssql $typesql";

        // now get rid of all attachments
        $fs = get_file_storage();
        if ($forums) {
            foreach ($forums as $forumid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
                    continue;
                }
                $context = context_module::instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_forum', 'attachment');
                $fs->delete_area_files($context->id, 'mod_forum', 'post');

                //remove ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // first delete all read flags
        $DB->delete_records_select('forum_read', "forumid IN ($forumssql)", $params);

        // remove tracking prefs
        $DB->delete_records_select('forum_track_prefs', "forumid IN ($forumssql)", $params);

        // remove posts from queue
        $DB->delete_records_select('forum_queue', "discussionid IN ($discussionssql)", $params);

        // all posts - initial posts must be kept in single simple discussion forums
        $DB->delete_records_select('forum_posts', "discussion IN ($discussionssql) AND parent <> 0", $params); // first all children
        $DB->delete_records_select('forum_posts', "discussion IN ($discussionssql AND f.type <> 'single') AND parent = 0", $params); // now the initial posts for non single simple

        // finally all discussions except single simple forums
        $DB->delete_records_select('forum_discussions', "forum IN ($forumssql AND f.type <> 'single')", $params);

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            if (empty($types)) {
                forum_reset_gradebook($data->courseid);
            } else {
                foreach ($types as $type) {
                    forum_reset_gradebook($data->courseid, $type);
                }
            }
        }

        $status[] = array('component'=>$componentstr, 'item'=>$typesstr, 'error'=>false);
    }

    // remove all ratings in this course's forums
    if (!empty($data->reset_forum_ratings)) {
        if ($forums) {
            foreach ($forums as $forumid=>$unused) {
                if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
                    continue;
                }
                $context = context_module::instance($cm->id);

                //remove ratings
                $ratingdeloptions->contextid = $context->id;
                $rm->delete_ratings($ratingdeloptions);
            }
        }

        // remove all grades from gradebook
        if (empty($data->reset_gradebook_grades)) {
            forum_reset_gradebook($data->courseid);
        }
    }

    // remove all subscriptions unconditionally - even for users still enrolled in course
    if (!empty($data->reset_forum_subscriptions)) {
        $DB->delete_records_select('forum_subscriptions', "forum IN ($allforumssql)", $params);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('resetsubscriptions','forum'), 'error'=>false);
    }

    // remove all tracking prefs unconditionally - even for users still enrolled in course
    if (!empty($data->reset_forum_track_prefs)) {
        $DB->delete_records_select('forum_track_prefs', "forumid IN ($allforumssql)", $params);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('resettrackprefs','forum'), 'error'=>false);
    }

    /// updating dates - shift may be negative too
    if ($data->timeshift) {
        shift_course_mod_dates('forum', array('assesstimestart', 'assesstimefinish'), $data->timeshift, $data->courseid);
        $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
    }

    return $status;
}
コード例 #30
0
/**
 * Actual implementation of the reset course functionality, delete all the
 * treasure hunt attempts for course $data->courseid, if $data->reset_treasurehunt_attempts is
 * set and true.
 *
 * Also, move the treasurehunt open and close dates, if the course start date is changing.
 *
 * @param object $data the data submitted from the reset course.
 * @return array status array
 */
function treasurehunt_reset_userdata($data)
{
    global $DB;
    $componentstr = get_string('modulenameplural', 'treasurehunt');
    $status = array();
    // Delete attempts.
    if (!empty($data->reset_treasurehunt_attempts)) {
        $DB->delete_records_select('treasurehunt_attempts', 'stageid IN (SELECT ri.id FROM {treasurehunt} t INNER JOIN ' . '{treasurehunt_roads} r ON t.id=r.treasurehuntid INNER JOIN ' . '{treasurehunt_stages} ri ON r.id=ri.roadid WHERE t.course = ?)', array($data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('attemptsdeleted', 'treasurehunt'), 'error' => false);
        // Remove all grades from gradebook.
        if (!empty($data->reset_gradebook_grades)) {
            treasurehunt_reset_gradebook($data->courseid);
            $status[] = array('component' => $componentstr, 'item' => get_string('gradesdeleted', 'treasurehunt'), 'error' => false);
        }
    }
    // Updating dates - shift may be negative too.
    if ($data->timeshift) {
        shift_course_mod_dates('treasurehunt', array('allowattemptsfromdate', 'cutoffdate'), $data->timeshift, $data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    return $status;
}