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 if no user is passed the current user will be used if no user found returns a WP_Error
Description Description
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
Default value: null
Return Return
(obj) $this (for chaining)
Source Source
File: includes/models/model.llms.quiz.attempt.php
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. |
User Contributed Notes User Contributed Notes
Permalink: