From 2c45ad6f186b5cc5d53d64ff10e7c0dd7a32eb00 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 7 Jul 2020 17:11:43 +0800 Subject: [PATCH] MDL-57678 core_course: Deprecate make_categories_options() Padding nested course categories by space to make them render in a tree structure does not really make a lot of sense as they are already being rendered as full paths. It's simpler to show them without the indentation. Given this, there's not much point keeping make_categories_options(). So it's better to deprecate this function and call core_course_category::make_categories_list() directly instead. --- course/classes/category.php | 2 -- course/lib.php | 17 ----------------- course/upgrade.txt | 4 ++++ lib/deprecatedlib.php | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/course/classes/category.php b/course/classes/category.php index cbe68789a86..abe5d565733 100644 --- a/course/classes/category.php +++ b/course/classes/category.php @@ -2592,8 +2592,6 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr * moving categories, where you do not want to allow people to move a category * to be the child of itself. * - * See also {@link make_categories_options()} - * * @param string/array $requiredcapability if given, only categories where the current * user has this capability will be returned. Can also be an array of capabilities, * in which case they are all required. diff --git a/course/lib.php b/course/lib.php index 98703cc2d78..7408941ffef 100644 --- a/course/lib.php +++ b/course/lib.php @@ -636,23 +636,6 @@ function get_category_or_system_context($categoryid) { } } -/** - * Returns full course categories trees to be used in html_writer::select() - * - * Calls {@link core_course_category::make_categories_list()} to build the tree and - * adds whitespace to denote nesting - * - * @return array array mapping course category id to the display name - */ -function make_categories_options() { - $cats = core_course_category::make_categories_list('', 0, ' / '); - foreach ($cats as $key => $value) { - // Prefix the value with the number of spaces equal to category depth (number of separators in the value). - $cats[$key] = str_repeat(' ', substr_count($value, ' / ')). $value; - } - return $cats; -} - /** * Print the buttons relating to course requests. * diff --git a/course/upgrade.txt b/course/upgrade.txt index 45dc3a15c63..16e84d35e04 100644 --- a/course/upgrade.txt +++ b/course/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in /course/*, information provided here is intended especially for developers. +=== 4.0 === + +* The function make_categories_options() has now been deprecated. Please use \core_course_category::make_categories_list() instead. + === 3.9 === * The function get_module_metadata is now deprecated. Please use \core_course\local\service\content_item_service instead. diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index c28996f6587..48661cb6bf8 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -3351,3 +3351,19 @@ function user_get_participants($courseid, $groupid = 0, $accesssince, $roleid, $ return $DB->get_recordset_sql("$select $from $where $sort", $params, $limitfrom, $limitnum); } + +/** + * Returns the list of full course categories to be used in html_writer::select() + * + * Calls {@see core_course_category::make_categories_list()} to build the list. + * + * @deprecated since Moodle 4.0 + * @todo This will be finally removed for Moodle 4.4 as part of MDL-69124. + * @return array array mapping course category id to the display name + */ +function make_categories_options() { + $deprecatedtext = __FUNCTION__ . '() is deprecated. Please use \core_course_category::make_categories_list() instead.'; + debugging($deprecatedtext, DEBUG_DEVELOPER); + + return core_course_category::make_categories_list('', 0, ' / '); +} -- 2.43.0