]> git.mjollnir.org Git - moodle.git/commitdiff
accesslib: get_user_courses_bycap() also returns categorypath
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:18:37 +0000 (07:18 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:18:37 +0000 (07:18 +0000)
Costs next to nothing according to testing, and allows us to walk
the categories very cheaply. We'll need this in get_my_courses()...

What a cheapskates I am...

lib/accesslib.php

index 7554d41a870134d654b023a62822cff3084bd4e8..01513d83c355bf018a756019e59c3d2876a86494 100755 (executable)
@@ -819,6 +819,9 @@ function has_capability_including_child_contexts($context, $capabilitynames) {
  * - the course records have $c->context which is a fully
  *   valid context object. Saves you a query per course!
  *
+ * - the course records have $c->categorypath to make
+ *   category lookups cheap
+ *
  * - current implementation is split in -
  *
  *   - if the user has the cap systemwide, stupidly
@@ -870,8 +873,11 @@ function get_user_courses_bycap($userid, $cap, $ad, $doanything, $sort='c.sortor
         // Yuck.
         //
         $sql = "SELECT $coursefields,
-                       ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth
+                       ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth,
+                       cc.path AS categorypath
                 FROM {$CFG->prefix}course c
+                JOIN {$CFG->prefix}course_categories cc
+                  ON c.category=cc.id
                 JOIN {$CFG->prefix}context ctx 
                   ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
                 ORDER BY $sort ";
@@ -918,8 +924,11 @@ function get_user_courses_bycap($userid, $cap, $ad, $doanything, $sort='c.sortor
         // appropriately and narrow things down...
         //
         $sql = "SELECT $coursefields,
-                       ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth
+                       ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth,
+                       cc.path AS categorypath
                 FROM {$CFG->prefix}course c
+                JOIN {$CFG->prefix}course_categories cc
+                  ON c.category=cc.id
                 JOIN {$CFG->prefix}context ctx 
                   ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
                 LEFT OUTER JOIN {$CFG->prefix}role_assignments ra