function qformat_default::get_category_path in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format.php \qformat_default::get_category_path()
get the category as a path (e.g., tom/dick/harry)
Parameters
int id the id of the most nested catgory:
string delimiter the delimiter you want:
Return value
string the path
1 call to qformat_default::get_category_path()
- qformat_default::exportprocess in includes/
moodle/ question/ format.php - Do the export For most types this should not need to be overrided
File
- includes/
moodle/ question/ format.php, line 747
Class
- qformat_default
- Base class for question import and export formats.
Code
function get_category_path($id, $delimiter = '/', $includecontext = true) {
$path = '';
if (!($firstcategory = get_record('question_categories', 'id', $id))) {
error("Error getting category record from db - " . $id);
}
$category = $firstcategory;
$contextstring = $this->translator
->context_to_string($category->contextid);
do {
$name = $category->name;
$id = $category->parent;
if (!empty($path)) {
$path = "{$name}{$delimiter}{$path}";
}
else {
$path = $name;
}
} while ($category = get_record('question_categories', 'id', $id));
if ($includecontext) {
$path = '$' . $contextstring . '$' . "{$delimiter}{$path}";
}
return $path;
}