From: skodak <skodak>
Date: Mon, 18 Feb 2008 20:14:16 +0000 (+0000)
Subject: MDL-13399 prevent ambiguous column names in get_my_courses; merged from MOODLE_19_STABLE
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7007049315a05efeb5f4c2b544744f605e0ffeee;p=moodle.git

MDL-13399 prevent ambiguous column names in get_my_courses; merged from MOODLE_19_STABLE
---

diff --git a/lib/datalib.php b/lib/datalib.php
index 0d245663b7..7303a36f5a 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -832,6 +832,16 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL
     $orderby = '';
     $sort    = trim($sort);
     if (!empty($sort)) {
+        $rawsorts = explode(',', $sort);
+        $sorts = array();
+        foreach ($rawsorts as $rawsort) {
+            $rawsort = trim($rawsort);
+            if (strpos('c.', $rawsort)) {
+                $rawsort = substr($rawsort, 2);
+            }
+            $sorts[] = trim($rawsort);
+        }
+        $sort = 'c.'.implode(',c.', $sorts);
         $orderby = "ORDER BY $sort";
     }