예제 #1
0
파일: locallib.php 프로젝트: rwijaya/moodle
/**
 * Fire an event to tell the rest of Moodle a quiz attempt has started.
 *
 * @param object $attempt
 * @param quiz   $quizobj
 */
function quiz_fire_attempt_started_event($attempt, $quizobj) {
    // Trigger event.
    $eventdata = array();
    $eventdata['context'] = $quizobj->get_context();
    $eventdata['courseid'] = $quizobj->get_courseid();
    $eventdata['relateduserid'] = $attempt->userid;
    $eventdata['objectid'] = $attempt->id;
    $event = \mod_quiz\event\attempt_started::create($eventdata);
    $event->add_record_snapshot('quiz', $quizobj->get_quiz());
    $event->add_record_snapshot('quiz_attempts', $attempt);
    $event->trigger();
}
예제 #2
0
/**
 * The save started question usage and quiz attempt in db and log the started attempt.
 *
 * @param quiz                       $quizobj
 * @param question_usage_by_activity $quba
 * @param object                     $attempt
 * @return object                    attempt object with uniqueid and id set.
 */
function quiz_attempt_save_started($quizobj, $quba, $attempt)
{
    global $DB;
    // Save the attempt in the database.
    question_engine::save_questions_usage_by_activity($quba);
    $attempt->uniqueid = $quba->get_id();
    $attempt->id = $DB->insert_record('quiz_attempts', $attempt);
    // Params used by the events below.
    $params = array('objectid' => $attempt->id, 'relateduserid' => $attempt->userid, 'courseid' => $quizobj->get_courseid(), 'context' => $quizobj->get_context());
    // Decide which event we are using.
    if ($attempt->preview) {
        $params['other'] = array('quizid' => $quizobj->get_quizid());
        $event = \mod_quiz\event\attempt_preview_started::create($params);
    } else {
        $event = \mod_quiz\event\attempt_started::create($params);
    }
    // Trigger the event.
    $event->add_record_snapshot('quiz', $quizobj->get_quiz());
    $event->add_record_snapshot('quiz_attempts', $attempt);
    $event->trigger();
    return $attempt;
}