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

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

    XMLWordPrintable

    Details

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              11 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Nov/19

                Time Tracking

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