MDL-30583 navigation: Added setting to control display of front page activities on...
authorSam Hemelryk <sam@moodle.com>
Tue, 6 Dec 2011 00:04:12 +0000 (13:04 +1300)
committerSam Hemelryk <sam@moodle.com>
Sun, 8 Jan 2012 20:49:34 +0000 (09:49 +1300)
admin/settings/appearance.php
lang/en/admin.php
lib/navigationlib.php

index 7bc3b58..9c86f4f 100644 (file)
@@ -102,6 +102,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     $temp->add(new admin_setting_configcheckbox('navlinkcoursesections', new lang_string('navlinkcoursesections', 'admin'), new lang_string('navlinkcoursesections_help', 'admin'), 0));
     $temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', new lang_string('usesitenameforsitepages', 'admin'), new lang_string('configusesitenameforsitepages', 'admin'), 0));
     $temp->add(new admin_setting_configcheckbox('linkadmincategories', new lang_string('linkadmincategories', 'admin'), new lang_string('linkadmincategories_help', 'admin'), 0));
+    $temp->add(new admin_setting_configcheckbox('navshowfrontpagemods', new lang_string('navshowfrontpagemods', 'admin'), new lang_string('navshowfrontpagemods_help', 'admin'), 1));
     $temp->add(new admin_setting_configcheckbox('navadduserpostslinks', new lang_string('navadduserpostslinks', 'admin'), new lang_string('navadduserpostslinks_help', 'admin'), 1));
 
     $ADMIN->add('appearance', $temp);
index 331888e..4767a8e 100644 (file)
@@ -693,6 +693,8 @@ $string['navigationupgrade'] = 'This upgrade introduces two new navigation block
 $string['navcourselimit'] = 'Course limit';
 $string['navlinkcoursesections'] = 'Link course sections';
 $string['navlinkcoursesections_help'] = 'If enabled course sections will be shown as links within the navigation.';
+$string['navshowfrontpagemods'] = 'Show front page activities in the navigation';
+$string['navshowfrontpagemods_help'] = 'If enabled front page activities will be shown on the navigation under site pages.';
 $string['navshowallcourses'] = 'Show all courses';
 $string['navshowcategories'] = 'Show course categories';
 $string['neverdeleteruns'] = 'Never delete runs';
index f75299b..22a7f68 100644 (file)
@@ -1608,6 +1608,7 @@ class global_navigation extends navigation_node {
                         continue;
                     }
                     $activity = new stdClass;
+                    $activity->course = $course->id;
                     $activity->section = $section->section;
                     $activity->name = $cm->name;
                     $activity->icon = $cm->icon;
@@ -1714,7 +1715,8 @@ class global_navigation extends navigation_node {
      * @param course_modinfo $modinfo Object returned from {@see get_fast_modinfo()}
      * @return array Array of activity nodes
      */
-    protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, $activities) {
+    protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, $activities, $course = null) {
+        global $CFG;
         // A static counter for JS function naming
         static $legacyonclickcounter = 0;
 
@@ -1724,6 +1726,18 @@ class global_navigation extends navigation_node {
         }
 
         $activitynodes = array();
+        if (empty($activities)) {
+            return $activitynodes;
+        }
+
+        if (!is_object($course)) {
+            $activity = reset($activities);
+            $courseid = $activity->course;
+        } else {
+            $courseid = $course->id;
+        }
+        $showactivities = ($courseid != SITEID || !empty($CFG->navshowfrontpagemods));
+
         foreach ($activities as $activity) {
             if ($activity->section != $sectionnumber) {
                 continue;
@@ -1763,7 +1777,7 @@ class global_navigation extends navigation_node {
             $activitynode = $sectionnode->add($activityname, $action, navigation_node::TYPE_ACTIVITY, null, $activity->id, $icon);
             $activitynode->title(get_string('modulename', $activity->modname));
             $activitynode->hidden = $activity->hidden;
-            $activitynode->display = $activity->display;
+            $activitynode->display = $showactivities && $activity->display;
             $activitynode->nodetype = $activity->nodetype;
             $activitynodes[$activity->id] = $activitynode;
         }