Skip to content

Commit

Permalink
MDL-27001 'Show description' feature part 2 - Automatic support for m…
Browse files Browse the repository at this point in the history
…odules 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.
  • Loading branch information
sammarshallou committed Sep 6, 2011
1 parent 8c40662 commit b3a8923
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ function get_array_of_activities($courseid) {

include_once("$CFG->dirroot/mod/$modname/lib.php");

if (function_exists($functionname)) {
if ($hasfunction = function_exists($functionname)) {
if ($info = $functionname($rawmods[$seq])) {
if (!empty($info->icon)) {
$mod[$seq]->icon = $info->icon;
Expand Down Expand Up @@ -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)) {
$mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance));
}
Expand Down

0 comments on commit b3a8923

Please sign in to comment.