From c09f474dd090410f72bb029f80cf852898cf41f7 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 7 Feb 2007 10:14:22 +0000 Subject: [PATCH] MDL-8450 Added support for including question categories in a quiz export. --- lib/questionlib.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/questionlib.php b/lib/questionlib.php index 6d9fec8b8e..2713996c7f 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -10,7 +10,11 @@ * TODO: separate those functions which form part of the API * from the helper functions. * +<<<<<<< questionlib.php * @version $Id$ +======= + * @version $Id$ +>>>>>>> 1.72.2.6 * @author Martin Dougiamas and many others. This has recently been completely * rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of * the Serving Mathematics project @@ -1681,6 +1685,30 @@ function create_category_path( $catpath, $delimiter='/', $courseid=0 ) { return $category; } +/** + * get the category as a path (e.g., tom/dick/harry) + * @param int id the id of the most nested catgory + * @param string delimiter the delimiter you want + * @return string the path + */ +function get_category_path( $id, $delimiter='/' ) { + $path = ''; + do { + if (!$category = get_record( 'question_categories','id',$id )) { + print_error( "Error reading category record - $id" ); + } + $name = $category->name; + $id = $category->parent; + if (!empty($path)) { + $path = "{$name}{$delimiter}{$path}"; + } + else { + $path = $name; + } + } while ($id != 0); + + return $path; +} //=========================== // Import/Export Functions -- 2.39.5