Merge branch 'MDL-34549-master' of git://github.com/ankitagarwal/moodle

This commit is contained in:
Aparup Banerjee 2012-08-28 11:45:11 +08:00
commit 9455f48280
61 changed files with 92 additions and 92 deletions

View File

@ -933,7 +933,7 @@ class override_permissions_table_advanced extends capability_table_with_risks {
global $DB;
/// Get the capabilities from the parent context, so that can be shown in the interface.
$parentcontext = get_context_instance_by_id(get_parent_contextid($this->context));
$parentcontext = context::instance_by_id(get_parent_contextid($this->context));
$this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext);
}
@ -996,7 +996,7 @@ abstract class role_assign_user_selector_base extends user_selector_base {
if (isset($options['context'])) {
$this->context = $options['context'];
} else {
$this->context = get_context_instance_by_id($options['contextid']);
$this->context = context::instance_by_id($options['contextid']);
}
$options['accesscontext'] = $this->context;
parent::__construct($name, $options);
@ -1230,7 +1230,7 @@ class existing_role_holders extends role_assign_user_selector_base {
}
protected function parent_con_group_name($search, $contextid) {
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
$contextname = print_context_name($context, true, true);
if ($search) {
$a = new stdClass;
@ -1477,7 +1477,7 @@ class role_allow_switch_page extends role_allow_role_page {
function roles_get_potential_user_selector($context, $name, $options) {
$blockinsidecourse = false;
if ($context->contextlevel == CONTEXT_BLOCK) {
$parentcontext = get_context_instance_by_id(get_parent_contextid($context));
$parentcontext = context::instance_by_id(get_parent_contextid($context));
$blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
}

View File

@ -45,7 +45,7 @@ foreach ($allcohorts as $c) {
// external cohorts can not be modified
continue;
}
$context = get_context_instance_by_id($c->contextid);
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:assign', $context)) {
continue;
}

View File

@ -43,7 +43,7 @@ class block_community extends block_list {
function user_can_edit() {
// Don't allow people to edit the block if they can't even use it
if (!has_capability('moodle/community:add',
get_context_instance_by_id($this->instance->parentcontextid))) {
context::instance_by_id($this->instance->parentcontextid))) {
return false;
}
return parent::user_can_edit();
@ -52,7 +52,7 @@ class block_community extends block_list {
function get_content() {
global $CFG, $OUTPUT, $USER;
$coursecontext = get_context_instance_by_id($this->instance->parentcontextid);
$coursecontext = context::instance_by_id($this->instance->parentcontextid);
if (!has_capability('moodle/community:add', $coursecontext)
or $this->content !== NULL) {

View File

@ -87,7 +87,7 @@ class block_edit_form extends moodleform {
$regionoptions = $this->page->theme->get_all_block_regions();
$parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
$parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));

View File

@ -108,7 +108,7 @@ class block_html extends block_base {
function content_is_trusted() {
global $SCRIPT;
if (!$context = get_context_instance_by_id($this->instance->parentcontextid)) {
if (!$context = context::instance_by_id($this->instance->parentcontextid, IGNORE_MISSING)) {
return false;
}
//find out if this block is on the profile page

View File

@ -53,7 +53,7 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a
send_file_not_found();
}
if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
if ($parentcontext->contextlevel == CONTEXT_USER) {
// force download on all personal pages including /my/
//because we do not have reliable way to find out from where this is used

View File

@ -65,7 +65,7 @@ class block_quiz_results extends block_base {
if (empty($this->instance->parentcontextid)) {
return 0;
}
$parentcontext = get_context_instance_by_id($this->instance->parentcontextid);
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return 0;
}

View File

@ -32,7 +32,7 @@ $id = required_param('id', PARAM_INT);
require_login();
$cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
require_capability('moodle/cohort:assign', $context);

View File

@ -40,9 +40,9 @@ require_login();
$category = null;
if ($id) {
$cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
} else {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
print_error('invalidcontext');
}

View File

@ -103,7 +103,7 @@ class cohort_edit_form extends moodleform {
}
// always add current - this is not likely, but if the logic gets changed it might be a problem
if (!isset($options[$currentcontextid])) {
$context = get_context_instance_by_id($currentcontextid, MUST_EXIST);
$context = context::instance_by_id($currentcontextid, MUST_EXIST);
$options[$context->id] = print_context_name($syscontext);
}
return $options;

View File

@ -35,7 +35,7 @@ $searchquery = optional_param('search', '', PARAM_RAW);
require_login();
if ($contextid) {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
} else {
$context = context_system::instance();
}

View File

@ -120,7 +120,7 @@ class comment {
$this->contextid = $this->context->id;
} else if(!empty($options->contextid)) {
$this->contextid = $options->contextid;
$this->context = get_context_instance_by_id($this->contextid);
$this->context = context::instance_by_id($this->contextid);
} else {
print_error('invalidcontext');
}

View File

@ -114,7 +114,7 @@ class comment_manager {
*/
private function setup_plugin($comment) {
global $DB;
$this->context = get_context_instance_by_id($comment->contextid);
$this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING);
if (!$this->context) {
return false;
}

View File

@ -61,7 +61,7 @@ if ($component !== 'user' or $filearea !== 'draft') {
send_file_not_found();
}
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
if ($context->contextlevel != CONTEXT_USER) {
send_file_not_found();
}

View File

@ -45,8 +45,8 @@ class enrol_category_handler {
return true;
}
// Only category level roles are interesting.
$parentcontext = get_context_instance_by_id($ra->contextid);
//only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return true;
}
@ -102,8 +102,8 @@ class enrol_category_handler {
return true;
}
// Only category level roles are interesting.
$parentcontext = get_context_instance_by_id($ra->contextid);
// only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return true;
}

View File

@ -46,7 +46,7 @@ class enrol_cohort_addinstance_form extends moodleform {
ORDER BY name ASC";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $c) {
$context = get_context_instance_by_id($c->contextid);
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}

View File

@ -92,7 +92,7 @@ class enrol_cohort_plugin extends enrol_plugin {
ORDER BY name ASC";
$cohorts = $DB->get_records_sql($sql, $params);
foreach ($cohorts as $c) {
$context = get_context_instance_by_id($c->contextid);
$context = context::instance_by_id($c->contextid);
if (has_capability('moodle/cohort:view', $context)) {
return true;
}

View File

@ -368,7 +368,7 @@ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
ORDER BY name ASC";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $c) {
$context = get_context_instance_by_id($c->contextid);
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}
@ -394,7 +394,7 @@ function enrol_cohort_can_view_cohort($cohortid) {
global $DB;
$cohort = $DB->get_record('cohort', array('id' => $cohortid), 'id, contextid');
if ($cohort) {
$context = get_context_instance_by_id($cohort->contextid);
$context = context::instance_by_id($cohort->contextid);
if (has_capability('moodle/cohort:view', $context)) {
return true;
}
@ -457,7 +457,7 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset
// Track offset
$offset++;
// Check capabilities
$context = get_context_instance_by_id($c->contextid);
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}

View File

@ -381,7 +381,7 @@ class core_role_external extends external_api {
foreach ($params['assignments'] as $assignment) {
// Ensure the current user is allowed to run this function in the enrolment context
$context = get_context_instance_by_id($assignment['contextid']);
$context = context::instance_by_id($assignment['contextid'], IGNORE_MISSING);
self::validate_context($context);
require_capability('moodle/role:assign', $context);
@ -445,7 +445,7 @@ class core_role_external extends external_api {
foreach ($params['unassignments'] as $unassignment) {
// Ensure the current user is allowed to run this function in the unassignment context
$context = get_context_instance_by_id($unassignment['contextid']);
$context = context::instance_by_id($unassignment['contextid'], IGNORE_MISSING);
self::validate_context($context);
require_capability('moodle/role:assign', $context);

View File

@ -82,7 +82,7 @@ class core_files_external extends external_api {
if (empty($fileinfo['contextid'])) {
$context = get_system_context();
} else {
$context = get_context_instance_by_id($fileinfo['contextid']);
$context = context::instance_by_id($fileinfo['contextid']);
}
if (empty($fileinfo['component'])) {
$fileinfo['component'] = null;
@ -272,7 +272,7 @@ class core_files_external extends external_api {
}
if (!empty($fileinfo['contextid'])) {
$context = get_context_instance_by_id($fileinfo['contextid']);
$context = context::instance_by_id($fileinfo['contextid']);
} else {
$context = get_system_context();
}

View File

@ -965,7 +965,7 @@ class files_tree_viewer implements renderable {
$this->path = array();
while ($level) {
$params = $level->get_params();
$context = get_context_instance_by_id($params['contextid']);
$context = context::instance_by_id($params['contextid']);
// $this->context is current context
if ($context->id != $this->context->id or empty($params['filearea'])) {
break;

View File

@ -223,7 +223,7 @@ class grading_manager {
global $DB;
$this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST);
$this->context = get_context_instance_by_id($this->areacache->contextid, MUST_EXIST);
$this->context = context::instance_by_id($this->areacache->contextid, MUST_EXIST);
$this->component = $this->areacache->component;
$this->area = $this->areacache->areaname;
}

View File

@ -57,7 +57,7 @@ if (!is_null($areaid)) {
if (is_null($contextid) or is_null($component) or is_null($area)) {
throw new coding_exception('The caller script must identify the gradable area.');
}
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
$manager = get_grading_manager($context, $component, $area);
}

View File

@ -1238,7 +1238,7 @@ class block_manager {
$systemcontext = context_system::instance();
$frontpagecontext = context_course::instance(SITEID);
$parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
$parentcontext = context::instance_by_id($data->bui_parentcontextid);
// Updating stickiness and contexts. See MDL-21375 for details.
if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination

View File

@ -520,7 +520,7 @@ function external_generate_token($tokentype, $serviceorid, $userid, $contextorid
$service = $serviceorid;
}
if (!is_object($contextorid)){
$context = get_context_instance_by_id($contextorid, MUST_EXIST);
$context = context::instance_by_id($contextorid, MUST_EXIST);
} else {
$context = $contextorid;
}

View File

@ -401,7 +401,7 @@ class file_info_context_course extends file_info {
public function get_parent() {
//TODO: error checking if get_parent_contextid() returns false
$pcid = get_parent_contextid($this->context);
$parent = get_context_instance_by_id($pcid);
$parent = context::instance_by_id($pcid, IGNORE_MISSING);
return $this->browser->get_file_info($parent);
}
}

View File

@ -195,7 +195,7 @@ class file_info_context_coursecat extends file_info {
*/
public function get_parent() {
$cid = get_parent_contextid($this->context);
$parent = get_context_instance_by_id($cid);
$parent = context::instance_by_id($cid, IGNORE_MISSING);
return $this->browser->get_file_info($parent);
}
}

View File

@ -283,7 +283,7 @@ class file_info_context_module extends file_info {
*/
public function get_parent() {
$pcid = get_parent_contextid($this->context);
$parent = get_context_instance_by_id($pcid);
$parent = context::instance_by_id($pcid, IGNORE_MISSING);
return $this->browser->get_file_info($parent);
}
}

View File

@ -1119,7 +1119,7 @@ function question_category_options($contexts, $top = false, $currentcat = 0,
$categoriesarray = array();
foreach ($pcontexts as $pcontext) {
$contextstring = print_context_name(
get_context_instance_by_id($pcontext), true, true);
context::instance_by_id($pcontext), true, true);
foreach ($categories as $category) {
if ($category->contextid == $pcontext) {
$cid = $category->id;
@ -1346,7 +1346,7 @@ function question_has_capability_on($question, $cap, $cachecat = -1) {
}
}
$category = $categories[$question->category];
$context = get_context_instance_by_id($category->contextid);
$context = context::instance_by_id($category->contextid);
if (array_search($cap, $question_questioncaps)!== false) {
if (!has_capability('moodle/question:' . $cap . 'all', $context)) {

View File

@ -206,7 +206,7 @@ class required_capability_exception extends moodle_exception {
$capabilityname = get_capability_string($capability);
if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) {
// we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead
$paranetcontext = get_context_instance_by_id(get_parent_contextid($context));
$paranetcontext = context::instance_by_id(get_parent_contextid($context));
$link = get_context_url($paranetcontext);
} else {
$link = get_context_url($context);

View File

@ -2271,7 +2271,7 @@ class accesslib_testcase extends advanced_testcase {
foreach ($DB->get_records('context') as $contextid=>$record) {
$context = context::instance_by_id($contextid);
$this->assertSame(get_context_instance_by_id($contextid), $context);
$this->assertSame(context::instance_by_id($contextid, IGNORE_MISSING), $context);
$this->assertSame(get_context_instance($record->contextlevel, $record->instanceid), $context);
$this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids());
if ($context->id == SYSCONTEXTID) {

View File

@ -1072,7 +1072,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_
if (is_object($options['context'])) {
$context = $options['context'];
} else {
$context = get_context_instance_by_id($options['context']);
$context = context::instance_by_id($options['context']);
}
} else if ($courseid_do_not_use) {
// legacy courseid
@ -1281,7 +1281,7 @@ function format_string($string, $striplinks = true, $options = NULL) {
// fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
$options['context'] = $PAGE->context;
} else if (is_numeric($options['context'])) {
$options['context'] = get_context_instance_by_id($options['context']);
$options['context'] = context::instance_by_id($options['context']);
}
if (!$options['context']) {

View File

@ -1325,7 +1325,7 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
* @return array an associative array of the user's rating permissions
*/
function data_rating_permissions($contextid, $component, $ratingarea) {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($component != 'mod_data' || $ratingarea != 'entry') {
return null;
}

View File

@ -3527,7 +3527,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
* @return array an associative array of the user's rating permissions
*/
function forum_rating_permissions($contextid, $component, $ratingarea) {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($component != 'mod_forum' || $ratingarea != 'post') {
// We don't know about this component/ratingarea so just return null to get the
// default restrictive permissions.

View File

@ -637,7 +637,7 @@ function glossary_rating_permissions($contextid, $component, $ratingarea) {
// default restrictive permissions.
return null;
}
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
return array(
'view' => has_capability('mod/glossary:viewrating', $context),
'viewany' => has_capability('mod/glossary:viewanyrating', $context),

View File

@ -73,7 +73,7 @@ function module_specific_buttons($cmid, $cmoptions) {
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
global $OUTPUT;
$out = '';
$catcontext = get_context_instance_by_id($category->contextid);
$catcontext = context::instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
if ($cmoptions->hasattempts) {
$disabled = ' disabled="disabled"';

View File

@ -183,7 +183,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
print_error('invalidcategoryid', 'error');
}
$catcontext = get_context_instance_by_id($category->contextid);
$catcontext = context::instance_by_id($category->contextid);
require_capability('moodle/question:useall', $catcontext);
// Find existing random questions in this category that are

View File

@ -59,7 +59,7 @@ class mod_wiki_edit_form extends moodleform {
if (isset($this->_customdata['pagetitle'])) {
// Page title must be formatted properly here as this is output and not an element.
$pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => get_context_instance_by_id($contextid, MUST_EXIST))));
$pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => context::instance_by_id($contextid, MUST_EXIST))));
} else {
$pagetitle = get_string('editing', 'wiki');
}

View File

@ -60,7 +60,7 @@ if ($cmid) {
}
// Check permissions.
$categorycontext = get_context_instance_by_id($category->contextid);
$categorycontext = context::instance_by_id($category->contextid);
require_capability('moodle/question:add', $categorycontext);
// Ensure other optional params get passed on to question.php.

View File

@ -71,7 +71,7 @@ if ($param->delete && ($questionstomove = $DB->count_records("question", array("
if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security
print_error('nocate', 'question', $thispageurl->out(), $param->delete);
}
$categorycontext = get_context_instance_by_id($category->contextid);
$categorycontext = context::instance_by_id($category->contextid);
$qcobject->moveform = new question_move_form($thispageurl,
array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
if ($qcobject->moveform->is_cancelled()){

View File

@ -246,7 +246,7 @@ class question_category_object {
$listhtml = $list->to_html(0, array('str'=>$this->str));
if ($listhtml){
echo $OUTPUT->box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel' . $list->context->contextlevel);
echo $OUTPUT->heading(get_string('questioncatsfor', 'question', print_context_name(get_context_instance_by_id($context))), 3);
echo $OUTPUT->heading(get_string('questioncatsfor', 'question', print_context_name(context::instance_by_id($context))), 3);
echo $listhtml;
echo $OUTPUT->box_end();
}
@ -374,7 +374,7 @@ class question_category_object {
}
list($parentid, $contextid) = explode(',', $newparent);
//moodle_form makes sure select element output is legal no need for further cleaning
require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid));
require_capability('moodle/question:managecategory', context::instance_by_id($contextid));
if ($parentid) {
if(!($DB->get_field('question_categories', 'contextid', array('id' => $parentid)) == $contextid)) {
@ -418,12 +418,12 @@ class question_category_object {
}
// Check permissions.
$fromcontext = get_context_instance_by_id($oldcat->contextid);
$fromcontext = context::instance_by_id($oldcat->contextid);
require_capability('moodle/question:managecategory', $fromcontext);
// If moving to another context, check permissions some more.
if ($oldcat->contextid != $tocontextid) {
$tocontext = get_context_instance_by_id($tocontextid);
$tocontext = context::instance_by_id($tocontextid);
require_capability('moodle/question:managecategory', $tocontext);
}

View File

@ -117,7 +117,7 @@ function question_can_delete_cat($todelete) {
print_error('cannotdeletecate', 'question');
} else {
$contextid = $DB->get_field('question_categories', 'contextid', array('id' => $todelete));
require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid));
require_capability('moodle/question:managecategory', context::instance_by_id($contextid));
}
}
@ -1323,7 +1323,7 @@ class question_bank_view {
$strdelete = get_string('delete');
list($categoryid, $contextid) = explode(',', $categoryandcontext);
$catcontext = get_context_instance_by_id($contextid);
$catcontext = context::instance_by_id($contextid);
$canadd = has_capability('moodle/question:add', $catcontext);
$caneditall =has_capability('moodle/question:editall', $catcontext);
@ -1467,7 +1467,7 @@ class question_bank_view {
if (! $tocategory = $DB->get_record('question_categories', array('id' => $tocategoryid, 'contextid' => $contextid))) {
print_error('cannotfindcate', 'question');
}
$tocontext = get_context_instance_by_id($contextid);
$tocontext = context::instance_by_id($contextid);
require_capability('moodle/question:add', $tocontext);
$rawdata = (array) data_submitted();
$questionids = array();
@ -1717,7 +1717,7 @@ function question_get_display_preference($param, $default, $type, $thispageurl)
function require_login_in_context($contextorid = null){
global $DB, $CFG;
if (!is_object($contextorid)){
$context = get_context_instance_by_id($contextorid);
$context = context::instance_by_id($contextorid, IGNORE_MISSING);
} else {
$context = $contextorid;
}

View File

@ -708,7 +708,7 @@ class question_usage_by_activity {
}
$quba = new question_usage_by_activity($record->component,
get_context_instance_by_id($record->contextid));
context::instance_by_id($record->contextid));
$quba->set_id_from_database($record->qubaid);
$quba->set_preferred_behaviour($record->preferredbehaviour);

View File

@ -128,7 +128,7 @@ class qformat_default {
debugging('You shouldn\'t call setCategory after setQuestions');
}
$this->category = $category;
$this->importcontext = get_context_instance_by_id($this->category->contextid);
$this->importcontext = context::instance_by_id($this->category->contextid);
}
/**
@ -500,10 +500,10 @@ class qformat_default {
}
if ($this->contextfromfile && $contextid !== false) {
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
require_capability('moodle/question:add', $context);
} else {
$context = get_context_instance_by_id($this->category->contextid);
$context = context::instance_by_id($this->category->contextid);
}
$this->importcontext = $context;

View File

@ -42,7 +42,7 @@ if (!$category = $DB->get_record("question_categories", array('id' => $catid)))
print_error('nocategory', 'question');
}
$categorycontext = get_context_instance_by_id($category->contextid);
$categorycontext = context::instance_by_id($category->contextid);
$category->context = $categorycontext;
//this page can be called without courseid or cmid in which case
//we get the context from the category object.

View File

@ -60,7 +60,7 @@ if ($cmid = optional_param('cmid', 0, PARAM_INT)) {
require_login();
$category = $DB->get_record('question_categories',
array('id' => $question->category), '*', MUST_EXIST);
$context = get_context_instance_by_id($category->contextid);
$context = context::instance_by_id($category->contextid);
$PAGE->set_context($context);
// Note that in the other cases, require_login will set the correct page context.
}

View File

@ -154,7 +154,7 @@ if (!$category = $DB->get_record('question_categories', array('id' => $question-
// Check permissions
$question->formoptions = new stdClass();
$categorycontext = get_context_instance_by_id($category->contextid);
$categorycontext = context::instance_by_id($category->contextid);
$addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) {
@ -259,7 +259,7 @@ if ($mform->is_cancelled()) {
if ($movecontext) {
// We are just moving the question to a different context.
list($tocatid, $tocontextid) = explode(',', $fromform->categorymoveto);
require_capability('moodle/question:add', get_context_instance_by_id($tocontextid));
require_capability('moodle/question:add', context::instance_by_id($tocontextid));
question_move_questions_to_category(array($question->id), $tocatid);
} else {
@ -267,7 +267,7 @@ if ($mform->is_cancelled()) {
if (!empty($question->id)) {
question_require_capability_on($question, 'edit');
} else {
require_capability('moodle/question:add', get_context_instance_by_id($newcontextid));
require_capability('moodle/question:add', context::instance_by_id($newcontextid));
if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
print_error('nopermissions', '', '', 'edit');
}

View File

@ -65,7 +65,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form {
print_error('categorydoesnotexist', 'question', $returnurl);
}
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
$this->categorycontext = context::instance_by_id($category->contextid);
parent::__construct($submiturl);
}

View File

@ -79,7 +79,7 @@ class question_dataset_dependent_items_form extends question_wizard_form {
print_error('categorydoesnotexist', 'question', $returnurl);
}
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
$this->categorycontext = context::instance_by_id($category->contextid);
//get the dataset defintions for this question
if (empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions(

View File

@ -101,14 +101,14 @@ abstract class question_edit_form extends question_wizard_form {
$record = $DB->get_record('question_categories',
array('id' => $question->category), 'contextid');
$this->context = get_context_instance_by_id($record->contextid);
$this->context = context::instance_by_id($record->contextid);
$this->editoroptions = array('subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES,
'context' => $this->context);
$this->fileoptions = array('subdirs' => 1, 'maxfiles' => -1, 'maxbytes' => -1);
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
$this->categorycontext = context::instance_by_id($category->contextid);
parent::__construct($submiturl, null, 'post', '', null, $formeditable);
}

View File

@ -1023,7 +1023,7 @@ class question_type {
protected function get_context_by_category_id($category) {
global $DB;
$contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category));
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid, IGNORE_MISSING);
return $context;
}

View File

@ -850,7 +850,7 @@ function report_security_check_riskbackup($detailed=false) {
$links = array();
foreach ($overriddenroles as $role) {
$role->name = $role->localname;
$context = get_context_instance_by_id($role->contextid);
$context = context::instance_by_id($role->contextid);
$role->name = role_get_name($role, $context, ROLENAME_BOTH);
$role->contextname = print_context_name($context);
$role->url = "$CFG->wwwroot/$CFG->admin/roles/override.php?contextid=$role->contextid&roleid=$role->id";
@ -867,7 +867,7 @@ function report_security_check_riskbackup($detailed=false) {
$sqluserinfo ORDER BY u.lastname, u.firstname", $params);
foreach ($rs as $user) {
$context = get_context_instance_by_id($user->contextid);
$context = context::instance_by_id($user->contextid);
$url = "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=$user->contextid&roleid=$user->roleid";
$a = (object)array('fullname'=>fullname($user), 'url'=>$url, 'email'=>$user->email,
'contextname'=>print_context_name($context));

View File

@ -67,7 +67,7 @@ class repository_coursefiles extends repository {
if (is_array($params)) {
$filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);;
$filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE);
$context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT));
$context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT));
}
} else {
$filename = null;
@ -158,7 +158,7 @@ class repository_coursefiles extends repository {
$filepath = clean_param($params['filepath'], PARAM_PATH);;
$filearea = clean_param($params['filearea'], PARAM_AREA);
$component = clean_param($params['component'], PARAM_COMPONENT);
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
return $file_info->get_url();

View File

@ -309,7 +309,7 @@ switch ($action) {
if (isset($source->original)) {
$reffiles = $fs->search_references($source->original);
foreach ($reffiles as $reffile) {
$refcontext = get_context_instance_by_id($reffile->get_contextid());
$refcontext = context::instance_by_id($reffile->get_contextid());
$fileinfo = $browser->get_file_info($refcontext, $reffile->get_component(), $reffile->get_filearea(), $reffile->get_itemid(), $reffile->get_filepath(), $reffile->get_filename());
if (empty($fileinfo)) {
$return['references'][] = get_string('undisclosedreference', 'repository');

View File

@ -496,7 +496,7 @@ abstract class repository {
if (is_object($context)) {
$this->context = $context;
} else {
$this->context = get_context_instance_by_id($context);
$this->context = context::instance_by_id($context);
}
$this->instance = $DB->get_record('repository_instances', array('id'=>$this->id));
$this->readonly = $readonly;
@ -1175,7 +1175,7 @@ abstract class repository {
$fileinfo = null;
$params = file_storage::unpack_reference($reference, true);
if (is_array($params)) {
$context = get_context_instance_by_id($params['contextid']);
$context = context::instance_by_id($params['contextid'], IGNORE_MISSING);
if ($context) {
$browser = get_file_browser();
$fileinfo = $browser->get_file_info($context, $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']);
@ -1622,7 +1622,7 @@ abstract class repository {
$filepath = clean_param($params['filepath'], PARAM_PATH);
$filearea = clean_param($params['filearea'], PARAM_AREA);
$component = clean_param($params['component'], PARAM_COMPONENT);
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
if (!empty($file_info)) {
$filesize = $file_info->get_filesize();

View File

@ -63,7 +63,7 @@ class repository_local extends repository {
$itemid = is_null($params['itemid']) ? NULL : clean_param($params['itemid'], PARAM_INT);
$filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);;
$filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE);
$context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT));
$context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT));
}
} else {
$itemid = null;

View File

@ -65,7 +65,7 @@ if ($usercourseid != SITEID) {
$url->param('usercourseid', $usercourseid);
}
$context = get_context_instance_by_id($contextid);
$context = context::instance_by_id($contextid);
$PAGE->set_url($url);
$PAGE->set_context($context);
@ -177,7 +177,7 @@ if (!empty($edit) || !empty($new)) {
}
$success = $instance->set_option($settings);
} else {
$success = repository::static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
$success = repository::static_function($plugin, 'create', $plugin, 0, context::instance_by_id($contextid), $fromform);
$data = data_submitted();
}
if ($success) {

View File

@ -122,7 +122,7 @@ class repository_recent extends repository {
foreach ($files as $file) {
// Check that file exists and accessible, retrieve size/date info
$browser = get_file_browser();
$context = get_context_instance_by_id($file['contextid']);
$context = context::instance_by_id($file['contextid']);
$fileinfo = $browser->get_file_info($context, $file['component'],
$file['filearea'], $file['itemid'], $file['filepath'], $file['filename']);
if ($fileinfo) {

View File

@ -94,8 +94,8 @@ switch ($action) {
// global search
case 'gsearch':
$params = array();
$params['context'] = array(get_context_instance_by_id($contextid), get_system_context());
$params['currentcontext'] = get_context_instance_by_id($contextid);
$params['context'] = array(context::instance_by_id($contextid), get_system_context());
$params['currentcontext'] = context::instance_by_id($contextid);
$repos = repository::get_instances($params);
$list = array();
foreach($repos as $repo){

View File

@ -34,7 +34,7 @@
'id' => $courseid));
if ($contextid) {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSE) {
print_error('invalidcontext');
}

View File

@ -949,7 +949,7 @@ abstract class webservice_server implements webservice_server_interface {
. ' is not supported - check this allowed user');
}
$this->restricted_context = get_context_instance_by_id($token->contextid);
$this->restricted_context = context::instance_by_id($token->contextid);
$this->restricted_serviceid = $token->externalserviceid;
$user = $DB->get_record('user', array('id'=>$token->userid), '*', MUST_EXIST);