• Resolved chanart

    (@chanart)


    I’d be happy if someone could tell me how I can return/echo the status of a lession completion (for a kind of a dashboard I’m creating). I manage to return the user Id, course ID, lesson id, but not the completion status – I constantly get errors.

    P.S. chatGPT is moving in circles as well… 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter chanart

    (@chanart)

    oops, lesson.. lesson 🙂

    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Hello there, @chanart!

    I have asked our developers to chime in, as this goes beyond my knowledge.

    We’ll circle back to you as soon as we have info to share – thanks for bearing with us!

    Plugin Author Dmitry Merkushin (a11n)

    (@merkushin)

    Hi @chanart

    One option is to use the lesson progress repository. We keep a copy of the instance in the public property, so you can do something like that:

    $progress = Sensei()->lesson_progress_repository->get( $lesson_id, $user_id );

    If the progress exists for the user in the lesson, you get a progress object.

    The described approach is a work in progress.

    Another option is to use the old way of getting lesson status:

    \Sensei_Utils::sensei_check_for_activity( array(
    	'type'    => 'sensei_lesson_status',
    	'user_id' => $user_id,
    	'post_id' => $lesson_id,
    ) );
    Thread Starter chanart

    (@chanart)

    Hi Dmitry, thanks!

    I tried the Sensei_Utils approach before and constantly got some errors. I found the lesson completion information in the wp_comments table and managed to retrieve it by creating the following function and then call it on a page in an if statement.. Seems to work 🙂

    function has_approved_comment( $user_id, $post_id, $status = 'complete' ) {
        $args = array(
            'user_id' => $user_id,
            'post_id' => $post_id,
            'status' => $status,
            'number' => 1, // Retrieve only one comment
        );
        $comments = get_comments( $args );
        return ( count( $comments ) > 0 );
    }
    
    // And then run it on the page in an if statement on the page I want:
    
    $current_user_id = get_current_user_id();
    $post_id = get_the_ID();
    
    if ( has_approved_comment( $current_user_id, $post_id, 'complete' ) ) {
        echo "completed";
    } else {
        echo "in progress";
    }
    
    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Hey @chanart,

    Thanks for sharing this! it will be very helpful for other users if they need a solution like this.

    You should be all set now! Happy to mark this as solved if you don’t have any further questions 🙂

    Thread Starter chanart

    (@chanart)

    Yeah, seems good 🙂

    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Fantastic 🙂

    I’m going to mark this thread as solved. If you have any further questions or need more help, you’re welcome to open another thread here. Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘return or echo lession completion status?’ is closed to new replies.