]> git.mjollnir.org Git - moodle.git/commitdiff
datalib: get_my_courses() - some fixes to the data we return
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:04:10 +0000 (07:04 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:04:10 +0000 (07:04 +0000)
strangely, get_my_courses() is expected to return the
array keyed on id, which messes up the sorting

So let's do it ;-)

lib/accesslib.php
lib/datalib.php

index 903266c6bd4b7c4170568f65d3205e745c6e0e44..95bda1938f0ee4ca5825cbde4fa17eb33ed2002f 100755 (executable)
@@ -1796,8 +1796,6 @@ function get_user_access_bycontext($userid, $context, $acc=NULL) {
 function load_all_capabilities() {
     global $USER,$CFG;
 
-    unset($USER->mycourses);        // Reset a cache used by get_my_courses
-
     static $defcaps;
 
     $base = '/'.SYSCONTEXTID;
index c8f3370563fb4d6ccaad5f05ba37e47cb2e66f82..ec610478df925b01735089cc66043a765f08c51f 100644 (file)
@@ -624,15 +624,21 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL
     }
 
     if ($userid === $USER->id && isset($USER->access)) {
-        return get_courses_bycap_fromsess('moodle/course:view', $USER->access,
-                                          $doanything, $sort, $fields,
-                                          $limit);
+        $accessinfo = $USER->access;
     } else {
         $accessinfo = get_user_access_sitewide($userid);
-        return get_courses_bycap_fromsess('moodle/course:view', $accessinfo,
+    }
+    $courses = get_courses_bycap_fromsess('moodle/course:view', $accessinfo,
                                           $doanything, $sort, $fields,
                                           $limit);
-    }
+    // strangely, get_my_courses() is expected to return the
+    // array keyed on id, which messes up the sorting
+    $kcourses = array();
+    $cc = count($courses);
+    for ($n=0; $n<$cc; $n++) {
+        $kcourses[$courses[$n]->id] = $courses[$n];
+    }
+    return $kcourses;
 }
 
 /**