Skip to content

Commit

Permalink
Merge pull request #230 from Benjamin-unige/improve-sortby-name
Browse files Browse the repository at this point in the history
Fix #229 Adding conditional CAST on SORT BY when ordering by group name
  • Loading branch information
NicoAlexH authored Nov 12, 2024
2 parents 684567c + ec2b44d commit 0f71c05
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,14 @@ function choicegroup_get_choicegroup($choicegroupid) {
$grpfilter = "AND grp_o.groupid = :groupid";
}

$castorderby = ($sortcolumn == 'name') ? $DB->sql_cast_char2int("REGEXP_SUBSTR($sortcolumn, '[0-9]+')") . "," : "";

$sql = "SELECT grp_m.id grpmemberid, grp_m.userid, grp_o.id, grp_o.groupid, grp_o.maxanswers
FROM {groups} grp
INNER JOIN {choicegroup_options} grp_o on grp.id = grp_o.groupid
LEFT JOIN {groups_members} grp_m on grp_m.groupid = grp_o.groupid
WHERE grp_o.choicegroupid = :choicegroupid $grpfilter
ORDER BY $sortcolumn ASC";
ORDER BY $castorderby $sortcolumn ASC";

$rs = $DB->get_recordset_sql($sql, $params);

Expand Down

0 comments on commit 0f71c05

Please sign in to comment.