Use defaultrequestcategory for new course from print_courses() if no other category is available

print_courses() produced PHP notice (Trying to get property of
non-object) and generated an invalid button to create a new course in this
case: (1) Passed paramater $category is 0 to display all categores (as in
case of home page, for example) and (2) get_child_categories(0) returns
more than one record. In such case, $categories is still a plain
integer, does not contain ->id property and the called /course/edit.php
exits with error.
This patch uses $CFG->defaultrequestcategory as category id in this
case.
This commit is contained in:
David Mudrak
2010-05-14 14:06:39 +00:00
parent 2ad5d2efaa
commit 4868e95f58
+5 -1
View File
@@ -2137,7 +2137,11 @@ function print_courses($category) {
$context = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('moodle/course:create', $context)) {
$options = array();
$options['category'] = $category->id;
if (!empty($category->id)) {
$options['category'] = $category->id;
} else {
$options['category'] = $CFG->defaultrequestcategory;
}
echo '<div class="addcoursebutton">';
echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
echo '</div>';