MDL-27001 'Show description' feature part 2 - Automatic support for modules that don't have a get_coursemodule_info function

If a module doesn't have module_get_coursemodule_info function, but it does have 'intro' and 'introformat' fields in its main table, then all it needs to do is return true for FEATURE_SHOW_DESCRIPTIONS and everything is handled automatically.
This commit is contained in:
sam marshall 2011-07-21 15:05:36 +01:00
parent 8c40662e22
commit b3a89232d9

View file

@ -1122,7 +1122,7 @@ function get_array_of_activities($courseid) {
include_once("$CFG->dirroot/mod/$modname/lib.php"); include_once("$CFG->dirroot/mod/$modname/lib.php");
if (function_exists($functionname)) { if ($hasfunction = function_exists($functionname)) {
if ($info = $functionname($rawmods[$seq])) { if ($info = $functionname($rawmods[$seq])) {
if (!empty($info->icon)) { if (!empty($info->icon)) {
$mod[$seq]->icon = $info->icon; $mod[$seq]->icon = $info->icon;
@ -1157,6 +1157,21 @@ function get_array_of_activities($courseid) {
} }
} }
} }
// When there is no modname_get_coursemodule_info function,
// but showdescriptions is enabled, then we use the 'intro'
// and 'introformat' fields in the module table
if (!$hasfunction && $rawmods[$seq]->showdescription) {
if ($modvalues = $DB->get_record($rawmods[$seq]->modname,
array('id' => $rawmods[$seq]->instance), 'name, intro, introformat')) {
// Set content from intro and introformat. Filters are disabled
// because we filter it with format_text at display time
$mod[$seq]->content = format_module_intro($rawmods[$seq]->modname,
$modvalues, $rawmods[$seq]->id, false);
// To save making another query just below, put name in here
$mod[$seq]->name = $modvalues->name;
}
}
if (!isset($mod[$seq]->name)) { if (!isset($mod[$seq]->name)) {
$mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance)); $mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance));
} }