Skip to content

Commit

Permalink
Merge branch 'w51_MDL-37105_m24_catlimit' of git://github.com/skodak/…
Browse files Browse the repository at this point in the history
…moodle into MOODLE_24_STABLE
  • Loading branch information
Sam Hemelryk committed Jan 6, 2013
2 parents 3735e3d + 697871d commit 1a5a5f8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/navigationlib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1663,19 +1663,21 @@ protected function load_all_categories($categoryid = self::LOAD_ROOT_CATEGORIES,
$categoryids[] = $category->key; $categoryids[] = $category->key;
} }
} }
list($categoriessql, $params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED); if ($categoryids) {
$params['limit'] = (!empty($CFG->navcourselimit))?$CFG->navcourselimit:20; list($categoriessql, $params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
$sql = "SELECT cc.id, COUNT(c.id) AS coursecount $params['limit'] = (!empty($CFG->navcourselimit))?$CFG->navcourselimit:20;
FROM {course_categories} cc $sql = "SELECT cc.id, COUNT(c.id) AS coursecount
JOIN {course} c ON c.category = cc.id FROM {course_categories} cc
WHERE cc.id {$categoriessql} JOIN {course} c ON c.category = cc.id
GROUP BY cc.id WHERE cc.id {$categoriessql}
HAVING COUNT(c.id) > :limit"; GROUP BY cc.id
$excessivecategories = $DB->get_records_sql($sql, $params); HAVING COUNT(c.id) > :limit";
foreach ($categories as &$category) { $excessivecategories = $DB->get_records_sql($sql, $params);
if (array_key_exists($category->key, $excessivecategories) && !$this->can_add_more_courses_to_category($category)) { foreach ($categories as &$category) {
$url = new moodle_url('/course/category.php', array('id'=>$category->key)); if (array_key_exists($category->key, $excessivecategories) && !$this->can_add_more_courses_to_category($category)) {
$category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING); $url = new moodle_url('/course/category.php', array('id'=>$category->key));
$category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING);
}
} }
} }
} }
Expand Down

0 comments on commit 1a5a5f8

Please sign in to comment.