From: martinlanghoff Date: Wed, 19 Sep 2007 07:54:37 +0000 (+0000) Subject: accesslib: make_context_subobj() now expects ctxlevel, and fix all callers X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=45ea1afb16e99153d836f27c232a0159d1cdd148;p=moodle.git accesslib: make_context_subobj() now expects ctxlevel, and fix all callers make_context_subobj() was not providing a contextlevel property, and no callers fetched the field. This comes from its humble origins where it was only ever called for course objects. These days it's used in many other situations, so this patch DTRT and - fixes make_context_subobj() expect a cxtlevel and turn it into contextlevel - fixes all callers (accesslib, datalib) to provide it --- diff --git a/lib/accesslib.php b/lib/accesslib.php index ab086481d5..a7b3aeaa2a 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -825,7 +825,8 @@ 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, ctx.contextlevel AS ctxlevel, cc.path AS categorypath FROM {$CFG->prefix}course c JOIN {$CFG->prefix}course_categories cc @@ -876,7 +877,8 @@ 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, ctx.contextlevel AS ctxlevel, cc.path AS categorypath FROM {$CFG->prefix}course c JOIN {$CFG->prefix}course_categories cc @@ -948,7 +950,8 @@ function get_context_users_byrole ($context, $roleid, $fields=NULL, $where=NULL, $contexts = str_replace('/', ',', $contexts); $sql = "SELECT $userfields, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}user u JOIN {$CFG->prefix}context ctx ON (u.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_USER.") @@ -1062,7 +1065,8 @@ function get_context_users_bycap ($context, $capability='moodle/course:view', $f // Get users $sql = "SELECT $userfields, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}user u JOIN {$CFG->prefix}context ctx ON (u.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_USER.") @@ -4542,8 +4546,9 @@ function make_context_subobj($rec) { $ctx->id = $rec->ctxid; unset($rec->ctxid); $ctx->path = $rec->ctxpath; unset($rec->ctxpath); $ctx->depth = $rec->ctxdepth; unset($rec->ctxdepth); + $ctx->contextlevel = $rec->ctxlevel; unset($rec->ctxlevel); $ctx->instanceid = $rec->id; - $ctx->contextlevel = CONTEXT_COURSE; + $rec->context = $ctx; return $rec; } diff --git a/lib/datalib.php b/lib/datalib.php index 87da06debd..283de16e18 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -515,7 +515,8 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c // pull out all course matching the cat $visiblecourses = array(); if (!($rs = get_recordset_sql("SELECT $fields, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course c JOIN {$CFG->prefix}context ctx ON (c.id = ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") @@ -667,7 +668,8 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a // pull out all courses matching the cat $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, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course c JOIN {$CFG->prefix}context ctx ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") @@ -906,7 +908,8 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL // (but here we don't need to check has_cap) $coursefields = 'c.' .join(',c.', $fields); $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, ctx.contextlevel AS ctxlevel, cc.path AS categorypath FROM {$CFG->prefix}course c JOIN {$CFG->prefix}course_categories cc @@ -951,7 +954,8 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL // to eval course visibility, get the categories if (empty($CFG->allowvisiblecoursesinhiddencategories)) { $sql = "SELECT cc.id, cc.path, cc.visible, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth as ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course_categories cc JOIN {$CFG->prefix}context ctx ON (cc.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT.") @@ -1131,7 +1135,8 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record } $sql = "SELECT c.*, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course c JOIN {$CFG->prefix}context ctx ON (c.id = ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") @@ -1198,7 +1203,8 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) { if ($parent === 'none') { $sql = "SELECT cc.*, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course_categories cc JOIN {$CFG->prefix}context ctx ON cc.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT." @@ -1206,7 +1212,8 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) { } elseif ($shallow) { $parent = (int)$parent; $sql = "SELECT cc.*, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course_categories cc JOIN {$CFG->prefix}context ctx ON cc.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT." @@ -1215,7 +1222,8 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) { } else { $parent = (int)$parent; $sql = "SELECT cc.*, - ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth as ctxdepth + ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel FROM {$CFG->prefix}course_categories cc JOIN {$CFG->prefix}context ctx ON cc.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT."