-
Improvement
-
Resolution: Fixed
-
Minor
-
2.8
-
MOODLE_28_STABLE
-
MOODLE_28_STABLE
-
MDL-46706-master -
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.)
- has a non-specific relationship to
-
MDL-44615 require_login simplified and improved
-
- Closed
-