Permalink
Browse files

MDL-37105 prevent fatal error when category limit reached

  • Loading branch information...
1 parent 322af44 commit 697871ddcfdadf09b9962741d7964faa67f84b74 @skodak skodak committed Dec 27, 2012
Showing with 15 additions and 13 deletions.
  1. +15 −13 lib/navigationlib.php
View
@@ -1663,19 +1663,21 @@ protected function load_all_categories($categoryid = self::LOAD_ROOT_CATEGORIES,
$categoryids[] = $category->key;
}
}
- list($categoriessql, $params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
- $params['limit'] = (!empty($CFG->navcourselimit))?$CFG->navcourselimit:20;
- $sql = "SELECT cc.id, COUNT(c.id) AS coursecount
- FROM {course_categories} cc
- JOIN {course} c ON c.category = cc.id
- WHERE cc.id {$categoriessql}
- GROUP BY cc.id
- HAVING COUNT(c.id) > :limit";
- $excessivecategories = $DB->get_records_sql($sql, $params);
- foreach ($categories as &$category) {
- if (array_key_exists($category->key, $excessivecategories) && !$this->can_add_more_courses_to_category($category)) {
- $url = new moodle_url('/course/category.php', array('id'=>$category->key));
- $category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING);
+ if ($categoryids) {
+ list($categoriessql, $params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
+ $params['limit'] = (!empty($CFG->navcourselimit))?$CFG->navcourselimit:20;
+ $sql = "SELECT cc.id, COUNT(c.id) AS coursecount
+ FROM {course_categories} cc
+ JOIN {course} c ON c.category = cc.id
+ WHERE cc.id {$categoriessql}
+ GROUP BY cc.id
+ HAVING COUNT(c.id) > :limit";
+ $excessivecategories = $DB->get_records_sql($sql, $params);
+ foreach ($categories as &$category) {
+ if (array_key_exists($category->key, $excessivecategories) && !$this->can_add_more_courses_to_category($category)) {
+ $url = new moodle_url('/course/category.php', array('id'=>$category->key));
+ $category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING);
+ }
}
}
}

0 comments on commit 697871d

Please sign in to comment.