Permalink
Browse files

MDL-34549 libraries: Replace get_context_instance_by_id() by context:…

…:instance_by_id()
  • Loading branch information...
1 parent d71c486 commit d197ea4300083cfa6c4f09613f9fb1f98ce2e69a @ankitagarwal ankitagarwal committed Aug 21, 2012
Showing with 92 additions and 92 deletions.
  1. +4 −4 admin/roles/lib.php
  2. +1 −1 admin/user/user_bulk_cohortadd.php
  3. +2 −2 blocks/community/block_community.php
  4. +1 −1 blocks/edit_form.php
  5. +1 −1 blocks/html/block_html.php
  6. +1 −1 blocks/html/lib.php
  7. +1 −1 blocks/quiz_results/block_quiz_results.php
  8. +1 −1 cohort/assign.php
  9. +2 −2 cohort/edit.php
  10. +1 −1 cohort/edit_form.php
  11. +1 −1 cohort/index.php
  12. +1 −1 comment/lib.php
  13. +1 −1 comment/locallib.php
  14. +1 −1 draftfile.php
  15. +4 −4 enrol/category/locallib.php
  16. +1 −1 enrol/cohort/addinstance_form.php
  17. +1 −1 enrol/cohort/lib.php
  18. +3 −3 enrol/cohort/locallib.php
  19. +2 −2 enrol/externallib.php
  20. +2 −2 files/externallib.php
  21. +1 −1 files/renderer.php
  22. +1 −1 grade/grading/lib.php
  23. +1 −1 grade/grading/manage.php
  24. +1 −1 lib/blocklib.php
  25. +1 −1 lib/externallib.php
  26. +1 −1 lib/filebrowser/file_info_context_course.php
  27. +1 −1 lib/filebrowser/file_info_context_coursecat.php
  28. +1 −1 lib/filebrowser/file_info_context_module.php
  29. +2 −2 lib/questionlib.php
  30. +1 −1 lib/setuplib.php
  31. +1 −1 lib/tests/accesslib_test.php
  32. +2 −2 lib/weblib.php
  33. +1 −1 mod/data/lib.php
  34. +1 −1 mod/forum/lib.php
  35. +1 −1 mod/glossary/lib.php
  36. +1 −1 mod/quiz/edit.php
  37. +1 −1 mod/quiz/editlib.php
  38. +1 −1 mod/wiki/edit_form.php
  39. +1 −1 question/addquestion.php
  40. +1 −1 question/category.php
  41. +4 −4 question/category_class.php
  42. +4 −4 question/editlib.php
  43. +1 −1 question/engine/questionusage.php
  44. +3 −3 question/format.php
  45. +1 −1 question/import.php
  46. +1 −1 question/preview.php
  47. +3 −3 question/question.php
  48. +1 −1 question/type/calculated/datasetdefinitions_form.php
  49. +1 −1 question/type/calculated/datasetitems_form.php
  50. +2 −2 question/type/edit_question_form.php
  51. +1 −1 question/type/questiontypebase.php
  52. +2 −2 report/security/locallib.php
  53. +2 −2 repository/coursefiles/lib.php
  54. +1 −1 repository/draftfiles_ajax.php
  55. +3 −3 repository/lib.php
  56. +1 −1 repository/local/lib.php
  57. +2 −2 repository/manage_instances.php
  58. +1 −1 repository/recent/lib.php
  59. +2 −2 repository/repository_ajax.php
  60. +1 −1 user/index.php
  61. +1 −1 webservice/lib.php
View
@@ -933,7 +933,7 @@ protected function load_parent_permissions() {
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 @@ public function __construct($name, $options) {
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 @@ protected function this_con_group_name($search, $numusers) {
}
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 @@ public function get_intro_text() {
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));
}
@@ -45,7 +45,7 @@
// 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;
}
@@ -43,7 +43,7 @@ function user_can_addto($page) {
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 @@ function user_can_edit() {
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
@@ -87,7 +87,7 @@ function definition() {
$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));
@@ -104,7 +104,7 @@ function instance_delete() {
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)) {
return false;
}
//find out if this block is on the profile page
View
@@ -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)) {
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
@@ -65,7 +65,7 @@ public function get_owning_quiz() {
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
@@ -32,7 +32,7 @@
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
@@ -40,9 +40,9 @@
$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
@@ -103,7 +103,7 @@ protected function get_category_options($currentcontextid) {
}
// 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
@@ -35,7 +35,7 @@
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
@@ -120,7 +120,7 @@ public function __construct(stdClass $options) {
$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
@@ -114,7 +114,7 @@ private function setup_course($courseid) {
*/
private function setup_plugin($comment) {
global $DB;
- $this->context = get_context_instance_by_id($comment->contextid);
+ $this->context = context::instance_by_id($comment->contextid);
if (!$this->context) {
return false;
}
View
@@ -61,7 +61,7 @@
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();
}
@@ -45,8 +45,8 @@ public static function role_assigned($ra) {
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 @@ public static function role_unassigned($ra) {
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;
}
@@ -46,7 +46,7 @@ function definition() {
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
@@ -92,7 +92,7 @@ protected function can_add_new_instances($courseid) {
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;
}
@@ -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
@@ -381,7 +381,7 @@ public static function assign_roles($assignments) {
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']);
self::validate_context($context);
require_capability('moodle/role:assign', $context);
@@ -445,7 +445,7 @@ public static function unassign_roles($unassignments) {
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']);
self::validate_context($context);
require_capability('moodle/role:assign', $context);
View
@@ -82,7 +82,7 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
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 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
}
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
@@ -965,7 +965,7 @@ public function __construct(file_info $file_info, array $options = null) {
$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
@@ -223,7 +223,7 @@ public function load($areaid) {
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
@@ -57,7 +57,7 @@
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
@@ -1238,7 +1238,7 @@ public function process_url_edit() {
$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
@@ -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;
}
@@ -401,7 +401,7 @@ public function get_children() {
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);
return $this->browser->get_file_info($parent);
}
}
@@ -195,7 +195,7 @@ public function get_children() {
*/
public function get_parent() {
$cid = get_parent_contextid($this->context);
- $parent = get_context_instance_by_id($cid);
+ $parent = context::instance_by_id($cid);
return $this->browser->get_file_info($parent);
}
}
@@ -283,7 +283,7 @@ public function get_children() {
*/
public function get_parent() {
$pcid = get_parent_contextid($this->context);
- $parent = get_context_instance_by_id($pcid);
+ $parent = context::instance_by_id($pcid);
return $this->browser->get_file_info($parent);
}
}
View
@@ -1106,7 +1106,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;
@@ -1333,7 +1333,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
@@ -206,7 +206,7 @@ function __construct($context, $capability, $errormessage, $stringfile) {
$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);
@@ -2271,7 +2271,7 @@ public function test_permission_evaluation() {
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), $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
@@ -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']) {
Oops, something went wrong.

0 comments on commit d197ea4

Please sign in to comment.