MDL-10965 core: deprecate function get_courses_page
This commit is contained in:
@@ -654,73 +654,6 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
|
||||
return $visiblecourses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses CONTEXT_COURSE
|
||||
* @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="") {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of courses that match a search
|
||||
*
|
||||
|
||||
@@ -3611,3 +3611,70 @@ function message_get_contact($contactid) {
|
||||
|
||||
return \core_message\api::get_contact($USER->id, $contactid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 41 - 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user