]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-14460, fix get_context_instance, merged from MOODLE_19_STABLE"
authordongsheng <dongsheng>
Thu, 1 May 2008 06:07:24 +0000 (06:07 +0000)
committerdongsheng <dongsheng>
Thu, 1 May 2008 06:07:24 +0000 (06:07 +0000)
lib/datalib.php
lib/db/mysql.php
lib/db/postgres7.php
lib/db/upgrade.php
lib/deprecatedlib.php
lib/statslib.php
lib/weblib.php
my/pagelib.php

index cd8260a13252f9c3ed38c59de7b0446e6217c5c0..4816efc7aa221f1d165baf9e65d2651cc22fdf83 100644 (file)
@@ -442,7 +442,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
         $sqland = "AND ";
     }
     if (!empty($USER->id)) {  // May need to check they are a teacher
-        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
             $visiblecourses = "$sqland ((c.visible > 0) OR t.userid = '$USER->id')";
             $teachertable = "LEFT JOIN {$CFG->prefix}user_teachers t ON t.course = c.id";
         }
@@ -543,7 +543,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
         $sqland = "AND ";
     }
     if (!empty($USER) and !empty($USER->id)) {  // May need to check they are a teacher
-        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
             $visiblecourses = "$sqland ((c.visible > 0) OR t.userid = '$USER->id')";
             $teachertable = "LEFT JOIN {$CFG->prefix}user_teachers t ON t.course=c.id";
         }
@@ -815,7 +815,7 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL
     global $CFG,$USER;
 
     // Guest's do not have any courses
-    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
     if (has_capability('moodle/legacy:guest',$sitecontext,$userid,false)) {
         return(array());
     }
