當前位置: 首頁>>代碼示例>>PHP>>正文


PHP lesson_reset_gradebook函數代碼示例

本文整理匯總了PHP中lesson_reset_gradebook函數的典型用法代碼示例。如果您正苦於以下問題:PHP lesson_reset_gradebook函數的具體用法?PHP lesson_reset_gradebook怎麽用?PHP lesson_reset_gradebook使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了lesson_reset_gradebook函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: lesson_reset_userdata

/**
 * 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;
}
開發者ID:alanaipe2015,項目名稱:moodle,代碼行數:58,代碼來源:lib.php


注:本文中的lesson_reset_gradebook函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。