Skip to content

Commit

Permalink
MDL-65319 core: Final deprecation get_courses_page
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed Nov 24, 2020
1 parent c8d33eb commit 8626965
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 63 deletions.
69 changes: 6 additions & 63 deletions lib/deprecatedlib.php
Expand Up @@ -2753,70 +2753,13 @@ function message_get_contact() {
}

/**
* Returns list of courses, for whole site, or category
*
* Similar to get_courses, but allows paging
* Important: Using c.* for fields is extremely expensive because
* we are using distinct. You almost _NEVER_ need all the fields
* in such a large SELECT
*
* @deprecated since Moodle 3.7
* @todo The final deprecation of this function will take place in Moodle 3.11 - see MDL-65319.
*
* @param string|int $categoryid Either a category id or 'all' for everything
* @param string $sort A field and direction to sort by
* @param string $fields The additional fields to return
* @param int $totalcount Reference for the number of courses
* @param string $limitfrom The course to start from
* @param string $limitnum The number of courses to limit to
* @return array Array of courses
*/
function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
&$totalcount, $limitfrom="", $limitnum="") {
debugging('Function get_courses_page() is deprecated. Please use core_course_category::get_courses() ' .
'or core_course_category::search_courses()', DEBUG_DEVELOPER);
global $USER, $CFG, $DB;

$params = array();

$categoryselect = "";
if ($categoryid !== "all" && is_numeric($categoryid)) {
$categoryselect = "WHERE c.category = :catid";
$params['catid'] = $categoryid;
} else {
$categoryselect = "";
}

$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$params['contextlevel'] = CONTEXT_COURSE;

$totalcount = 0;
if (!$limitfrom) {
$limitfrom = 0;
}
$visiblecourses = array();

$sql = "SELECT $fields $ccselect
FROM {course} c
$ccjoin
$categoryselect
ORDER BY $sort";

// Pull out all course matching the cat.
$rs = $DB->get_recordset_sql($sql, $params);
// Iteration will have to be done inside loop to keep track of the limitfrom and limitnum.
foreach ($rs as $course) {
context_helper::preload_from_record($course);
if (core_course_category::can_view_course_info($course)) {
$totalcount++;
if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
$visiblecourses [$course->id] = $course;
}
}
}
$rs->close();
return $visiblecourses;
*/
function get_courses_page() {
throw new coding_exception(
'Function get_courses_page() has been removed. Please use core_course_category::get_courses() ' .
'or core_course_category::search_courses()'
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Expand Up @@ -4,6 +4,8 @@ information provided here is intended especially for developers.
=== 3.11 ===
* New optional parameter $extracontent for print_collapsible_region_start(). This allows developers to add interactive HTML elements
(e.g. a help icon) after the collapsible region's toggle link.
* Final deprecation of get_courses_page. Function has been removed and core_course_category::get_courses() should be
used instead.

=== 3.10 ===
* PHPUnit has been upgraded to 8.5. That comes with a few changes:
Expand Down

0 comments on commit 8626965

Please sign in to comment.