"MDL-14460, fix all get_context_instance"
This commit is contained in:
+5
-5
@@ -441,7 +441,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";
|
||||
}
|
||||
@@ -542,7 +542,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";
|
||||
}
|
||||
@@ -814,7 +814,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());
|
||||
}
|
||||
@@ -2134,7 +2134,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;
|
||||
@@ -2251,7 +2251,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());
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+4
-4
@@ -2489,7 +2489,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&id=1&modid=site_errors">'.get_string('logs').'</a>)';
|
||||
}
|
||||
@@ -4776,7 +4776,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);
|
||||
}
|
||||
|
||||
@@ -5169,7 +5169,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';
|
||||
@@ -5195,7 +5195,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";
|
||||
|
||||
+2
-2
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user