]> git.mjollnir.org Git - moodle.git/commitdiff
accesslib: make_context_subobj() now expects ctxlevel, and fix all callers
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:54:37 +0000 (07:54 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:54:37 +0000 (07:54 +0000)
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

lib/accesslib.php
lib/datalib.php

index ab086481d56514b8ef6703763b7ae098fa1693cd..a7b3aeaa2ad69843046363be0999ee03c60b8b93 100755 (executable)
@@ -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;
 }
index 87da06debdf841c197d1a6403b4fdbc0fea8c8ae..283de16e1856ab05fdea851b72e9d9928a4afa70 100644 (file)
@@ -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."