From 4fd2a16e35b1482fa178fe8a05f74a06c63f97f9 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 26 Nov 2013 13:54:19 +1100 Subject: [PATCH] MDL-40191 navigation: do not throw an error if activity is not visible navigationlib is not the place to check it, let the page itself decide what to do in this case --- lib/navigationlib.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index d1c873f998b..7e6180824c6 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1850,9 +1850,6 @@ class global_navigation extends navigation_node { } foreach ($modinfo->sections[$section->section] as $cmid) { $cm = $modinfo->cms[$cmid]; - if (!$cm->uservisible) { - continue; - } $activity = new stdClass; $activity->id = $cm->id; $activity->course = $course->id; @@ -1870,7 +1867,7 @@ class global_navigation extends navigation_node { $activity->display = false; } else { $activity->url = $cm->get_url()->out(); - $activity->display = true; + $activity->display = $cm->uservisible ? true : false; if (self::module_extends_navigation($cm->modname)) { $activity->nodetype = navigation_node::NODETYPE_BRANCH; } @@ -2009,9 +2006,6 @@ class global_navigation extends navigation_node { return null; } $cm = $modinfo->cms[$this->page->cm->id]; - if (!$cm->uservisible) { - return null; - } if ($cm->icon) { $icon = new pix_icon($cm->icon, get_string('modulename', $cm->modname), $cm->iconcomponent); } else { @@ -2021,7 +2015,11 @@ class global_navigation extends navigation_node { $activitynode = $coursenode->add(format_string($cm->name), $url, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon); $activitynode->title(get_string('modulename', $cm->modname)); $activitynode->hidden = (!$cm->visible); - if (!$url) { + if (!$cm->uservisible) { + // Do not show any error here, let the page handle exception that activity is not visible for the current user. + // Also there may be no exception at all in case when teacher is logged in as student. + $activitynode->display = false; + } else if (!$url) { // Don't show activities that don't have links! $activitynode->display = false; } else if (self::module_extends_navigation($cm->modname)) { -- 2.11.4.GIT