LLMS_Quiz_Attempt::answer_question( int $question_id, int $answer )
Answer a question records the selected option and whether or not the selected option was the correct option Automatically updates & saves the attempt to the database
Description Description
Parameters Parameters
- $question_id
-
(int) (Required) WP_Post ID of the LLMS_Question
- $answer
-
(int) (Required) index/key of the selected answer option as found in the array of options retrieved by LLMS_Question->get_options()
Return Return
($this)
Source Source
File: includes/models/model.llms.quiz.attempt.php
public function answer_question( $question_id, $answer ) { $questions = $this->get_questions(); foreach ( $questions as $key => $data ) { if ( $question_id != $data['id'] ) { continue; } $question = llms_get_post( $question_id ); $graded = $question->grade( $answer ); $questions[ $key ]['answer'] = $answer; $questions[ $key ]['correct'] = $graded; if ( llms_parse_bool( $graded ) ) { $questions[ $key ]['earned'] = $questions[ $key ]['points']; } break; } $this->set_questions( $questions )->save(); return $this; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: