moodle如何在数据库中保存用户测验响应?

时间:2010-03-16 07:14:47

标签: php moodle

moodle1.9如何在数据库中保存用户尝试测验结果,以及在用户尝试任何测验时更新哪些表?

请指导我。

如果可能请更新我,哪些函数用于在moodle1.9数据库中插入用户测验尝试数据?

1 个答案:

答案 0 :(得分:4)

来自attempt.php文件(Moodle 1.9.7):

$attempt = quiz_create_attempt($quiz, $attemptnumber);

然后:

if (!$attempt->id = insert_record('quiz_attempts', $attempt)) {
            error('Could not create new attempt');
        }

来自locallib.php

/**
 * Creates an object to represent a new attempt at a quiz
 *
 * Creates an attempt object to represent an attempt at the quiz by the current
 * user starting at the current time. The ->id field is not set. The object is
 * NOT written to the database.
 * @return object                The newly created attempt object.
 * @param object $quiz           The quiz to create an attempt for.
 * @param integer $attemptnumber The sequence number for the attempt.
 */
function quiz_create_attempt($quiz, $attemptnumber) {
    global $USER, $CFG;

    if (!$attemptnumber > 1 or !$quiz->attemptonlast or !$attempt = get_record('quiz_attempts', 'quiz', $quiz->id, 'userid', $USER->id, 'attempt', $attemptnumber-1)) {
        // we are not building on last attempt so create a new attempt
        $attempt->quiz = $quiz->id;
        $attempt->userid = $USER->id;
        $attempt->preview = 0;
        if ($quiz->shufflequestions) {
            $attempt->layout = quiz_repaginate($quiz->questions, $quiz->questionsperpage, true);
        } else {
            $attempt->layout = $quiz->questions;
        }
    }

    $timenow = time();
    $attempt->attempt = $attemptnumber;
    $attempt->sumgrades = 0.0;
    $attempt->timestart = $timenow;
    $attempt->timefinish = 0;
    $attempt->timemodified = $timenow;
    $attempt->uniqueid = question_new_attempt_uniqueid();

    return $attempt;
}

请参阅源代码了解主要详情。