LLMS_Quiz_Attempt::init( int $quiz_id, int $lesson_id, mixed $student = null )
Initialize a new quiz attempt by quiz and lesson for a user
Description Description
If no user found throws an Exception.
Parameters Parameters
- $quiz_id
-
(int) (Required) WP Post ID of the quiz.
- $lesson_id
-
(int) (Required) WP Post ID of the lesson.
- $student
-
(mixed) (Optional) Accepts anything that can be passed to llms_get_student. If no user is passed the current user will be used. Default
null
.Default value: null
Return Return
(obj)
Source Source
File: includes/models/model.llms.quiz.attempt.php
* @return obj */ public static function init( $quiz_id, $lesson_id, $student = null ) { $student = llms_get_student( $student ); if ( ! $student ) { throw new Exception( __( 'You must be logged in to take a quiz!', 'lifterlms' ) ); } // Initialize a new attempt. $attempt = new self(); $attempt->set( 'quiz_id', $quiz_id ); $attempt->set( 'lesson_id', $lesson_id ); $attempt->set( 'student_id', $student->get_id() ); $attempt->set_status( 'incomplete' ); $attempt->set_questions( $attempt->get_new_questions() ); $number = 1; $last_attempt = $student->quizzes()->get_last_attempt( $quiz_id ); if ( $last_attempt ) { $number = absint( $last_attempt->get( 'attempt' ) ) + 1; } $attempt->set( 'attempt', $number ); return $attempt;
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |