From 2a62743c40896099d346bddf84f888dba37fd13c Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 13 Oct 2010 18:51:37 +0000 Subject: [PATCH] MDL-24316 "reenabling" access to stealth activities --- lib/navigationlib.php | 59 ++++++++++++++++++++++++++++++++++++------- pluginfile.php | 3 +-- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 72ec693f92969..128f6dbf864e7 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1034,17 +1034,29 @@ public function initialise() { } // Load all of the section activities for the section the cm belongs to. - $activities = $this->load_section_activities($sections[$cm->sectionnumber]->sectionnode, $cm->sectionnumber, get_fast_modinfo($course)); + if (isset($cm->sectionnumber) and !empty($sections[$cm->sectionnumber])) { + $activities = $this->load_section_activities($sections[$cm->sectionnumber]->sectionnode, $cm->sectionnumber, get_fast_modinfo($course)); + } else { + $activities = array(); + if ($activity = $this->load_stealth_activity($coursenode, get_fast_modinfo($course))) { + // "stealth" activity from unavailable section + $activities[$cm->id] = $activity; + } + } } else { $activities = array(); $activities[$cm->id] = $coursenode->get($cm->id, navigation_node::TYPE_ACTIVITY); } - // Finally load the cm specific navigaton information - $this->load_activity($cm, $course, $activities[$cm->id]); - // Check if we have an active ndoe - if (!$activities[$cm->id]->contains_active_node() && !$activities[$cm->id]->search_for_active_node()) { - // And make the activity node active. - $activities[$cm->id]->make_active(); + if (!empty($activities[$cm->id])) { + // Finally load the cm specific navigaton information + $this->load_activity($cm, $course, $activities[$cm->id]); + // Check if we have an active ndoe + if (!$activities[$cm->id]->contains_active_node() && !$activities[$cm->id]->search_for_active_node()) { + // And make the activity node active. + $activities[$cm->id]->make_active(); + } + } else { + //TODO: something is wrong, what to do? (Skodak) } break; case CONTEXT_USER : @@ -1424,12 +1436,11 @@ protected function load_section_activities(navigation_node $sectionnode, $sectio return true; } - $viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $this->page->context); $activities = array(); foreach ($modinfo->sections[$sectionnumber] as $cmid) { $cm = $modinfo->cms[$cmid]; - if (!$viewhiddenactivities && !$cm->visible) { + if (!$cm->uservisible) { continue; } if ($cm->icon) { @@ -1451,6 +1462,36 @@ protected function load_section_activities(navigation_node $sectionnode, $sectio return $activities; } + /** + * Loads a stealth module from unavailable section + * @param navigation_node $coursenode + * @param stdClass $modinfo + * @return navigation_node or null if not accessible + */ + protected function load_stealth_activity(navigation_node $coursenode, $modinfo) { + if (empty($modinfo->cms[$this->page->cm->id])) { + 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 { + $icon = new pix_icon('icon', get_string('modulename', $cm->modname), $cm->modname); + } + $url = new moodle_url('/mod/'.$cm->modname.'/view.php', array('id'=>$cm->id)); + $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 ($cm->modname == 'label') { + $activitynode->display = false; + } else if ($this->module_extends_navigation($cm->modname)) { + $activitynode->nodetype = navigation_node::NODETYPE_BRANCH; + } + return $activitynode; + } /** * Loads the navigation structure for the given activity into the activities node. * diff --git a/pluginfile.php b/pluginfile.php index b7d917c8f07af..9cb971ba95c59 100644 --- a/pluginfile.php +++ b/pluginfile.php @@ -500,8 +500,7 @@ if ($course->numsections < $section->section) { if (!has_capability('moodle/course:update', $context)) { - // disable access to invisible sections if can not edit course - // this is going to break some ugly hacks, but is necessary + // block access to unavailable sections if can not edit course send_file_not_found(); } }