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

标签 php moodle

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

请指导我。

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

最佳答案

来自 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;
}

主要细节请引用源码。

关于php - moodle 如何在数据库中保存用户测验响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2452647/

相关文章:

php - 从php删除后重置mysql自动递增字段值?

php - #1136 - 列数与第 1 行的值数不匹配,但查询写得很好

moodle - BigBlueButton网课结束后如何回放录制的视频

moodle - 自动从一个网站登录到 Moodle 网站?

javascript - 使用 javascript 访问 php 变量

php - 有没有办法记录 SQLite 查询?

php - 在 Laravel 中使用 id 重定向

php - 如何设计一个多对多关系的模式,其中一个表用于存储有序项目?

moodle_database::insert_record_raw() 未找到字段

moodle - 在 Moodle 2.7 中从头开始自定义主题开发