MDL-57564 enrol: Change the default sort in other two functions

Similarly to what the previous patch does, we now change the default
sorting in functions enrol_get_users_courses() and
enrol_get_all_users_courses() too.

The patch also adds missing phpDocs for the functions, improves the
readability of some existing bits and mentions the changes in the
enrol/upgrade.txt file.
This commit is contained in:
David Mudrák 2017-12-05 21:53:55 +01:00
parent ee2187273f
commit a3d003603a
2 changed files with 39 additions and 28 deletions

View File

@ -1,6 +1,11 @@
This files describes API changes in /enrol/* - plugins,
information provided here is intended especially for developers.
=== 3.5 ===
* Default sorting in enrol_get_my_courses(), enrol_get_all_users_courses() and enrol_get_users_courses() now respects
the site setting "navsortmycoursessort" and should be consistently used when displaying the courses in the UI.
=== 3.4 ===
* render_course_enrolment_users_table method has been removed from the renderer. The enrolled users page is now

View File

@ -544,27 +544,25 @@ function enrol_add_course_navigation(navigation_node $coursenode, $course) {
/**
* Returns list of courses current $USER is enrolled in and can access
*
* - $fields is an array of field names to ADD
* so name the fields you really need, which will
* be added and uniq'd
* The $fields param is a list of field names to ADD so name just the fields you really need,
* which will be added and uniq'd.
*
* If $allaccessible is true, this will additionally return courses that the current user is not
* enrolled in, but can access because they are open to the user for other reasons (course view
* permission, currently viewing course as a guest, or course allows guest access without
* password).
*
* @param string|array $fields
* @param string|null $sort
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
* @param int $limit max number of courses
* @param array $courseids the list of course ids to filter by
* @param bool $allaccessible Include courses user is not enrolled in, but can access
* @return array
*/
function enrol_get_my_courses($fields = null, $sort = null,
$limit = 0, $courseids = [], $allaccessible = false) {
global $CFG, $DB, $USER;
function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $courseids = [], $allaccessible = false) {
global $DB, $USER, $CFG;
if (is_null($sort)) {
if ($sort === null) {
if (empty($CFG->navsortmycoursessort)) {
$sort = 'visible DESC, sortorder ASC';
} else {
@ -796,19 +794,19 @@ function enrol_get_course_description_texts($course) {
/**
* Returns list of courses user is enrolled into.
* (Note: use enrol_get_all_users_courses if you want to use the list wihtout any cap checks )
*
* - $fields is an array of fieldnames to ADD
* so name the fields you really need, which will
* be added and uniq'd
* Note: Use {@link enrol_get_all_users_courses()} if you need the list without any capability checks.
*
* @param int $userid
* @param bool $onlyactive return only active enrolments in courses user may see
* @param string|array $fields
* @param string $sort
* The $fields param is a list of field names to ADD so name just the fields you really need,
* which will be added and uniq'd.
*
* @param int $userid User whose courses are returned, defaults to the current user.
* @param bool $onlyactive Return only active enrolments in courses user may see.
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
* @return array
*/
function enrol_get_users_courses($userid, $onlyactive = false, $fields = NULL, $sort = 'visible DESC,sortorder ASC') {
function enrol_get_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) {
global $DB;
$courses = enrol_get_all_users_courses($userid, $onlyactive, $fields, $sort);
@ -885,19 +883,27 @@ function enrol_user_sees_own_courses($user = null) {
}
/**
* Returns list of courses user is enrolled into without any capability checks
* - $fields is an array of fieldnames to ADD
* so name the fields you really need, which will
* be added and uniq'd
* Returns list of courses user is enrolled into without performing any capability checks.
*
* @param int $userid
* @param bool $onlyactive return only active enrolments in courses user may see
* @param string|array $fields
* @param string $sort
* The $fields param is a list of field names to ADD so name just the fields you really need,
* which will be added and uniq'd.
*
* @param int $userid User whose courses are returned, defaults to the current user.
* @param bool $onlyactive Return only active enrolments in courses user may see.
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
* @return array
*/
function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = NULL, $sort = 'visible DESC,sortorder ASC') {
global $DB;
function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) {
global $CFG, $DB;
if ($sort === null) {
if (empty($CFG->navsortmycoursessort)) {
$sort = 'visible DESC, sortorder ASC';
} else {
$sort = 'visible DESC, '.$CFG->navsortmycoursessort.' ASC';
}
}
// Guest account does not have any courses
if (isguestuser($userid) or empty($userid)) {