Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30775 get_course_contents: remove warnings when the section is empty

  • Loading branch information...
commit 46295524d71cd754032d8d450d49ac6bf0087c3e 1 parent 5e00b9a
@mouneyrac mouneyrac authored
Showing with 46 additions and 43 deletions.
  1. +46 −43 course/externallib.php
View
89 course/externallib.php
@@ -108,6 +108,7 @@ public static function get_course_contents($courseid, $options = array()) {
$sections = get_all_sections($course->id);
//for each sections (first displayed to last displayed)
+ $modinfosections = $modinfo->get_sections();
foreach ($sections as $key => $section) {
$showsection = (has_capability('moodle/course:viewhiddensections', $context) or $section->visible or !$course->hiddensections);
@@ -126,62 +127,64 @@ public static function get_course_contents($courseid, $options = array()) {
$sectioncontents = array();
//for each module of the section
- foreach ($modinfo->sections[$section->section] as $cmid) { //matching /course/lib.php:print_section() logic
- $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;
- }
+ // stop here if the module is not visible to the user
+ if (!$cm->uservisible) {
+ continue;
+ }
- $module = array();
+ $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;
+ //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 = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
- if (!empty($cm->showdescription)) {
- $module['description'] = $cm->get_content();
- }
+ 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();
- }
+ //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',
- get_context_instance(CONTEXT_MODULE, $cm->id));
- //user that can view hidden module should know about the visibility
- $module['visible'] = $cm->visible;
+ $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;
- }
+ //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';
+ $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;
+ //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;
Please sign in to comment.
Something went wrong with that request. Please try again.