From ca92b391584f6faa05524dc4460c584df8eb8ba0 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:13:45 +0000 Subject: [PATCH] accesslib: create_context() fix to also populate the depth Set the depth field correctly. --- lib/accesslib.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 918fde9223..d0e226b0ef 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1985,50 +1985,56 @@ function create_context($contextlevel, $instanceid) { // Define $context->path based on the parent // context. In other words... Who is your daddy? - $basepath = '/' . SYSCONTEXTID; + $basepath = '/' . SYSCONTEXTID; + $basedepth = 1; switch ($contextlevel) { case CONTEXT_COURSECAT: - $sql = "SELECT ctx.path + $sql = "SELECT ctx.path, ctx.depth FROM {$CFG->prefix}context ctx JOIN {$CFG->prefix}course_categories cc ON (cc.parent=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT.") WHERE cc.id={$instanceid}"; - if ($path = get_field_sql($sql)) { - $basepath = $path; + if ($p = get_record_sql($sql)) { + $basepath = $p->path; + $basedepth = $p->depth; } break; case CONTEXT_COURSE: - $sql = "SELECT ctx.path + $sql = "SELECT ctx.path, ctx.depth FROM {$CFG->prefix}context ctx JOIN {$CFG->prefix}course c ON (c.category=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSECAT.") WHERE c.id={$instanceid} AND c.id !=" . SITEID; - if ($path = get_field_sql($sql)) { - $basepath = $path; + if ($p = get_record_sql($sql)) { + $basepath = $p->path; + $basedepth = $p->depth; } break; case CONTEXT_MODULE: - $sql = "SELECT ctx.path + $sql = "SELECT ctx.path, ctx.depth FROM {$CFG->prefix}context ctx JOIN {$CFG->prefix}course_modules cm ON (cm.course=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") WHERE cm.id={$instanceid}"; - $path = get_field_sql($sql); - $basepath = $path; + $p = get_record_sql($sql); + $basepath = $p->path; + $basedepth = $p->depth; break; case CONTEXT_BLOCK: // Only non-pinned & course-page based - $sql = "SELECT ctx.path + $sql = "SELECT ctx.path, ctx.depth FROM {$CFG->prefix}context ctx JOIN {$CFG->prefix}block_instance bi ON (bi.pageid=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") WHERE bi.id={$instanceid} AND bi.pagetype='course-view'"; - $path = get_field_sql($sql); - $basepath = $path; + if ($p = get_record_sql($sql)) { + $basepath = $p->path; + $basedepth = $p->depth; + } break; case CONTEXT_USER: // default to basepath @@ -2038,6 +2044,8 @@ function create_context($contextlevel, $instanceid) { break; } + $context->depth = $basedepth+1; + if ($id = insert_record('context',$context)) { // can't set the path till we know the id! set_field('context', 'path', $basepath . '/' . $id, -- 2.39.5