Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

A new function navmenulist which simply returns a UL list containing

all the modules in a course.

This is so theme designers can start experimenting with popup menus etc

From header.html or footer.html, you can use code like this to get the data:

<?php  if (is_object($course)) {
           $list = navmenulist($course, 50);
           echo '<div id="floatnav">'.$list.'</div>';
       }
?>
  • Loading branch information...
commit f3a74e68171346465b2759648b4af6ea47e15e34 1 parent b623ea5
moodler authored

Showing 1 changed file with 103 additions and 0 deletions. Show diff stats Hide diff stats

  1. +103 0 lib/weblib.php
103 lib/weblib.php
@@ -3200,6 +3200,109 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
3200 3200 '</td><td>'. $nextmod .'</td></tr></table>';
3201 3201 }
3202 3202
  3203 +
  3204 +/**
  3205 + * Given a course
  3206 + * This function returns a small popup menu with all the
  3207 + * course activity modules in it, as a navigation menu
  3208 + * outputs a simple list structure in XHTML
  3209 + * The data is taken from the serialised array stored in
  3210 + * the course record
  3211 + *
  3212 + * @param course $course A {@link $COURSE} object.
  3213 + * @return string
  3214 + * @todo Finish documenting this function
  3215 + */
  3216 +function navmenulist($course, $width=50) {
  3217 +
  3218 + global $CFG;
  3219 +
  3220 + if (empty($course)) {
  3221 + return '';
  3222 + }
  3223 +
  3224 + if ($course->format == 'weeks') {
  3225 + $strsection = get_string('week');
  3226 + } else {
  3227 + $strsection = get_string('topic');
  3228 + }
  3229 +
  3230 + if (!$modinfo = unserialize($course->modinfo)) {
  3231 + return '';
  3232 + }
  3233 + $isteacher = isteacher($course->id);
  3234 + $section = -1;
  3235 + $selected = '';
  3236 + $url = '';
  3237 + $previousmod = NULL;
  3238 + $backmod = NULL;
  3239 + $nextmod = NULL;
  3240 + $selectmod = NULL;
  3241 + $logslink = NULL;
  3242 + $flag = false;
  3243 + $menu = array();
  3244 +
  3245 + $sections = get_records('course_sections','course',$course->id,'section','section,visible,summary');
  3246 +
  3247 + $menu[] = '<ul>';
  3248 + foreach ($modinfo as $mod) {
  3249 + if ($mod->mod == 'label') {
  3250 + continue;
  3251 + }
  3252 +
  3253 + if ($mod->section > $course->numsections) { /// Don't show excess hidden sections
  3254 + break;
  3255 + }
  3256 +
  3257 + if ($mod->section > 0 and $section <> $mod->section) {
  3258 + $thissection = $sections[$mod->section];
  3259 +
  3260 + if ($thissection->visible or !$course->hiddensections or $isteacher) {
  3261 + $thissection->summary = strip_tags(format_string($thissection->summary,true));
  3262 + if (!empty($doneheading)) {
  3263 + $menu[] = '</ul>';
  3264 + }
  3265 + if ($course->format == 'weeks' or empty($thissection->summary)) {
  3266 + $menu[] = '<li>'. $strsection ." ". $mod->section .'</li>';
  3267 + } else {
  3268 + if (strlen($thissection->summary) < ($width-3)) {
  3269 + $menu[] = '<li>'.$thissection->summary.'</li>';
  3270 + } else {
  3271 + $menu[] = '<li>'.substr($thissection->summary, 0, $width).'...</li>';
  3272 + }
  3273 + }
  3274 + $menu[] = '<ul>';
  3275 + $doneheading = true;
  3276 + }
  3277 + }
  3278 +
  3279 + $section = $mod->section;
  3280 +
  3281 + //Only add visible or teacher mods to jumpmenu
  3282 + if ($mod->visible or $isteacher) {
  3283 + $url = $mod->mod .'/view.php?id='. $mod->cm;
  3284 + if ($flag) { // the current mod is the "next" mod
  3285 + $nextmod = $mod;
  3286 + $flag = false;
  3287 + }
  3288 + $mod->name = strip_tags(format_string(urldecode($mod->name),true));
  3289 + if (strlen($mod->name) > ($width+5)) {
  3290 + $mod->name = substr($mod->name, 0, $width).'...';
  3291 + }
  3292 + if (!$mod->visible) {
  3293 + $mod->name = '('.$mod->name.')';
  3294 + }
  3295 + $menu[] = '<li><a href="'.$CFG->wwwroot.'/mod/'.$url.'">'.$mod->name.'</a></li>';
  3296 + $previousmod = $mod;
  3297 + }
  3298 + }
  3299 + $menu[] = '</ul>';
  3300 +
  3301 + return implode("\n", $menu);
  3302 +}
  3303 +
  3304 +
  3305 +
3203 3306 /**
3204 3307 * Prints form items with the names $day, $month and $year
3205 3308 *

0 comments on commit f3a74e6

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