MDL-34549 libraries: Replace get_context_instance_by_id() by context::instance_by_id()
authorAnkit Agarwal <ankit@moodle.com>
Tue, 21 Aug 2012 06:20:30 +0000 (14:20 +0800)
committerAnkit Agarwal <ankit@moodle.com>
Fri, 24 Aug 2012 03:30:10 +0000 (11:30 +0800)
61 files changed:
admin/roles/lib.php
admin/user/user_bulk_cohortadd.php
blocks/community/block_community.php
blocks/edit_form.php
blocks/html/block_html.php
blocks/html/lib.php
blocks/quiz_results/block_quiz_results.php
cohort/assign.php
cohort/edit.php
cohort/edit_form.php
cohort/index.php
comment/lib.php
comment/locallib.php
draftfile.php
enrol/category/locallib.php
enrol/cohort/addinstance_form.php
enrol/cohort/lib.php
enrol/cohort/locallib.php
enrol/externallib.php
files/externallib.php
files/renderer.php
grade/grading/lib.php
grade/grading/manage.php
lib/blocklib.php
lib/externallib.php
lib/filebrowser/file_info_context_course.php
lib/filebrowser/file_info_context_coursecat.php
lib/filebrowser/file_info_context_module.php
lib/questionlib.php
lib/setuplib.php
lib/tests/accesslib_test.php
lib/weblib.php
mod/data/lib.php
mod/forum/lib.php
mod/glossary/lib.php
mod/quiz/edit.php
mod/quiz/editlib.php
mod/wiki/edit_form.php
question/addquestion.php
question/category.php
question/category_class.php
question/editlib.php
question/engine/questionusage.php
question/format.php
question/import.php
question/preview.php
question/question.php
question/type/calculated/datasetdefinitions_form.php
question/type/calculated/datasetitems_form.php
question/type/edit_question_form.php
question/type/questiontypebase.php
report/security/locallib.php
repository/coursefiles/lib.php
repository/draftfiles_ajax.php
repository/lib.php
repository/local/lib.php
repository/manage_instances.php
repository/recent/lib.php
repository/repository_ajax.php
user/index.php
webservice/lib.php

index 43eb7f5..df537f0 100644 (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));
         }
 
index 1e32564..be72d51 100644 (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;
     }
index 35e3f2e..c211342 100644 (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) {
index 9380fa2..169c54d 100644 (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));
index 39040ae..6ca71b3 100644 (file)
@@ -104,7 +104,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)) {
             return false;
         }
         //find out if this block is on the profile page
index a2555c3..93fdbb8 100644 (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)) {
         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
index d18af55..8795a68 100644 (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;
         }
index b7f6589..5eaa2a7 100644 (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);
 
index dc1bd08..721d790 100644 (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');
     }
index 9576071..81e7a7c 100644 (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;
index 026bcb8..00aab66 100644 (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();
 }
index 9bf2653..8954244 100644 (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');
         }
index 5a8b0d7..25f907f 100644 (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);
         if (!$this->context) {
             return false;
         }
index ede5706..821ae57 100644 (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();
 }
index 2c16f76..9e4ab0c 100644 (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;
         }
index e9015a2..c209493 100644 (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;
             }
index b70b89f..4ad304e 100644 (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;
             }
index 5ca237a..869e06c 100644 (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;
         }
index 0fd4182..e669ca7 100644 (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']);
             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']);
             self::validate_context($context);
             require_capability('moodle/role:assign', $context);
 
index f6001d2..4d8e3ae 100644 (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();
         }
index cfa14e0..6a648b0 100644 (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;
index c6e8186..0a3de68 100644 (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;
     }
index 954f91f..c5d90ad 100644 (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);
 }
 
index 79ec70d..76ff728 100644 (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
index f547850..0c6e44d 100644 (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;
     }
index 05b3489..d1e703b 100644 (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);
         return $this->browser->get_file_info($parent);
     }
 }
index 1cded83..47636e6 100644 (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);
         return $this->browser->get_file_info($parent);
     }
 }
index 0357ee3..363f6a0 100644 (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);
         return $this->browser->get_file_info($parent);
     }
 }
index 149f351..fbfab99 100644 (file)
@@ -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)) {
index 51f8d82..16b2aa3 100644 (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);
index 52d700f..b8535fd 100644 (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), $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) {
index 1295b00..b3d7339 100644 (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']) {
index fa660c0..0cc49b3 100644 (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;
     }
index 405bc95..b36bcd6 100644 (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.
index 1ddcc56..ab8657a 100644 (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),
index ef5e633..1fce2b4 100644 (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"';
index 44f00d6..987a39b 100644 (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
index 9992dde..2d34a6c 100644 (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');
         }
index fa262cd..02e6224 100644 (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.
index 5ad3de9..b208a46 100644 (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()){
index fd65dba..79339f2 100644 (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);
         }
 
index f28b9c2..bb4633f 100644 (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);
     } else {
         $context = $contextorid;
     }
index e4de197..d6fbae8 100644 (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);
 
index e1cc7db..bf9daca 100644 (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;
 
index 20b6c9a..7110e53 100644 (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.
index 2938762..b8a83ed 100644 (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.
 }
index 63f54ad..47a6893 100644 (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');
             }
index 23a15f3..45efea3 100644 (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);
     }
 
index 3ff9750..aa2156a 100644 (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(
index 7428254..9a2ebeb 100644 (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);
     }
index 50bbe76..22226da 100644 (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);
         return $context;
     }
 
index 6573629..f6021fd 100644 (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&amp;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&amp;roleid=$user->roleid";
             $a = (object)array('fullname'=>fullname($user), 'url'=>$url, 'email'=>$user->email,
                                'contextname'=>print_context_name($context));
index c25be53..ba4891a 100644 (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();
index a3ea3aa..43ff97d 100644 (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');
index e8a60f4..1a51e8e 100644 (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']);
                 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();
index a4c511d..37d214a 100644 (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;
index a6b1363..43efe2e 100644 (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) {
index f1265c8..76cdb69 100644 (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) {
index d9f3cea..f19738b 100644 (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){
index b30a10b..73fe0ee 100644 (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');
         }
index 66ed91f..31e78b9 100644 (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);