From 956b2f102e21f1cd061a37d94c97ec7efe657921 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:18:37 +0000 Subject: [PATCH] accesslib: get_user_courses_bycap() also returns categorypath 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 7554d41a8..01513d83c 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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 -- 2.11.4.GIT