Incorrect number of mandatory items

We have 10 unit in our course and for each unit we have selected 'User needs to answer all mandatory assessments and view all pages in order to access the next unit'. This working except that in unit two there are 12 mandatory questions, but when all questions are answered the course progress page says '12 of 13 mandatory items completed'. This prevents the student from progressing to the next unit.

There are only 12 questions. In the student assessment it correctly shows that 12 questions have been answered. How do I find and remove this 'phantom' 13th answer field?

Gary

  • Milan

    Hello @teckyhead,

    I hope you are having a good day and thanks for asking us. :slight_smile:

    Dear member first of all I tried to replicate this issue on my sandbox site but no luck. so it seems I'll need access to your site, Will you please grant me support staff access so that I can check in depth regarding your issue ?. You can grant me support access via WPMU DEV > Support > Support Access > Grant Access.

    Have a great day. :slight_smile:

    Thanks & Kind Regards,
    Milan Savaliya.

  • Predrag Dubajic

    Hi Gary,

    I was doing some extensive testing on your site but still can't figure out what's causing this on your end, number of mandatory elements is indeed 12 and can't figure out what's adding that extra one.

    I will need to ping some of our second level support dev guys in here to see if they have any thoughts on this.
    Please note that, developer response might be slower than usual staff response, so we appreciate your patience on this.

    Best regards,
    Predrag

  • teckyhead

    Hi Predrag,

    I managed to fix this but it does seem like the plugin has a bug that is causing some of the course meta data to remain when an answer field is removed. Here's how I tracked this down:

    First up I tracked through the code to find the point at which the number of mandatory items is calculated. This happens in the get_module_completion_data function in class.course.unit.php. I added a var_dump for the $criteria array and it gave me the list of mandatory modules' post IDs:

    array(6) {
    ["mandatory_modules"]=>
    array(13) {
    [0]=>
    int(153)~
    [1]=>
    int(155)~
    [2]=>
    int(158)~
    [3]=>
    int(160)~
    [4]=>
    int(199) <==
    [5]=>
    int(1404)~
    [6]=>
    int(1406)~
    [7]=>
    int(1408)~
    [8]=>
    int(1410)~
    [9]=>
    int(1412)~
    [10]=>
    int(1416)~
    [11]=>
    int(1474)~
    [12]=>
    int(3159)~
    }

    I then checked these in the database and they all existed except for post number 199. It wasn't in the wp_posts table or the wp_post_meta table.

    I then had a look in the wp_post_meta table and tracked down the relevant data in the input_modules row for the course (hope this formats okay...):

    a:13:{
    i:153;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:155;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:158;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:160;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:199;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1404;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1406;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1408;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1410;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1412;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1416;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:3:"yes";s:20:"limit_attempts_value";s:1:"1";}
    i:1474;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:0:"";s:14:"limit_attempts";s:2:"no";s:20:"limit_attempts_value";s:0:"";}
    i:3159;a:5:{s:16:"mandatory_answer";s:3:"yes";s:15:"gradable_answer";s:2:"no";s:22:"minimum_grade_required";s:3:"100";s:14:"limit_attempts";s:2:"no";s:20:"limit_attempts_value";s:1:"1";}
    }

    I removed the entry for post ID 199 (the line that starts with i:199) and it now displays the correct number of mandatory items and allows me to complete that unit.

    I'll have a look at our other course now and see if the issue can be resolved in the same way.

    Gary

  • Jose

    Hello there Gary,

    Hope you are doing great, and thanks for the detailed report.

    I'm guessing there's some caching somewhere...

    Yes. Due to performance concerns, the completion data for each student is cached in the session for 1 hour.
    There are some specific changes that will trigger a session refresh. Deleting a module wasn't one of those changes, so I went ahead and fixed it so that the deleted module is reflected in student's completion immediately.

    With regard to the original problem, I wasn't able to reproduce it. Nevertheless, I added some improvements to prevent any possible glitch.
    If you take a look in delete_module() method in wp-content/plugins/coursepress/includes/classes/class.course.unit.module.php you will notice the following call that updates the input_modules metadata accordingly:

    // Remove input module meta
    Unit::delete_input_module_meta( $unit_id, $id );

    So, the only way to re-create the issue would be deleting the modules without using this method.
    There is also a small chance that something is going wrong on your end before the metadata deletion is actually processed. In order to prevent any possible issue, I wrapped this routine in a transaction.

    All these improvements should be out soon with the next release :slight_smile:

    Cheers,
    José

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.