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

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

    XMLWordPrintable

    Details

    • Testing Instructions:
      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
    • Affected Branches:
      MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE, MOODLE_37_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-66409-edit-numerical/master

      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

            Assignee:
            rsnts Raphael Santos
            Reporter:
            rsnts Raphael Santos
            Peer reviewer:
            Peter Dias
            Integrator:
            Jake Dallimore
            Tester:
            Janelle Barcega
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            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