From 9f3cc17d8ff2efea9f5a40029127c8452246405b Mon Sep 17 00:00:00 2001 From: Jerome Mouneyrac Date: Fri, 26 Apr 2013 15:56:28 +0800 Subject: [PATCH] MDL-30775 get_course_contents: remove warnings when the section is empty --- course/externallib.php | 109 +++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/course/externallib.php b/course/externallib.php index 72d62dca7e3..aa031159bb3 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -108,6 +108,7 @@ class core_course_external extends external_api { $sections = $modinfo->get_section_info_all(); //for each sections (first displayed to last displayed) + $modinfosections = $modinfo->get_sections(); foreach ($sections as $key => $section) { if (!$section->uservisible) { @@ -125,62 +126,64 @@ class core_course_external extends external_api { $sectioncontents = array(); //for each module of the section - foreach ($modinfo->sections[$section->section] as $cmid) { - $cm = $modinfo->cms[$cmid]; + if (!empty($modinfosections[$section->section])) { + foreach ($modinfosections[$section->section] as $cmid) { + $cm = $modinfo->cms[$cmid]; - // stop here if the module is not visible to the user - if (!$cm->uservisible) { - continue; - } - - $module = array(); - - //common info (for people being able to see the module or availability dates) - $module['id'] = $cm->id; - $module['name'] = format_string($cm->name, true); - $module['modname'] = $cm->modname; - $module['modplural'] = $cm->modplural; - $module['modicon'] = $cm->get_icon_url()->out(false); - $module['indent'] = $cm->indent; - - $modcontext = context_module::instance($cm->id); - - if (!empty($cm->showdescription)) { - $module['description'] = $cm->get_content(); - } - - //url of the module - $url = $cm->get_url(); - if ($url) { //labels don't have url - $module['url'] = $cm->get_url()->out(); - } - - $canviewhidden = has_capability('moodle/course:viewhiddenactivities', - context_module::instance($cm->id)); - //user that can view hidden module should know about the visibility - $module['visible'] = $cm->visible; - - //availability date (also send to user who can see hidden module when the showavailabilyt is ON) - if ($canupdatecourse or ($CFG->enableavailability && $canviewhidden && $cm->showavailability)) { - $module['availablefrom'] = $cm->availablefrom; - $module['availableuntil'] = $cm->availableuntil; - } - - $baseurl = 'webservice/pluginfile.php'; - - //call $modulename_export_contents - //(each module callback take care about checking the capabilities) - require_once($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'); - $getcontentfunction = $cm->modname.'_export_contents'; - if (function_exists($getcontentfunction)) { - if ($contents = $getcontentfunction($cm, $baseurl)) { - $module['contents'] = $contents; + // stop here if the module is not visible to the user + if (!$cm->uservisible) { + continue; } + + $module = array(); + + //common info (for people being able to see the module or availability dates) + $module['id'] = $cm->id; + $module['name'] = format_string($cm->name, true); + $module['modname'] = $cm->modname; + $module['modplural'] = $cm->modplural; + $module['modicon'] = $cm->get_icon_url()->out(false); + $module['indent'] = $cm->indent; + + $modcontext = context_module::instance($cm->id); + + if (!empty($cm->showdescription)) { + $module['description'] = $cm->get_content(); + } + + //url of the module + $url = $cm->get_url(); + if ($url) { //labels don't have url + $module['url'] = $cm->get_url()->out(false); + } + + $canviewhidden = has_capability('moodle/course:viewhiddenactivities', + context_module::instance($cm->id)); + //user that can view hidden module should know about the visibility + $module['visible'] = $cm->visible; + + //availability date (also send to user who can see hidden module when the showavailabilyt is ON) + if ($canupdatecourse or ($CFG->enableavailability && $canviewhidden && $cm->showavailability)) { + $module['availablefrom'] = $cm->availablefrom; + $module['availableuntil'] = $cm->availableuntil; + } + + $baseurl = 'webservice/pluginfile.php'; + + //call $modulename_export_contents + //(each module callback take care about checking the capabilities) + require_once($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'); + $getcontentfunction = $cm->modname.'_export_contents'; + if (function_exists($getcontentfunction)) { + if ($contents = $getcontentfunction($cm, $baseurl)) { + $module['contents'] = $contents; + } + } + + //assign result to $sectioncontents + $sectioncontents[] = $module; + } - - //assign result to $sectioncontents - $sectioncontents[] = $module; - } $sectionvalues['modules'] = $sectioncontents;