From bd1f93687d587952994a2acecab6c3d3e84083eb Mon Sep 17 00:00:00 2001 From: ericmerrill Date: Thu, 8 Oct 2009 04:52:16 +0000 Subject: [PATCH] My Moodle/Courses: MDL-20472 get_my_courses returns 2 more courses then limit. Repairs two off by one errors in get_my_courses and get_user_courses_bycap. --- lib/accesslib.php | 6 ++++-- lib/datalib.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index b5d0782cb29..682926ecbab 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1118,10 +1118,12 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort=' $c = make_context_subobj($c); if (has_capability_in_accessdata($cap, $c->context, $accessdata, $doanything)) { - $courses[] = $c; - if ($limit > 0 && $cc++ > $limit) { + if ($limit > 0 && $cc >= $limit) { break; } + + $courses[] = $c; + $cc++; } } rs_close($rs); diff --git a/lib/datalib.php b/lib/datalib.php index ccb05262416..fcea8d78401 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -916,10 +916,12 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL // build the context obj $c = make_context_subobj($c); - $courses[$c->id] = $c; - if ($limit > 0 && $cc++ > $limit) { + if ($limit > 0 && $cc >= $limit) { break; } + + $courses[$c->id] = $c; + $cc++; } rs_close($rs); return $courses;