Exemple #1
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;
}
Exemple #2
0
/**
 * 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;
}