LLMS_Controller_Lesson_Progression::quiz_maybe_prevent_lesson_completion( bool $allow_completion, int $user_id, int $lesson_id, string $trigger, array $args )

Before a lesson is marked as complete, check if all the lesson’s quiz requirements are met


Parameters Parameters

$allow_completion

(bool) (Required) Whether or not to allow completion (true by default, false if something else has already prevented).

$user_id

(int) (Required) WP User ID of the student completing the lesson.

$lesson_id

(int) (Required) WP Post ID of the lesson to be completed.

$trigger

(string) (Required) Text string to record the reason why the lesson is being completed.

$args

(array) (Optional) additional arguments from the triggering function.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/controllers/class.llms.controller.lesson.progression.php

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
public function quiz_maybe_prevent_lesson_completion( $allow_completion, $user_id, $lesson_id, $trigger, $args ) {
 
    // If allow completion is already false, we don't need to run any quiz checks.
    if ( ! $allow_completion ) {
        return $allow_completion;
    }
 
    $lesson           = llms_get_post( $lesson_id );
    $passing_required = llms_parse_bool( $lesson->get( 'require_passing_grade' ) );
 
    // If the lesson is being completed by a quiz.
    if ( 0 === strpos( $trigger, 'quiz_' ) ) {
 
        // Passing is required AND the attempt was a failure.
        if ( $passing_required && ! $args['attempt']->is_passing() ) {
            $allow_completion = false;
        }
    } elseif ( $lesson->is_quiz_enabled() ) {
 
        $quiz_id = $lesson->get( 'quiz' );
        $student = llms_get_student( $user_id );
        $attempt = $student->quizzes()->get_best_attempt( $quiz_id );
 
        // Passing is not required but there's not attempts yet.
        // At least one attempt (passing or otherwise) is required!.
        if ( ! $passing_required && ! $attempt ) {
            $allow_completion = false;
 
            // Passing is required and there's no attempts or the best attempt is not passing.
        } elseif ( $passing_required && ( ! $attempt || ! $attempt->is_passing() ) ) {
            $allow_completion = false;
        }
    }
 
    return $allow_completion;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.17.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.