MDL-38147 deprecated make_categories_list(), change usage to coursecat

This commit is contained in:
Marina Glancy
2013-03-25 13:20:46 +11:00
parent b28bb7e8c7
commit 4e0b6025ad
15 changed files with 117 additions and 175 deletions
+74
View File
@@ -3425,3 +3425,77 @@ function update_category_button($categoryid = 0) {
}
return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
}
/**
* This function recursively travels the categories, building up a nice list
* for display. It also makes an array that list all the parents for each
* category.
*
* For example, if you have a tree of categories like:
* Miscellaneous (id = 1)
* Subcategory (id = 2)
* Sub-subcategory (id = 4)
* Other category (id = 3)
* Then after calling this function you will have
* $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
* 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
* 3 => 'Other category');
* $parents = array(2 => array(1), 4 => array(1, 2));
*
* If you specify $requiredcapability, then only categories where the current
* user has that capability will be added to $list, although all categories
* will still be added to $parents, and if you only have $requiredcapability
* in a child category, not the parent, then the child catgegory will still be
* included.
*
* If you specify the option $excluded, then that category, and all its children,
* are omitted from the tree. This is useful when you are doing something like
* moving categories, where you do not want to allow people to move a category
* to be the child of itself.
*
* This function is deprecated! For list of categories use
* coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
* For parents of one particular category use
* coursecat::get($id)->get_parents()
*
* @deprecated since 2.5
*
* @param array $list For output, accumulates an array categoryid => full category path name
* @param array $parents For output, accumulates an array categoryid => list of parent category ids.
* @param string/array $requiredcapability if given, only categories where the current
* user has this capability will be added to $list. Can also be an array of capabilities,
* in which case they are all required.
* @param integer $excludeid Omit this category and its children from the lists built.
* @param object $category Not used
* @param string $path Not used
*/
function make_categories_list(&$list, &$parents, $requiredcapability = '',
$excludeid = 0, $category = NULL, $path = "") {
global $CFG, $DB;
require_once($CFG->libdir.'/coursecatlib.php');
debugging('Global function make_categories_list() is deprecated. Please use '.
'coursecat::make_categories_list() and coursecat::get_parents()',
DEBUG_DEVELOPER);
// For categories list use just this one function:
if (empty($list)) {
$list = array();
}
$list += coursecat::make_categories_list($requiredcapability, $excludeid);
// Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
// Usually user needs only parents for one particular category, in which case should be used:
// coursecat::get($categoryid)->get_parents()
if (empty($parents)) {
$parents = array();
}
$all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
foreach ($all as $record) {
if ($record->parent) {
$parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
} else {
$parents[$record->id] = array();
}
}
}