|
From da6261b0fe00a33c2c672c239df7d875f82e3457 Mon Sep 17 00:00:00 2001 |
|
From: Mark Johnson <[email protected]> |
|
Date: Fri, 19 Aug 2011 10:32:23 +0100 |
|
Subject: [PATCH 38/78] Modified Navigationlib to support categories in My |
|
Courses |
|
|
|
My Courses in the Nav block doesn't support categories by default. |
|
This hack implements a new setting, $CFG->mycoursescollapsecategories, |
|
where an array of category IDs can be spefied. Any courses appearing in |
|
My Courses that are under these categories will be collapsed underneath them. |
|
If there are several categories in the array with the same name, courses |
|
will be grouped under a single heading. |
|
--- |
|
lib/navigationlib.php | 27 ++++++++++++++++++++++++++- |
|
1 file changed, 26 insertions(+), 1 deletion(-) |
|
|
|
diff --git a/lib/navigationlib.php b/lib/navigationlib.php |
|
index 7aea49a..fa40685 100644 |
|
--- a/lib/navigationlib.php |
|
+++ b/lib/navigationlib.php |
|
@@ -2210,7 +2210,32 @@ class global_navigation extends navigation_node { |
|
$shortname = get_string('sitepages'); |
|
} |
|
} else if ($ismycourse) { |
|
- $parent = $this->rootnodes['mycourses']; |
|
+ |
|
+ // LOCAL: Collapse courses under specificed categories |
|
+ if (isset($CFG->mycoursescollapsecategories && is_array($CFG->mycoursescollapsecategories)) { |
|
+ global $DB; |
|
+ $collapsecategories = array(); |
|
+ foreach($CFG->mycoursescollapsecategories as $catid) { |
|
+ $collapsecategories[$catid] = $DB->get_record('course_categories', array('id' => $catid)); |
|
+ $collapsecategories[$catid]->context = get_context_instance(CONTEXT_COURSECAT, $catid); |
|
+ } |
|
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); |
|
+ $contextpath = explode('/', $coursecontext->path); |
|
+ foreach ($collapsecategories as $collapsecategory) { |
|
+ if (in_array($collapsecategory->context->id, $contextpath)) { |
|
+ if (!$categorynode = $this->rootnodes['mycourses']->get('cat'.$collapsecategory->name)) { |
|
+ $categorynode = $this->rootnodes['mycourses']->add($collapsecategory->name, null, self::TYPE_CONTAINER, null, 'cat'.$collapsecategory->name); |
|
+ } |
|
+ } |
|
+ } |
|
+ } |
|
+ if (isset($categorynode)) { |
|
+ $parent = $categorynode; |
|
+ } else { |
|
+ $parent = $this->rootnodes['mycourses']; |
|
+ } |
|
+ |
|
+// $parent = $this->rootnodes['mycourses']; |
|
$url = new moodle_url('/course/view.php', array('id'=>$course->id)); |
|
} else { |
|
$parent = $this->rootnodes['courses']; |
|
-- |
|
1.7.10 |
|
|