]> git.mjollnir.org Git - moodle.git/commitdiff
Upgrading table to rename the context->aggregatelevel field which was
authormoodler <moodler>
Fri, 22 Sep 2006 06:19:32 +0000 (06:19 +0000)
committermoodler <moodler>
Fri, 22 Sep 2006 06:19:32 +0000 (06:19 +0000)
really bugging me.   Code should be a little bit more readable now.

Apologies to those with non-core code already using this field.

12 files changed:
admin/roles/assign.php
admin/roles/override.php
admin/roles/tabs.php
lib/accesslib.php
lib/db/install.xml
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
lib/statslib.php
mod/forum/lib.php
version.php

index 7b19cda2f7bdc59620028df59173c76eb199d4ea..bc8e751327abfd4a49a177cc865d8606e05aad96 100755 (executable)
@@ -28,7 +28,7 @@
 
 
     $inmeta = 0;
-    if ($context->aggregatelevel == CONTEXT_COURSE) {
+    if ($context->contextlevel == CONTEXT_COURSE) {
         $courseid = $context->instanceid;
         if ($course = get_record('course', 'id', $courseid)) {
             $inmeta = $course->metacourse;
@@ -79,7 +79,7 @@
 
 /// Print the header and tabs
 
-    if ($context->aggregatelevel == CONTEXT_USER) {
+    if ($context->contextlevel == CONTEXT_USER) {
         /// course header
         if ($courseid!= SITEID) {
             print_header("$fullname", "$fullname",
index 5190699292415a74c03a396b816ab5762e553de8..b21be28d827116c4f02e18f130a3f840fd15e817 100755 (executable)
@@ -49,7 +49,7 @@
 
 /// Print the header and tabs
 
-    if ($context->aggregatelevel == CONTEXT_USER) {
+    if ($context->contextlevel == CONTEXT_USER) {
 
         /// course header
         if ($course->id != SITEID) {
index b74a598f001db1b61a96f23e6159e0d95aac53f6..c2720dd890edb1e25726df9117afc4216746e3af 100755 (executable)
@@ -3,7 +3,7 @@
 // Handles headers and tabs for the roles control at any level apart from SYSTEM level
 
 if ($currenttab != 'update') {
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM:
             $stradministration = get_string('administration');
@@ -104,9 +104,9 @@ if ($currenttab != 'update') {
 }
 
 
-if ($context->aggregatelevel != CONTEXT_SYSTEM) {    // Print tabs for anything except SYSTEM context
+if ($context->contextlevel != CONTEXT_SYSTEM) {    // Print tabs for anything except SYSTEM context
 
-    if ($context->aggregatelevel == CONTEXT_MODULE) { // only show update button if module?
+    if ($context->contextlevel == CONTEXT_MODULE) { // only show update button if module?
 
         $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
                        $context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('update'));
index a06a723756a117e2f856a189578b4c0303203629..8e28f4f45bc0a788acab83f07fff99f8cea67a00 100755 (executable)
@@ -234,7 +234,7 @@ function require_capability($capability, $context=NULL, $userid=NULL, $doanythin
 /// If the current user is not logged in, then make sure they are
 
     if (empty($userid) and empty($USER->id)) {
-        if ($context && ($context->aggregatelevel == CONTEXT_COURSE)) {
+        if ($context && ($context->contextlevel == CONTEXT_COURSE)) {
             require_login($context->instanceid);
         } else {
             require_login();
@@ -310,7 +310,7 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
             }
         }
 
-        switch ($context->aggregatelevel) {
+        switch ($context->contextlevel) {
 
             case CONTEXT_COURSECAT:
                 // Check parent cats.
@@ -419,14 +419,14 @@ function capability_search($capability, $context, $capabilities) {
     global $USER, $CFG;
 
     if (isset($capabilities[$context->id][$capability])) {
-        debugging("Found $capability in context $context->id at level $context->aggregatelevel: ".$capabilities[$context->id][$capability], E_ALL);
+        debugging("Found $capability in context $context->id at level $context->contextlevel: ".$capabilities[$context->id][$capability], E_ALL);
         return ($capabilities[$context->id][$capability]);
     }
 
     /* Then, we check the cache recursively */
     $permission = 0;
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM: // by now it's a definite an inherit
             $permission = 0;
@@ -481,7 +481,7 @@ function capability_search($capability, $context, $capabilities) {
             error ('This is an unknown context!');
         return false;
     }
-    debugging("Found $capability recursively from context $context->id at level $context->aggregatelevel: $permission", E_ALL);
+    debugging("Found $capability recursively from context $context->id at level $context->contextlevel: $permission", E_ALL);
 
     return $permission;
 }
@@ -569,7 +569,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
 
     $siteinstance = get_context_instance(CONTEXT_SYSTEM, SITEID);
 
-    $SQL = " SELECT  rc.capability, c1.id, (c1.aggregatelevel * 100) AS aggrlevel,
+    $SQL = " SELECT  rc.capability, c1.id, (c1.contextlevel * 100) AS aggrlevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments ra,
@@ -584,12 +584,12 @@ function load_user_capability($capability='', $context ='', $userid='') {
                      $capsearch
                      $timesql
               GROUP BY
-                     rc.capability, (c1.aggregatelevel * 100), c1.id
+                     rc.capability, (c1.contextlevel * 100), c1.id
                      HAVING
                      SUM(rc.permission) != 0
               UNION
 
-              SELECT rc.capability, c1.id, (c1.aggregatelevel * 100 + c2.aggregatelevel) AS aggrlevel,
+              SELECT rc.capability, c1.id, (c1.contextlevel * 100 + c2.contextlevel) AS aggrlevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments ra,
@@ -608,7 +608,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
                      $timesql
 
               GROUP BY
-                     rc.capability, (c1.aggregatelevel * 100 + c2.aggregatelevel), c1.id
+                     rc.capability, (c1.contextlevel * 100 + c2.contextlevel), c1.id
                      HAVING
                      SUM(rc.permission) != 0
               ORDER BY
@@ -627,7 +627,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
 
             foreach ($array as $key=>$val) {
                 if ($key == 'aggrlevel') {
-                    $temprecord->aggregatelevel = $val;
+                    $temprecord->contextlevel = $val;
                 } else {
                     $temprecord->{$key} = $val;
                 }
@@ -638,31 +638,31 @@ function load_user_capability($capability='', $context ='', $userid='') {
     }
 
     /* so up to this point we should have somethign like this
-     * $capabilities[1]    ->aggregatelevel = 1000
+     * $capabilities[1]    ->contextlevel = 1000
                            ->module = SITEID
                            ->capability = do_anything
                            ->id = 1 (id is the context id)
                            ->sum = 0
 
-     * $capabilities[2]     ->aggregatelevel = 1000
+     * $capabilities[2]     ->contextlevel = 1000
                             ->module = SITEID
                             ->capability = post_messages
                             ->id = 1
                             ->sum = -9000
 
-     * $capabilittes[3]     ->aggregatelevel = 3000
+     * $capabilittes[3]     ->contextlevel = 3000
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 25
                             ->sum = 1
 
-     * $capabilittes[4]     ->aggregatelevel = 3000
+     * $capabilittes[4]     ->contextlevel = 3000
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 26
                             ->sum = 0 (this is another course)
 
-     * $capabilities[5]     ->aggregatelevel = 3050
+     * $capabilities[5]     ->contextlevel = 3050
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 25 (override in course 25)
@@ -792,7 +792,7 @@ function capability_prohibits($capability, $context, $sum='', $array='') {
             return true;
         }
     }
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM:
             // By now it's a definite an inherit.
@@ -1092,10 +1092,10 @@ function islegacy($capabilityname) {
  * @param $level
  * @param $instanceid
  */
-function create_context($aggregatelevel, $instanceid) {
-    if (!get_record('context','aggregatelevel',$aggregatelevel,'instanceid',$instanceid)) {
+function create_context($contextlevel, $instanceid) {
+    if (!get_record('context','contextlevel',$contextlevel,'instanceid',$instanceid)) {
         $context = new object;
-        $context->aggregatelevel = $aggregatelevel;
+        $context->contextlevel = $contextlevel;
         $context->instanceid = $instanceid;
         return insert_record('context',$context);
     }
@@ -1108,12 +1108,12 @@ function create_context($aggregatelevel, $instanceid) {
  * @param $level
  * @param $instance
  */
-function get_context_instance($aggregatelevel=NULL, $instance=SITEID) {
+function get_context_instance($contextlevel=NULL, $instance=SITEID) {
 
     global $context_cache, $context_cache_id, $CONTEXT;
 
 /// If no level is supplied then return the current global context if there is one
-    if (empty($aggregatelevel)) {
+    if (empty($contextlevel)) {
         if (empty($CONTEXT)) {
             debugging("Error: get_context_instance() called without a context");
         } else {
@@ -1122,19 +1122,19 @@ function get_context_instance($aggregatelevel=NULL, $instance=SITEID) {
     }
 
 /// Check the cache
-    if (isset($context_cache[$aggregatelevel][$instance])) {  // Already cached
-        return $context_cache[$aggregatelevel][$instance];
+    if (isset($context_cache[$contextlevel][$instance])) {  // Already cached
+        return $context_cache[$contextlevel][$instance];
     }
 
 /// Get it from the database, or create it
-    if (!$context = get_record('context', 'aggregatelevel', $aggregatelevel, 'instanceid', $instance)) {
-        create_context($aggregatelevel, $instance);
-        $context = get_record('context', 'aggregatelevel', $aggregatelevel, 'instanceid', $instance);
+    if (!$context = get_record('context', 'contextlevel', $contextlevel, 'instanceid', $instance)) {
+        create_context($contextlevel, $instance);
+        $context = get_record('context', 'contextlevel', $contextlevel, 'instanceid', $instance);
     }
 
 /// Only add to cache if context isn't empty.
     if (!empty($context)) {
-        $context_cache[$aggregatelevel][$instance] = $context;    // Cache it for later
+        $context_cache[$contextlevel][$instance] = $context;    // Cache it for later
         $context_cache_id[$context->id] = $context;      // Cache it for later
     }
 
@@ -1155,7 +1155,7 @@ function get_context_instance_by_id($id) {
     }
 
     if ($context = get_record('context', 'id', $id)) {   // Update the cache and return
-        $context_cache[$context->aggregatelevel][$context->instanceid] = $context;
+        $context_cache[$context->contextlevel][$context->instanceid] = $context;
         $context_cache_id[$context->id] = $context;
         return $context;
     }
@@ -1444,7 +1444,7 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
     }
 
     /// now handle metacourse role assignments if in course context
-    if ($success and $context->aggregatelevel == CONTEXT_COURSE) {
+    if ($success and $context->contextlevel == CONTEXT_COURSE) {
         if ($parents = get_records('course_meta', 'child_course', $context->instanceid)) {
             foreach ($parents as $parent) {
                 sync_metacourse($parent->parent_course);
@@ -1504,7 +1504,7 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0) {
                 }
 
                 /// now handle metacourse role unassigment and removing from goups if in course context
-                if (!empty($context) and $context->aggregatelevel == CONTEXT_COURSE) {
+                if (!empty($context) and $context->contextlevel == CONTEXT_COURSE) {
                     //remove from groups when user has no role
                     $roles = get_user_roles($context, $ra->userid, true);
                     if (empty($roles)) {
@@ -1573,7 +1573,7 @@ function role_add_lastaccess_entries($userid, $context) {
 
     global $USER, $CFG;
 
-    if (empty($context->aggregatelevel)) {
+    if (empty($context->contextlevel)) {
         return false;
     }
 
@@ -1581,7 +1581,7 @@ function role_add_lastaccess_entries($userid, $context) {
     $lastaccess->userid = $userid;
     $lastaccess->timeaccess = 0;
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM:   // For the whole site
              if ($courses = get_record('course')) {
@@ -1816,7 +1816,7 @@ function capabilities_cleanup($component, $newcapdef=NULL) {
 function print_context_name($context) {
 
     $name = '';
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM: // by now it's a definite an inherit
             $name = get_string('site');
@@ -1903,7 +1903,7 @@ function fetch_context_capabilities($context) {
 
     $sort = 'ORDER BY contextlevel,component,id';   // To group them sensibly for display
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM: // all
             $SQL = "select * from {$CFG->prefix}capabilities";
@@ -1953,7 +1953,7 @@ function fetch_context_capabilities($context) {
     $records = array_merge($records, $contextindependentcaps);
 
     // special sorting of core system capabiltites and enrollments
-    if ($context->aggregatelevel == CONTEXT_SYSTEM) {
+    if ($context->contextlevel == CONTEXT_SYSTEM) {
         $first = array();
         foreach ($records as $key=>$record) {
             if (preg_match('|^moodle/|', $record->name) and $record->contextlevel == CONTEXT_SYSTEM) {
@@ -2022,7 +2022,7 @@ function role_context_capabilities($roleid, $context, $cap='') {
             WHERE rc.contextid in $contexts
                  AND rc.roleid = $roleid
                  AND rc.contextid = c.id $search
-            ORDER BY c.aggregatelevel DESC,
+            ORDER BY c.contextlevel DESC,
                      rc.capability DESC";
 
     $capabilities = array();
@@ -2048,7 +2048,7 @@ function role_context_capabilities($roleid, $context, $cap='') {
  */
 function get_parent_contexts($context) {
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM: // no parent
             return array();
@@ -2390,7 +2390,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true) {
                            '   AND ra.roleid = r.id
                                AND ra.contextid = c.id
                                AND '.$contexts.
-                           ' ORDER BY c.aggregatelevel DESC');
+                           ' ORDER BY c.contextlevel DESC');
 }
 
 /**
@@ -2537,7 +2537,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
     $sortby = $sort ? " ORDER BY $sort " : '';
 
 /// If context is a course, then construct sql for ul
-    if ($context->aggregatelevel == CONTEXT_COURSE) {
+    if ($context->contextlevel == CONTEXT_COURSE) {
         $courseid = $context->instanceid;
         $coursesql = "AND (ul.courseid = $courseid OR ul.courseid IS NULL)";
     } else {
index 44da08c6eaae0924eafcddb5b931cc6dff9ce9f1..5f5f48b5179bfdc4ad833531c8cdb591e4d4c7d2 100644 (file)
     </TABLE>
     <TABLE NAME="context" COMMENT="one of these must be set" PREVIOUS="role" NEXT="capabilities">
       <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="aggregatelevel"/>
-        <FIELD NAME="aggregatelevel" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="instanceid"/>
-        <FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="aggregatelevel"/>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="contextlevel"/>
+        <FIELD NAME="contextlevel" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="instanceid"/>
+        <FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="contextlevel"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for context"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="aggregatelevel-instanceid" UNIQUE="true" FIELDS="aggregatelevel, instanceid" NEXT="instanceid"/>
-        <INDEX NAME="instanceid" UNIQUE="false" FIELDS="instanceid" PREVIOUS="aggregatelevel-instanceid"/>
+        <INDEX NAME="contextlevel-instanceid" UNIQUE="true" FIELDS="contextlevel, instanceid" NEXT="instanceid"/>
+        <INDEX NAME="instanceid" UNIQUE="false" FIELDS="instanceid" PREVIOUS="contextlevel-instanceid"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="capabilities" COMMENT="this defines all capabilities" PREVIOUS="context" NEXT="role_allow_assign">
       </SENTENCES>
     </STATEMENT>
   </STATEMENTS>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index 775fbe6946646746e05c9bb1e7c2ffdb999f33d3..aa6f5e99e12360bcda4ab7090ebb7843c6142f9f 100644 (file)
@@ -2285,6 +2285,12 @@ function main_upgrade($oldversion=0) {
 
     }
 
+    if ($oldversion < 2006092200) {
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `aggregatelevel-instanceid`;",false);
+        table_column('context', 'aggregatelevel', 'contextlevel', 'int', '10', 'unsigned', '0', 'not null', '');
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `contextlevel-instanceid` (`contextlevel`, `instanceid`)",false);
+    }
+
 
     return $result;
 }
index c450b6853ba1edc0212a443b8d8744ec59e88eff..7fccceb714c9f5debbab6ea1eaf158ad2d9fcc54 100644 (file)
@@ -901,10 +901,10 @@ CREATE TABLE prefix_role (
 
 CREATE TABLE prefix_context (
   `id` int(10) unsigned NOT NULL auto_increment,
-  `aggregatelevel` int(10) unsigned NOT NULL default '0',
+  `contextlevel` int(10) unsigned NOT NULL default '0',
   `instanceid` int(10) unsigned NOT NULL default '0',
   KEY `instanceid` (`instanceid`),
-  UNIQUE KEY `aggregatelevel-instanceid` (`aggregatelevel`, `instanceid`),
+  UNIQUE KEY `contextlevel-instanceid` (`contextlevel`, `instanceid`),
   PRIMARY KEY  (`id`)
 ) TYPE=MyISAM COMMENT ='one of these must be set';
 
index 9a1fafe3b3214fc64ba2de84d3d1bf95746c2183..9fe8117a49be7eb1567d7f122be37e66bba0da69 100644 (file)
@@ -1884,6 +1884,12 @@ function main_upgrade($oldversion=0) {
 
     }
 
+    if ($oldversion < 2006092200) {
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `aggregatelevel-instanceid`;",false);
+        table_column('context', 'aggregatelevel', 'contextlevel', 'int', '10', 'unsigned', '0', 'not null', '');
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `contextlevel-instanceid` (`contextlevel`, `instanceid`)",false);
+    }
+
 
     return $result;
 }
index ec52b9362e6afa527ef763f5f632821f2d779f7c..c2745b9ce04ce16638837bd3fbdb9863038d9600 100644 (file)
@@ -674,11 +674,11 @@ CREATE INDEX prefix_role_sortorder_idx ON prefix_role (sortorder);
          
 CREATE TABLE prefix_context (    
   id SERIAL PRIMARY KEY,     
-  aggregatelevel integer NOT NULL default 0,      
+  contextlevel integer NOT NULL default 0,      
   instanceid integer NOT NULL default 0      
 );
 CREATE INDEX prefix_context_instanceid_idx ON prefix_context (instanceid);
-CREATE UNIQUE INDEX prefix_context_aggregatelevelinstanceid_idx ON prefix_context (aggregatelevel, instanceid);
+CREATE UNIQUE INDEX prefix_context_contextlevelinstanceid_idx ON prefix_context (contextlevel, instanceid);
          
 CREATE TABLE prefix_role_assignments (   
   id SERIAL PRIMARY KEY,     
index b30f288d07c780fb5fe95850506301024a1af714..5c5a58f367e957ce52bb8fb87b38c64536dc4107 100644 (file)
@@ -151,13 +151,13 @@ function stats_cron_daily () {
                    FROM '.$CFG->prefix.'role_assignments ra 
                    INNER JOIN '.$CFG->prefix.'role r_outmost ON (ra.roleid=r_outmost.id)
                    INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
-                   WHERE roleid='.$role->id.' AND c.instanceid='.$course->id.' AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                   WHERE roleid='.$role->id.' AND c.instanceid='.$course->id.' AND c.contextlevel = '.CONTEXT_COURSE.'
                    AND NOT EXISTS
                    (SELECT 1 
                        FROM '.$CFG->prefix.'role_assignments 
                        INNER JOIN '.$CFG->prefix.'role ON ('.$CFG->prefix.'role.id=roleid)
                        INNER JOIN '.$CFG->prefix.'context ON contextid = c.id
-                       WHERE instanceid='.$course->id.' AND userid=ra.userid AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                       WHERE instanceid='.$course->id.' AND userid=ra.userid AND c.contextlevel = '.CONTEXT_COURSE.'
                        AND '.$CFG->prefix.'role.sortorder < r_outmost.sortorder
                    )';
 
@@ -168,13 +168,13 @@ function stats_cron_daily () {
                    INNER JOIN '.$CFG->prefix.'role r_outmost ON (ra.roleid=r_outmost.id)
                    INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
                    INNER JOIN '.$CFG->prefix.'log l ON (ra.userid=l.userid AND course=instanceid)
-                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND '.$timesql.' AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND '.$timesql.' AND c.contextlevel = '.CONTEXT_COURSE.'
                    AND NOT EXISTS
                    (SELECT 1 
                        FROM '.$CFG->prefix.'role_assignments
                        INNER JOIN '.$CFG->prefix.'role ON (mdl_role.id=roleid)
                        INNER JOIN '.$CFG->prefix.'context c ON contextid = c.id
-                       WHERE instanceid='.$course->id.' AND userid=ra.userid AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                       WHERE instanceid='.$course->id.' AND userid=ra.userid AND c.contextlevel = '.CONTEXT_COURSE.'
                        AND '.$CFG->prefix.'role.sortorder < r_outmost.sortorder
                    )';
                 
@@ -195,14 +195,14 @@ function stats_cron_daily () {
                    INNER JOIN '.$CFG->prefix.'role r_outmost ON (ra.roleid=r_outmost.id)
                    INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
                    INNER JOIN '.$CFG->prefix.'log l ON (ra.userid=l.userid AND course=instanceid)
-                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND c.contextlevel = '.CONTEXT_COURSE.'
                    AND '.$timesql.' '.stats_get_action_sql_in('view').'
                    AND NOT EXISTS
                    (SELECT 1 
                        FROM '.$CFG->prefix.'role_assignments
                        INNER JOIN '.$CFG->prefix.'role ON (mdl_role.id=roleid)
                        INNER JOIN '.$CFG->prefix.'context c ON contextid = c.id
-                       WHERE instanceid='.$course->id.' AND userid=ra.userid  AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                       WHERE instanceid='.$course->id.' AND userid=ra.userid  AND c.contextlevel = '.CONTEXT_COURSE.'
                        AND '.$CFG->prefix.'role.sortorder < r_outmost.sortorder
                    )';
                 
@@ -212,14 +212,14 @@ function stats_cron_daily () {
                    INNER JOIN '.$CFG->prefix.'role r_outmost ON (ra.roleid=r_outmost.id)
                    INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
                    INNER JOIN '.$CFG->prefix.'log l ON (ra.userid=l.userid AND course=instanceid)
-                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                   WHERE roleid='.$role->id.' AND instanceid='.$course->id.' AND c.contextlevel = '.CONTEXT_COURSE.'
                    AND '.$timesql.' '.stats_get_action_sql_in('post').'
                    AND NOT EXISTS
                    (SELECT 1 
                        FROM '.$CFG->prefix.'role_assignments
                        INNER JOIN '.$CFG->prefix.'role ON (mdl_role.id=roleid)
                        INNER JOIN '.$CFG->prefix.'context c ON contextid = c.id
-                       WHERE instanceid='.$course->id.' AND userid=ra.userid  AND c.aggregatelevel = '.CONTEXT_COURSE.'
+                       WHERE instanceid='.$course->id.' AND userid=ra.userid  AND c.contextlevel = '.CONTEXT_COURSE.'
                        AND '.$CFG->prefix.'role.sortorder < r_outmost.sortorder
                    )';
                 $stat->stat2 = count_records_sql($sql);       
@@ -752,12 +752,12 @@ function stats_get_course_users($course,$timesql) {
     $sql = 'SELECT active_course_users.userid,
            (SELECT roleid FROM '.$CFG->prefix.'role_assignments INNER JOIN '.$CFG->prefix.'role a_u_r ON roleid=a_u_r.id
             INNER JOIN '.$CFG->prefix.'context c ON contextid = c.id
-            WHERE instanceid='.$course->id.' AND c.aggregatelevel = '.CONTEXT_COURSE.' AND userid=active_course_users.userid
+            WHERE instanceid='.$course->id.' AND c.contextlevel = '.CONTEXT_COURSE.' AND userid=active_course_users.userid
             AND NOT EXISTS (SELECT 1 FROM '.$CFG->prefix.'role_assignments o_r_a 
                                      INNER JOIN '.$CFG->prefix.'role o_r ON o_r_a.roleid = o_r.id 
                                      INNER JOIN '.$CFG->prefix.'context c on contextid = c.id  
                                      WHERE o_r.sortorder < a_u_r.sortorder  AND c.instanceid = '.$course->id.'
-                                     AND c.aggregatelevel = '.CONTEXT_COURSE.' AND o_r_a.userid = active_course_users.userid
+                                     AND c.contextlevel = '.CONTEXT_COURSE.' AND o_r_a.userid = active_course_users.userid
                             )
             ) AS primaryrole
             FROM (SELECT DISTINCT userid FROM '.$CFG->prefix.'log l WHERE course='.$course->id.' AND '.$timesql.') active_course_users';
index 95bd34ff03b98ff8e43eb16cc829de2598e415a2..f5fad5e17e8e606d525725d3e981af826a21e8dd 100644 (file)
@@ -3739,11 +3739,11 @@ function forum_role_unassign($userid, $context) {
 function forum_add_user_default_subscriptions($userid, $context) {
 /// Add subscriptions for new users
 
-    if (empty($context->aggregatelevel)) {
+    if (empty($context->contextlevel)) {
         return false;
     }
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM:   // For the whole site
              if ($courses = get_records('course')) {
@@ -3808,11 +3808,11 @@ function forum_add_user_default_subscriptions($userid, $context) {
 function forum_remove_user_subscriptions($userid, $context) {
 /// Remove subscriptions for a user in a context
 
-    if (empty($context->aggregatelevel)) {
+    if (empty($context->contextlevel)) {
         return false;
     }
 
-    switch ($context->aggregatelevel) {
+    switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM:   // For the whole site
              if ($courses = get_records('course')) {
@@ -4669,4 +4669,4 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
 
 
 
-?>
\ No newline at end of file
+?>
index ccdc5702388e6ad91ea2a7985d24f1a10cbea0bf..b5c28201ffd0d54f15a79f66337952fa6a4bc20c 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2006092100;  // YYYYMMDD = date
+   $version = 2006092200;  // YYYYMMDD = date
                            //       XY = increments within a single day
 
    $release = '1.7 dev';    // Human-friendly version name