Moodle
  1. Moodle
  2. MDL-27757

Load missing data if required in completion_info::is_enabled()

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4
    • Component/s: Course completion
    • Labels:
    • Rank:
      17444

      Description

      If an instance of the completion_info class is created with only a placeholder course object (e.g. with only 'id' => 2), the is_enabled() function will throw a notice when trying to access the course's "enablecompletion" property. Here is a patch to lazy load that field if it is missing and is needed.

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          Hi, Aaron.

          This is your baby, so I assume you know what you mean, but it would be good to add a few details to this issue, if nothing else, so we can keep an eye on it at HQ.

          Michael;

          Show
          Michael de Raadt added a comment - Hi, Aaron. This is your baby, so I assume you know what you mean, but it would be good to add a few details to this issue, if nothing else, so we can keep an eye on it at HQ. Michael;
          Hide
          Aaron Barnes added a comment -

          @Michael

          All done, thanks.

          Show
          Aaron Barnes added a comment - @Michael All done, thanks.
          Hide
          Sam Hemelryk added a comment -

          Thanks Aaron - this has been integrated now.
          Cheers
          Sam

          Show
          Sam Hemelryk added a comment - Thanks Aaron - this has been integrated now. Cheers Sam
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Passing test: I've executed this in one forum/view.php hacked file:

          $co = new stdclass();
          $co->id = $course->id;
          $completion = new completion_info($co);
          print_object($co);
          $completion->is_enabled();
          print_object($co);
          

          And lazy load worked as expected, without outputting any notice at all with results:

          stdClass Object
          (
              [id] => 9
              [enablecompletion] => 1
          )
          
          Show
          Eloy Lafuente (stronk7) added a comment - Passing test: I've executed this in one forum/view.php hacked file: $co = new stdclass(); $co->id = $course->id; $completion = new completion_info($co); print_object($co); $completion->is_enabled(); print_object($co); And lazy load worked as expected, without outputting any notice at all with results: stdClass Object ( [id] => 9 [enablecompletion] => 1 )
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Upstream, upstream, this is part of upstream, upstream... thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Upstream, upstream, this is part of upstream, upstream... thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: