如何在Moodle中保存测验尝试步骤数据?

时间:2014-01-01 14:33:29

标签: php moodle

我正在编写一个自定义Moodle(2.6)Web服务来接受moodle测验,这需要创建尝试或开始尝试。我编写了API来开始尝试,并获得特定测验的问题。但是,我无法弄清楚如何保存用户对问题尝试的响应。 (问题尝试步骤数据)。如果有人能帮助我,我将不胜感激。

    //Fetch all the user attempts

    $attempts = quiz_get_user_attempts($quizObj->get_quizid(), 3, 'all', true);

    //Get the last attempt

    $lastattempt = end($attempts);


    // Delete any previous preview attempts belonging to this user.
    quiz_delete_previews($quizObj->get_quiz(), $USER->id);

    //fetch the quiz usage object
    $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizObj->get_context());


    $quba->set_preferred_behaviour($quizObj->get_quiz()->preferredbehaviour);


    // Create the new attempt and initialize the question sessions
    $timenow = time(); // Update time now, in case the server is running really slowly.
    $attempt = quiz_create_attempt($quizObj, $attemptnumber, $lastattempt, $timenow, $quizObj->is_preview_user());


    if ($lastAttemptStatus == quiz_attempt::FINISHED) {
        $attemptnumber = $lastattempt->attempt + 1;

        $attempt = quiz_start_new_attempt($quizObj, $quba, $attempt, $attemptnumber, $timenow);


    } elseif ($lastAttemptStatus == quiz_attempt::IN_PROGRESS) {
        $attempt = quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt);

    }

//就在这里让我们说我想硬编码(得到参数)用户对特定问题的测验的响应必须去...并且我已将这些响应添加为尝试步骤数据..

    $transaction = $DB->start_delegated_transaction();


    $attempt = quiz_attempt_save_started($quizObj, $quba, $attempt);
    quiz_fire_attempt_started_event($attempt, $quizObj);

    $transaction->allow_commit();

    $lastattempt = end($attempts);

1 个答案:

答案 0 :(得分:1)

要保存测验,您需要调用 mod_quiz_save_attempt API 在参数中回答问题。

例如:

yourButton.addEventListener("click", function(){
    function(){
        alert($(this).text());
    };
});

有关详细信息refer this link