MDL-38147 deprecated get_course_category(), change usage to coursecat
This commit is contained in:
+26
-10
@@ -3265,6 +3265,31 @@ class course_request {
|
||||
return $this->properties->collision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category where this course request should be created
|
||||
*
|
||||
* Note that we don't check here that user has a capability to view
|
||||
* hidden categories if he has capabilities 'moodle/site:approvecourse' and
|
||||
* 'moodle/course:changecategory'
|
||||
*
|
||||
* @return coursecat
|
||||
*/
|
||||
public function get_category() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
// If the category is not set, if the current user does not have the rights to change the category, or if the
|
||||
// category does not exist, we set the default category to the course to be approved.
|
||||
// The system level is used because the capability moodle/site:approvecourse is based on a system level.
|
||||
if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) ||
|
||||
(!$category = coursecat::get($this->properties->category, IGNORE_MISSING, true))) {
|
||||
$category = coursecat::get($CFG->defaultrequestcategory, IGNORE_MISSING, true);
|
||||
}
|
||||
if (!$category) {
|
||||
$category = coursecat::get_default();
|
||||
}
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function approves the request turning it into a course
|
||||
*
|
||||
@@ -3287,18 +3312,9 @@ class course_request {
|
||||
unset($data->reason);
|
||||
unset($data->requester);
|
||||
|
||||
// If the category is not set, if the current user does not have the rights to change the category, or if the
|
||||
// category does not exist, we set the default category to the course to be approved.
|
||||
// The system level is used because the capability moodle/site:approvecourse is based on a system level.
|
||||
if (empty($data->category) || !has_capability('moodle/course:changecategory', context_system::instance()) ||
|
||||
(!$category = get_course_category($data->category))) {
|
||||
$category = get_course_category($CFG->defaultrequestcategory);
|
||||
}
|
||||
|
||||
// Set category
|
||||
$category = $this->get_category();
|
||||
$data->category = $category->id;
|
||||
$data->sortorder = $category->sortorder; // place as the first in category
|
||||
|
||||
// Set misc settings
|
||||
$data->requested = 1;
|
||||
|
||||
|
||||
+2
-11
@@ -110,23 +110,14 @@ if (empty($pending)) {
|
||||
// Check here for shortname collisions and warn about them.
|
||||
$course->check_shortname_collision();
|
||||
|
||||
// Retreiving category name.
|
||||
// If the category was not set (can happen after upgrade) or if the user does not have the capability
|
||||
// to change the category, we fallback on the default one.
|
||||
// Else, the category proposed is fetched, but we fallback on the default one if we can't find it.
|
||||
// It is just a matter of displaying the right information because the logic when approving the category
|
||||
// proceeds the same way. The system context level is used as moodle/site:approvecourse uses it.
|
||||
if (empty($course->category) || !has_capability('moodle/course:changecategory', context_system::instance()) ||
|
||||
(!$category = get_course_category($course->category))) {
|
||||
$category = get_course_category($CFG->defaultrequestcategory);
|
||||
}
|
||||
$category = $course->get_category();
|
||||
|
||||
$row = array();
|
||||
$row[] = format_string($course->shortname);
|
||||
$row[] = format_string($course->fullname);
|
||||
$row[] = fullname($course->get_requester());
|
||||
$row[] = $course->summary;
|
||||
$row[] = format_string($category->name);
|
||||
$row[] = $category->get_formatted_name();
|
||||
$row[] = format_string($course->reason);
|
||||
$row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
|
||||
$OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');
|
||||
|
||||
@@ -1026,48 +1026,6 @@ function get_all_subcategories($catid) {
|
||||
return $subcats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return specified category, default if given does not exist
|
||||
*
|
||||
* @global object
|
||||
* @uses MAX_COURSES_IN_CATEGORY
|
||||
* @uses CONTEXT_COURSECAT
|
||||
* @uses SYSCONTEXTID
|
||||
* @param int $catid course category id
|
||||
* @return object caregory
|
||||
*/
|
||||
function get_course_category($catid=0) {
|
||||
global $DB;
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes course category and course sortorder, also verifies category and course parents and paths.
|
||||
* (circular references are not fixed)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ information provided here is intended especially for developers.
|
||||
* Functions responsible for managing and accessing course categories are moved to class coursecat
|
||||
in lib/coursecatlib.php. The following global functions are deprecated: make_categories_list(),
|
||||
category_delete_move(), category_delete_full(), move_category(), course_category_hide(),
|
||||
course_category_show()
|
||||
course_category_show(), get_course_category()
|
||||
|
||||
YUI changes:
|
||||
* M.util.help_icon has been deprecated. Code should be updated to use moodle-core-popuphelp
|
||||
|
||||
Reference in New Issue
Block a user