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

Lesson's numerical answers with value 0 are deleted on edit

XMLWordPrintable

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • MOODLE_36_STABLE, MOODLE_37_STABLE
    • MDL-66409-edit-numerical/master
    • Hide
      • Create a course
      • In that course, create a lesson activity
      • In that lesson activity, add a numerical question page
      • Set one answer to 0
      • Save the page
      • Edit the page and save the page again
      • The 0 answer must still be present
      Show
      Create a course In that course, create a lesson activity In that lesson activity, add a numerical question page Set one answer to 0 Save the page Edit the page and save the page again The 0 answer must still be present

      When editing a numerical question in a lesson, all the answers equal to zero are being deleted.

      This has been fixed when adding such an answer (MDL-57366) but editing is still broken.

      The field text value is saved into a lesson_page_answer (extending lesson_base) object. And within that class, the isset function is overridden and is returning the empty function result.

      Which makes this test https://github.com/moodle/moodle/blob/MOODLE_36_STABLE/mod/lesson/locallib.php#L4479 fail. The answer is therefore dropped.

      A simple fix would be to replace the test mentioned above:

       if (isset($this->answers[$i]->answer) && $this->answers[$i]->answer != '') {
      

      with

      if ($this->answers[$i]->answer !== null && $this->answers[$i]->answer !== '') {
      

      to avoid calling the "magic" isset function.

       

      In order to reproduce the issue:

      • Create a new lesson
      • Add a new numerical page
      • Add an answer with value of 0
      • Save the question
      • Edit that question and save it again

      => The answer is dropped.

            rsnts Raphael Santos
            rsnts Raphael Santos
            Peter Dias Peter Dias
            Jake Dallimore Jake Dallimore
            Janelle Barcega Janelle Barcega
            Votes:
            11 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 22 minutes
                22m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.