@@ -2135,7 +2135,7 @@ function count_login_failures($mode, $username, $lastlogin) {
 
     $select = 'module=\'login\' AND action=\'error\' AND time > '. $lastlogin;
 
-    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {    // Return information about all accounts
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {    // Return information about all accounts
         if ($count->attempts = count_records_select('log', $select)) {
             $count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
             return $count;
@@ -2252,7 +2252,7 @@ function user_can_create_courses() {
     global $USER;
     // if user has course creation capability at any site or course cat, then return true;
 
-    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) {
         return true;
     } else {
         return (bool) count(get_creatable_categories());
index d7a39f9584f7c8db25e0c19049f7e2da28a79164..3e27b02c1aa3a4be528ac3f7ca3e3e5f3f092600 100644 (file)
@@ -2199,7 +2199,7 @@ function main_upgrade($oldversion=0) {
     if (!empty($CFG->rolesactive) and $oldversion < 2006091212) {   // Reload the guest roles completely with new defaults
         if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
             delete_records('capabilities');
-            $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $sitecontext = get_context_instance(CONTEXT_SYSTEM);
             foreach ($guestroles as $guestrole) {
                 delete_records('role_capabilities', 'roleid', $guestrole->id);
                 assign_capability('moodle/legacy:guest', CAP_ALLOW, $guestrole->id, $sitecontext->id);
index 8e1d6cf3a717c47da41896145edd4ff4d8f7fa51..3decbc2832784a0eba31d99871aa7839a73c4277 100644 (file)
@@ -1798,7 +1798,7 @@ function main_upgrade($oldversion=0) {
     if (!empty($CFG->rolesactive) and $oldversion < 2006091212) {   // Reload the guest roles completely with new defaults
         if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
             delete_records('capabilities');
-            $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $sitecontext = get_context_instance(CONTEXT_SYSTEM);
             foreach ($guestroles as $guestrole) {
                 delete_records('role_capabilities', 'roleid', $guestrole->id);
                 assign_capability('moodle/legacy:guest', CAP_ALLOW, $guestrole->id, $sitecontext->id);
index 9c7fad11494d860eeba26c3223ea14ca5de8979e..6487ea45adc6acf35f5ec938cdc9a2169030b29c 100644 (file)
@@ -881,7 +881,7 @@ function xmldb_main_upgrade($oldversion=0) {
 
         if( $defaultroleid != $userrole->id ) {
             //  Add in the new moodle/my:manageblocks capibility to the default user role
-            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $context = get_context_instance(CONTEXT_SYSTEM);
             assign_capability('moodle/my:manageblocks',CAP_ALLOW,$defaultroleid,$context->id);
         }
 
index 0d25719fc727fc2dd8304d6c2ad44bc7c86f07be..32d1048ec9b0d7c4bc9b8d32ae17675947a11dca 100644 (file)
@@ -119,7 +119,7 @@ function isadmin($userid=0) {
         return record_exists('user_admins', 'userid', $userid);
     }
 
-    $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+    $context = get_context_instance(CONTEXT_SYSTEM);
 
     return has_capability('moodle/legacy:admin', $context, $userid, false);
 }
@@ -145,7 +145,7 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
     if ($courseid) {
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
     } else {
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        $context = get_context_instance(CONTEXT_SYSTEM);
     }
 
     return (has_capability('moodle/legacy:teacher', $context, $userid, false)
@@ -199,7 +199,7 @@ function isteacherinanycourse($userid=0, $includeadmin=true) {
 
 /// Include admins if required
     if ($includeadmin) {
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        $context = get_context_instance(CONTEXT_SYSTEM);
         if (has_capability('moodle/legacy:admin', $context, $userid, false)) {
             return true;
         }
@@ -223,7 +223,7 @@ function isteacheredit($courseid, $userid=0, $obsolete_ignorestudentview=false)
     }
 
     if (empty($courseid)) {
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        $context = get_context_instance(CONTEXT_SYSTEM);
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
     }
@@ -245,7 +245,7 @@ function iscreator ($userid=0) {
         return false;
     }
 
-    $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+    $context = get_context_instance(CONTEXT_SYSTEM);
 
     return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
          or has_capability('moodle/legacy:admin', $context, $userid, false));
@@ -271,7 +271,7 @@ function isstudent($courseid=0, $userid=0) {
     }
 
     if ($courseid == 0) {
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        $context = get_context_instance(CONTEXT_SYSTEM);
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
     }
@@ -355,7 +355,7 @@ function unenrol_student($userid, $courseid=0) {
         }
         /// remove from all legacy student roles
         if ($courseid == SITEID) {
-            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $context = get_context_instance(CONTEXT_SYSTEM);
         } else if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
             return false;
         }
index 77b9695afd94237a9f4d306d154a96aa4abefe93..92b21fb194cba6dac841e7b54ad0e7fb5624c525 100644 (file)
@@ -1304,13 +1304,13 @@ function stats_get_report_options($courseid,$mode) {
     case STATS_MODE_DETAILED:
         $reportoptions[STATS_REPORT_USER_ACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ACTIVITY);
         $reportoptions[STATS_REPORT_USER_ALLACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ALLACTIVITY);
-        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM))) {
             $site = get_site();
             $reportoptions[STATS_REPORT_USER_LOGINS] = get_string('statsreport'.STATS_REPORT_USER_LOGINS);
         }
         break;
     case STATS_MODE_RANKED:
-        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM))) {
             $reportoptions[STATS_REPORT_ACTIVE_COURSES] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES);
             $reportoptions[STATS_REPORT_ACTIVE_COURSES_WEIGHTED] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES_WEIGHTED);
             $reportoptions[STATS_REPORT_PARTICIPATORY_COURSES] = get_string('statsreport'.STATS_REPORT_PARTICIPATORY_COURSES);
index c3b1a271e8984c6ca61951efd7215781e7f4f6db..75fc71ebe67838b760e04c1280b60c46d0780156 100644 (file)
@@ -2499,7 +2499,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
                     } else {
                         $menu .= get_string('failedloginattemptsall', '', $count);
                     }
-                    if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+                    if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM))) {
                         $menu .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php'.
                                              '?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
                     }
@@ -4802,7 +4802,7 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false, $
     $output = '';
 
     if (is_null($viewfullnames)) {
-        $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        $context = get_context_instance(CONTEXT_SYSTEM);
         $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
     }
 
@@ -5195,7 +5195,7 @@ function update_category_button($categoryid) {
 function update_categories_button() {
     global $CFG, $USER;
 
-    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM))) {
         if (!empty($USER->categoryediting)) {
             $string = get_string('turneditingoff');
             $categoryedit = 'off';
@@ -5221,7 +5221,7 @@ function update_categories_search_button($search,$page,$perpage) {
     global $CFG, $USER;
 
     // not sure if this capability is the best  here
-    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM))) {
         if (!empty($USER->categoryediting)) {
             $string = get_string("turneditingoff");
             $edit = "off";
index 1789ac0936c0b206f78795b28b8a2f7b6833b38f..3366ddc51da4b0963a7592b97e2ba2da09edfc44 100644 (file)
@@ -12,7 +12,7 @@ class page_my_moodle extends page_base {
         page_id_and_class($id,$class);
         if ($id == PAGE_MY_MOODLE) {
             return true;
-        } else if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
+        } else if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return false;
@@ -20,7 +20,7 @@ class page_my_moodle extends page_base {
 
     function user_is_editing() {
         global $USER;
-        if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
+        if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return (!empty($USER->editing));