MDL-85115 core_grades: Sort the grade instances

This commit is contained in:
Huong Nguyen 2025-04-07 10:08:38 +07:00
parent e3b05240c1
commit 50c2179f08
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,7 @@
issueNumber: MDL-85115
notes:
core_grades:
- message: >
The `grade_object::fetch_all_helper()` now accepts a new `$sort`
parameter with a default value is `id ASC` to sort the grade instances
type: changed

View File

@ -174,9 +174,10 @@ abstract class grade_object {
* @param string $table The table to retrieve from
* @param string $classname The name of the class to instantiate
* @param array $params An array of conditions like $fieldname => $fieldvalue
* @return array|bool Array of object instances or false if not found
* @param string $sortby The SQL sort order. E.g. 'id ASC'
* @return array|bool Array of object instances (sorted by $sortby) or false if not found
*/
public static function fetch_all_helper($table, $classname, $params) {
public static function fetch_all_helper($table, $classname, $params, string $sortby = 'id ASC') {
global $DB; // Need to introspect DB here.
$instance = new $classname();
@ -217,7 +218,7 @@ abstract class grade_object {
}
global $DB;
$rs = $DB->get_recordset_select($table, $wheresql, $newparams);
$rs = $DB->get_recordset_select($table, $wheresql, $newparams, $sortby);
//returning false rather than empty array if nothing found
if (!$rs->valid()) {
$rs->close();