Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-45686

In multichoice multianswer question type get_num_selected_choices return wrong number of selected choices

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6.3, 2.7
    • Fix Version/s: 2.6.4, 2.7.1
    • Component/s: Questions
    • Labels:
    • Testing Instructions:
      Hide

      It's not easy to test this in core Moodle because the get_num_selected_choices function is only used to detect when the student has selected too many choices and in that case disable clearing wrong responses and displaying a message on screen.
      The easiest way to test this is to install Open University plugin oumultiresponse question type (see https://moodle.org/plugins/view.php?plugin=qtype_oumultiresponse).

      • Create an oumultiresponse question with 2 correct answers
      • Create a quiz with settings : unlimited attempts, each attempt build on last, deferred feedback for how questions behave and last attempt grading method (all these settings are importants to trigger the bug)
      • include the oumultiresponse question in this quiz
      • attempt the quiz as a student
      • on first attempt answer the question correctly
      • submit all and finish
      • review your attempt and verify you get the maximum grade
      • start a second attempt
      • don't change your response, just submit all and finish
      • review your second attempt and verify that you still get the maximum grade (before this patch the second attempt was graded as partially correct and a "You have selected too many options." feedback was displayed)
      Show
      It's not easy to test this in core Moodle because the get_num_selected_choices function is only used to detect when the student has selected too many choices and in that case disable clearing wrong responses and displaying a message on screen. The easiest way to test this is to install Open University plugin oumultiresponse question type (see https://moodle.org/plugins/view.php?plugin=qtype_oumultiresponse ). Create an oumultiresponse question with 2 correct answers Create a quiz with settings : unlimited attempts, each attempt build on last, deferred feedback for how questions behave and last attempt grading method (all these settings are importants to trigger the bug) include the oumultiresponse question in this quiz attempt the quiz as a student on first attempt answer the question correctly submit all and finish review your attempt and verify you get the maximum grade start a second attempt don't change your response, just submit all and finish review your second attempt and verify that you still get the maximum grade (before this patch the second attempt was graded as partially correct and a "You have selected too many options." feedback was displayed)
    • Affected Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull Master Branch:

      Description

      php docblock for get_num_selected_choices function says:

         /**
           * @param array $response responses, as returned by
           *      {@link question_attempt_step::get_qt_data()}.
           * @return int the number of choices that were selected. in this response.
           */ 
      

      But this is not working as expected because question_attempt_step::get_qt_data can return an array containing other elements than those related to choices, for instance the core qtype_multichoice_multi_question return an array with an '_order' element. So the count of selected answers is wrong by 1.
      We need to filter such element discarting those where the name start with an underscore.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                14/Jul/14