/** * Recursively builds a dynamic tree menu for seleting the categories to filter * search results by. * * @param array $cats An array of category objects from the DB. * @param array $selected An array of currently selected category IDs. * @param string $baseurl The base URL that this menu is being displayed on. * @return array An array of completed HTML_TreeMenu nodes. */ function elis_files_make_category_select_tree_browse($cats, $selected = array(), $baseurl = '') { global $CFG; global $repo; static $catlist; if (empty($cats)) { return; } $icon = 'folder.gif'; $eicon = 'folder-expanded.gif'; $nodes = array(); /// Get the list of all the categories we actually need to display here if (!isset($catlist)) { $catlist = elis_files_make_category_tree(); } $catfilter = elis_files_get_category_filter(); for ($i = 0; $i < count($cats); $i++) { if (!empty($catlist) && !array_key_exists($cats[$i]->id, $catlist)) { continue; } if (empty($catfiler) || in_array($cats[$i]->id, $catfilter)) { if (in_array($cats[$i]->id, $selected)) { $checked = ' checked'; } else { $checked = ''; } $text = '<input type="checkbox" name="categories[]" value="' . $cats[$i]->id . '"' . $checked . ' /> '; } if (!empty($baseurl)) { $text .= '<a href="' . $baseurl . '&search=*&category=' . $cats[$i]->id . '">' . $cats[$i]->title . '</a>'; } else { $text .= $cats[$i]->title; } $node = new HTML_TreeNode(array( 'text' => $text, 'icon' => $icon, 'expandedIcon' => $eicon, 'expanded' => false )); if ($children = $repo->category_get_children($cats[$i]->id)) { if ($cnodes = elis_files_make_category_select_tree_browse($children, $selected, $baseurl)) { for ($j = 0; $j < count($cnodes); $j++) { $node->addItem($cnodes[$j]); } } } $nodes[] = $node; } return $nodes; }
if (isset($data->reset)) { $DB->delete_records('repository_elisfiles_cats'); // Perform the back-end category refresh $categories = elis_files_get_categories(); $uuids = array(); $repo->process_categories($uuids, $categories); } else if (isset($data->categories)) { set_config('catfilter', serialize($data->categories), 'elisfiles'); } else { set_config('catfilter', '', 'elisfiles'); } } /// Get (or create) the array of category IDs that are already selected in the filter. $catfilter = elis_files_get_category_filter(); // Set up header etc... $url = new moodle_url('/repository/elisfiles/config-categories.php'); $PAGE->set_url($url); $PAGE->requires->js('/repository/elisfiles/lib/HTML_TreeMenu-1.2.0/TreeMenu.js', true); $PAGE->set_title($strconfigcatfilter); $PAGE->set_heading($SITE->fullname); echo $OUTPUT->header(); echo $OUTPUT->box_start(); echo '<form method="post" action="' . $CFG->wwwroot . '/repository/elisfiles/config-categories.php">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo '<center>';