Skip to content

Commit

Permalink
"MDL-14460, fix get_context_instance, merged from MOODLE_19_STABLE"
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsheng committed May 1, 2008
1 parent 2cb5f03 commit 12d0687
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lib/db/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/db/postgres7.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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));
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/statslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>)';
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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';
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions my/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ function user_allowed_editing() {
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;
}

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));
Expand Down

0 comments on commit 12d0687

Please sign in to comment.