Permalink
Browse files

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

  • Loading branch information...
1 parent 6e1d1ee commit 2d8a275baba858ae2ae350aa8b5553a09fb528cf @marinaglancy marinaglancy committed Feb 21, 2013
Showing with 84 additions and 64 deletions.
  1. +26 −10 course/lib.php
  2. +2 −11 course/pending.php
  3. +0 −42 lib/datalib.php
  4. +55 −0 lib/deprecatedlib.php
  5. +1 −1 lib/upgrade.txt
View
@@ -3266,6 +3266,31 @@ public function check_shortname_collision($shortnamemark = '[*]') {
}
/**
+ * 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
*
* This function converts the course request into a course, at the same time
@@ -3287,18 +3312,9 @@ public function approve() {
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;
View
@@ -110,23 +110,14 @@
// 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');
View
@@ -1027,48 +1027,6 @@ function get_all_subcategories($catid) {
}
/**
- * 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)
*
View
@@ -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;
+}
View
@@ -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

0 comments on commit 2d8a275

Please sign in to comment.