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

Library: API to get cm_info more easily

XMLWordPrintable

    • MOODLE_28_STABLE
    • MOODLE_28_STABLE
    • MDL-46706-master
    • Hide

      Please run unit tests, specifically:

      vendor/bin/phpunit lib/tests/modinfolib_test.php

      There is no actual code using these functions yet, they are intended for new development, so you can't test in the interface.

      Show
      Please run unit tests, specifically: vendor/bin/phpunit lib/tests/modinfolib_test.php There is no actual code using these functions yet, they are intended for new development, so you can't test in the interface.

      In Moodle, $cm objects are sometimes stdClass and sometimes cm_info. The cm_info objects are required in certain places, and have performance advantages.

      The main way to get a cm_info object is like this:

      $modinfo = get_fast_modinfo($course);
      $cm = $modinfo->get_cm($cmid);
      

      As you can see, a course is required as well as a cmid. In the common situation where you only have a cmid, it requires some SQL-query gymnastics to do this without making unnecessary queries.

      This compares to the nice simple function for getting stdclass-type $cm:

      $cm = get_coursemodule_from_id('assign', $id, 0, false, MUST_EXIST);
      

      I would like to implement two new utility functions:

      1) An efficient function that returns $cm and $course, given a $cmid (and optionally checking the module type also).

      2) A convenience function cm_info::from_mixed($cm) that returns a cm_info based on an existing $cm object that might be any type. (This will not be as efficient as ensuring that the $cm object was right first time round, but realistically, is needed in some places.)

            quen Sam Marshall
            quen Sam Marshall
            Marina Glancy Marina Glancy
            Damyon Wiese Damyon Wiese
            Frédéric Massart Frédéric Massart
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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