mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 15:49:43 +02:00
"MDL-14460, fix get_context_instance, merged from MOODLE_19_STABLE"
This commit is contained in:
parent
2cb5f03a66
commit
12d0687748
8 changed files with 23 additions and 23 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&id=1&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";
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue