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

This commit is contained in:
Marina Glancy
2013-03-25 13:21:20 +11:00
parent 6e1d1ee0e7
commit 2d8a275bab
5 changed files with 84 additions and 64 deletions
+55
View File
@@ -3616,3 +3616,58 @@ function course_category_show($category) {
coursecat::get($category->id)->show();
}
/**
* Return specified category, default if given does not exist
*
* This function is deprecated.
* To get the category with the specified it please use:
* coursecat::get($catid, IGNORE_MISSING);
* or
* coursecat::get($catid, MUST_EXIST);
*
* To get the first available category please use
* coursecat::get_default();
*
* class coursecat will also make sure that at least one category exists in DB
*
* @deprecated since 2.5
* @see coursecat::get()
* @see coursecat::get_default()
*
* @param int $catid course category id
* @return object caregory
*/
function get_course_category($catid=0) {
global $DB;
debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
$category = false;
if (!empty($catid)) {
$category = $DB->get_record('course_categories', array('id'=>$catid));
}
if (!$category) {
// the first category is considered default for now
if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
$category = reset($category);
} else {
$cat = new stdClass();
$cat->name = get_string('miscellaneous');
$cat->depth = 1;
$cat->sortorder = MAX_COURSES_IN_CATEGORY;
$cat->timemodified = time();
$catid = $DB->insert_record('course_categories', $cat);
// make sure category context exists
context_coursecat::instance($catid);
mark_context_dirty('/'.SYSCONTEXTID);
fix_course_sortorder(); // Required to build course_categories.depth and .path.
$category = $DB->get_record('course_categories', array('id'=>$catid));
}
}
return $category;
}