/** * Recursive function to print out all the categories in a nice format * with or without courses included * * @param null $category current category * @param null $displaylist display list * @param null $parentslist list of parent categories * @param $depth depth of the category for indentation purposes * @param bool $showcourses determines if we display courses and course information * @param string $branch current output that is stored until visibilty is true. Otherwise this branch output gets destroyed * @param bool $visible maintains the visibility state of the navigation branch * @param $output variable used to output html during recursion * @return mixed */ function print_whole_category_manager_list($category = null, $displaylist = null, $parentslist = null, $depth = -1, $showcourses = true, $branch = '', $visible = false, &$output) { global $CFG; // Note: maxcategorydepth == 0 meant no limit. if (!empty($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth) { return; } if (!$displaylist) { make_categories_manager_list($displaylist, $parentslist); } if ($category) { if (!has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id)) && $visible) { $visible = false; $branch = print_category_manager_info($category, $depth, $showcourses, $visible); } else { if ($visible) { $branch .= print_category_manager_info($category, $depth, $showcourses, $visible); $output .= $branch; $branch = ''; } else { $branch .= print_category_manager_info($category, $depth, $showcourses, $visible); } } } else { $category = new stdClass(); $category->id = "0"; } if ($categories = get_child_manager_categories($category->id)) { // Print all the children recursively. $countcats = count($categories); $count = 0; $first = true; $last = false; foreach ($categories as $cat) { if (has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($cat->id)) && !$visible) { $visible = true; } $count++; if ($count == $countcats) { $last = true; } $up = $first ? false : true; $down = $last ? false : true; $first = false; print_whole_category_manager_list($cat, $displaylist, $parentslist, $depth + 1, $showcourses, $branch, $visible, $output); } } else { $visible = false; $depth = 0; $branch = ''; } }
} if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) { print_error('invalidcontext'); } // Set the context & setup the page. $PAGE->set_url("/local/contextadmin/index.php", array("contextid" => $contextid)); $PAGE->set_context($context); $PAGE->set_pagelayout('standard'); $site = get_site(); $PAGE->set_title("{$site->shortname}"); $PAGE->set_heading($site->fullname); $PAGE->set_pagelayout('coursecategory'); $renderer = $PAGE->get_renderer('local_contextadmin'); $actions = array(); // Need to load list of categories that this user has access to. if ($context->contextlevel == CONTEXT_SYSTEM) { include_once $CFG->dirroot . '/local/contextadmin/locallib.php'; include_once $CFG->dirroot . '/course/lib.php'; $test = ''; print_whole_category_manager_list(null, null, null, 0, false, '', false, $test); $actions[0] = $test; echo $renderer->index_page('System Context', $actions); } else { if ($context->contextlevel = CONTEXT_COURSECAT) { // Load category level settings/links. // Need to check for permission here. // - 'moodle/site:config'. // - 'mod/contextadmin:manage', $context, where context is a valid category context for that user. echo $renderer->index_page('Category Context', $actions); } }