You are here

function course_book_items_recurse in Course 6

Same name and namespace in other branches
  1. 8.3 modules/course_book/course_book.module \course_book_items_recurse()
  2. 8.2 modules/course_book/course_book.module \course_book_items_recurse()
  3. 7.2 modules/course_book/course_book.module \course_book_items_recurse()
  4. 7 modules/course_book/course_book.module \course_book_items_recurse()
  5. 3.x modules/course_book/course_book.module \course_book_items_recurse()

A recursive helper function for course_book_items().

1 call to course_book_items_recurse()
course_book_items in modules/course_book/course_book.module
Gets a nested list of book items.

File

modules/course_book/course_book.module, line 201

Code

function course_book_items_recurse($tree, $links, $exclude, $depth_limit) {
  $items = array();
  foreach ($tree as $data) {
    if ($data['link']['depth'] > $depth_limit) {

      // Don't iterate through any links on this level.
      break;
    }
    if (!in_array($data['link']['mlid'], $exclude)) {
      $link = array();

      // Build the current nested item - either a link or text.
      $text = truncate_utf8($data['link']['title'], 30, TRUE, TRUE);
      if ($links) {
        $path = $data['link']['href'];
        $link['data'] = l($text, $path);
      }
      else {
        $link['data'] = $text;
      }

      // Get children, if any.
      if ($data['below']) {
        $link['children'] = course_book_items_recurse($data['below'], $links, $exclude, $depth_limit);
      }
      $items[] = $link;
    }
  }
  return array_values($items);
}