- course category depth can be estimated in make_categories_options() by the number of separators
function make_categories_options() {
global $CFG;
require_once($CFG->libdir. '/coursecatlib.php');
- $cats = coursecat::make_categories_list();
+ $cats = coursecat::make_categories_list('', 0, ' / ');
foreach ($cats as $key => $value) {
- $cats[$key] = str_repeat(' ', coursecat::get($key)->depth - 1). $value;
+ // Prefix the value with the number of spaces equal to category depth (number of separators in the value).
+ $cats[$key] = str_repeat(' ', substr_count($value, ' / ')). $value;
}
return $cats;
}