Skip to content
Browse files

MDL-31122 Navigation: Do not show week in navigation if it contains o…

…nly labels
  • Loading branch information...
1 parent 1aff7bb commit c59e5f07c394b1044da3c18c63e7d10ae01ad173 @sammarshallou sammarshallou committed Jan 11, 2012
Showing with 25 additions and 4 deletions.
  1. +25 −4 lib/navigationlib.php
View
29 lib/navigationlib.php
@@ -127,6 +127,8 @@ class navigation_node implements renderable {
protected static $fullmeurl = null;
/** @var bool toogles auto matching of active node */
public static $autofindactive = true;
+ /** @var mixed If set to an int, that section will be included even if it has no activities */
+ public $includesectionnum = false;
/**
* Constructs a new navigation_node
@@ -1176,13 +1178,29 @@ public function initialise() {
}
$this->add_course_essentials($coursenode, $course);
+
+ // Get section number from $cm (if provided) - we need this
+ // before loading sections in order to tell it to load this section
+ // even if it would not normally display (=> it contains only
+ // a label, which we are now editing)
+ $sectionnum = isset($cm->sectionnum) ? $cm->sectionnum : 0;
+ if ($sectionnum) {
+ // This value has to be stored in a member variable because
+ // otherwise we would have to pass it through a public API
+ // to course formats and they would need to change their
+ // functions to pass it along again...
+ $this->includesectionnum = $sectionnum;
+ } else {
+ $this->includesectionnum = false;
+ }
+
// Load the course sections into the page
$sections = $this->load_course_sections($course, $coursenode);
if ($course->id != SITEID) {
// Find the section for the $CM associated with the page and collect
// its section number.
- if (isset($cm->sectionnum)) {
- $cm->sectionnumber = $cm->sectionnum;
+ if ($sectionnum) {
+ $cm->sectionnumber = $sectionnum;
} else {
foreach ($sections as $section) {
if ($section->id == $cm->section) {
@@ -1639,7 +1657,9 @@ protected function generate_sections_and_activities(stdClass $course) {
}
}
$activities[$cmid] = $activity;
- $sections[$key]->hasactivites = true;
+ if ($activity->display) {
+ $sections[$key]->hasactivites = true;
+ }
}
}
$this->cache->set('course_sections_'.$course->id, $sections);
@@ -1676,7 +1696,8 @@ public function load_generic_course_sections(stdClass $course, navigation_node $
if ($course->id == SITEID) {
$this->load_section_activities($coursenode, $section->section, $activities);
} else {
- if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections && !$section->hasactivites)) {
+ if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections &&
+ !$section->hasactivites && $this->includesectionnum !== $section->section)) {
continue;
}
if ($namingfunctionexists) {

0 comments on commit c59e5f0

Please sign in to comment.
Something went wrong with that request. Please try again.