Permalink
Browse files

MDL-34465 - lib - Replacing get_context_instance with context_XXXX::i…

…nstance (group 8)
  • Loading branch information...
1 parent 55a568f commit b0c6dc1cac89c36c5d7ef3b267b5928b81516fd2 @abgreeve abgreeve committed Jul 25, 2012
Showing with 180 additions and 180 deletions.
  1. +4 −4 lib/adminlib.php
  2. +1 −1 lib/ajax/getnavbranch.php
  3. +4 −4 lib/blocklib.php
  4. +13 −13 lib/datalib.php
  5. +5 −5 lib/deprecatedlib.php
  6. +1 −1 lib/editor/tinymce/lib.php
  7. +6 −6 lib/enrollib.php
  8. +1 −1 lib/externallib.php
  9. +1 −1 lib/filebrowser/file_browser.php
  10. +1 −1 lib/filebrowser/file_info_context_course.php
  11. +3 −3 lib/filebrowser/file_info_context_coursecat.php
  12. +2 −2 lib/filebrowser/file_info_context_system.php
  13. +10 −10 lib/filelib.php
  14. +6 −6 lib/filterlib.php
  15. +1 −1 lib/form/editor.php
  16. +1 −1 lib/form/filemanager.php
  17. +3 −3 lib/form/filepicker.php
  18. +1 −1 lib/form/tags.php
  19. +2 −2 lib/form/url.php
  20. +6 −6 lib/formslib.php
  21. +2 −2 lib/grade/grade_outcome.php
  22. +2 −2 lib/grade/grade_scale.php
  23. +4 −4 lib/gradelib.php
  24. +6 −6 lib/grouplib.php
  25. +1 −1 lib/messagelib.php
  26. +2 −2 lib/modinfolib.php
  27. +7 −7 lib/moodlelib.php
  28. +26 −26 lib/navigationlib.php
  29. +1 −1 lib/outputcomponents.php
  30. +4 −4 lib/outputrenderers.php
  31. +5 −5 lib/pagelib.php
  32. +1 −1 lib/portfoliolib.php
  33. +4 −4 lib/questionlib.php
  34. +2 −2 lib/resourcelib.php
  35. +4 −4 lib/statslib.php
  36. +4 −4 lib/tests/accesslib_test.php
  37. +10 −10 lib/tests/blocklib_test.php
  38. +1 −1 lib/tests/filter_test.php
  39. +1 −1 lib/tests/other/pdflibtestpage.php
  40. +1 −1 lib/tests/other/todochecker.php
  41. +8 −8 lib/tests/pagelib_test.php
  42. +1 −1 lib/tests/performance/filtersettingsperformancetester.php
  43. +1 −1 lib/uploadlib.php
  44. +7 −7 lib/weblib.php
  45. +1 −1 lib/xhprof/xhprof_html/callgraph.php
  46. +1 −1 lib/xhprof/xhprof_html/index.php
  47. +1 −1 lib/xhprof/xhprof_html/typeahead.php
View
@@ -526,7 +526,7 @@ function set_cron_lock($name, $until, $ignorecurrent=false) {
function admin_critical_warnings_present() {
global $SESSION;
- if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
+ if (!has_capability('moodle/site:config', context_system::instance())) {
return 0;
}
@@ -1164,7 +1164,7 @@ public function search($query) {
*/
public function check_access() {
global $CFG;
- $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
+ $context = empty($this->context) ? context_system::instance() : $this->context;
foreach($this->req_capability as $cap) {
if (has_capability($cap, $context)) {
return true;
@@ -1340,7 +1340,7 @@ public function add($setting) {
*/
public function check_access() {
global $CFG;
- $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
+ $context = empty($this->context) ? context_system::instance() : $this->context;
foreach($this->req_capability as $cap) {
if (has_capability($cap, $context)) {
return true;
@@ -2854,7 +2854,7 @@ function load_choices() {
if (is_array($this->choices)) {
return true;
}
- $users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM),
+ $users = get_users_by_capability(context_system::instance(),
$this->capability, 'u.id,u.username,u.firstname,u.lastname', 'u.lastname,u.firstname');
$this->choices = array(
'$@NONE@$' => get_string('nobody'),
@@ -42,7 +42,7 @@
// This identifies the block instance requesting AJAX extension
$instanceid = optional_param('instance', null, PARAM_INT);
- $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $PAGE->set_context(context_system::instance());
// Create a global nav object
$navigation = new global_navigation_for_ajax($PAGE, $branchtype, $branchid);
View
@@ -657,7 +657,7 @@ public function add_block($blockname, $region, $weight, $showinsubcontexts, $pag
$blockinstance->id = $DB->insert_record('block_instances', $blockinstance);
// Ensure the block context is created.
- get_context_instance(CONTEXT_BLOCK, $blockinstance->id);
+ context_block::instance($blockinstance->id);
// If the new instance was created, allow it to do additional setup
if ($block = block_instance($blockname, $blockinstance)) {
@@ -1230,8 +1230,8 @@ public function process_url_edit() {
$bi->subpagepattern = $data->bui_subpagepattern;
}
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
- $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
+ $systemcontext = context_system::instance();
+ $frontpagecontext = context_course::instance(SITEID);
$parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
// Updating stickiness and contexts. See MDL-21375 for details.
@@ -2102,7 +2102,7 @@ function blocks_add_default_system_blocks() {
global $DB;
$page = new moodle_page();
- $page->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $page->set_context(context_system::instance());
$page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('navigation', 'settings')), '*', null, true);
$page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2);
View
@@ -158,7 +158,7 @@ function search_users($courseid, $groupid, $searchtext, $sort='', array $excepti
return $DB->get_records_sql($sql, $params);
} else {
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$contextlists = get_related_contexts_string($context);
$sql = "SELECT u.id, u.firstname, u.lastname, u.email
@@ -412,7 +412,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
context_instance_preload($course);
if (isset($course->visible) && $course->visible <= 0) {
// for hidden courses, require visibility check
- if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
+ if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
$visiblecourses [$course->id] = $course;
}
} else {
@@ -479,7 +479,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
context_instance_preload($course);
if ($course->visible <= 0) {
// for hidden courses, require visibility check
- if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
+ if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
$totalcount++;
if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
$visiblecourses [$course->id] = $course;
@@ -596,7 +596,7 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
// managers efficiently later...
foreach ($courses as $k => $course) {
context_instance_preload($course);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$courses[$k] = $course;
$courses[$k]->managers = array();
if ($allcats === false) {
@@ -694,7 +694,7 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
}
} else {
foreach ($courses as $k => $course) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
// Note that strpos() returns 0 as "matched at pos 0"
if (strpos($coursecontext->path, $ra->path.'/') === 0) {
// Only add it to subpaths
@@ -806,7 +806,7 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $course) {
context_instance_preload($course);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// Don't exit this loop till the end
// we need to count all the visible courses
@@ -885,7 +885,7 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) {
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $cat) {
context_instance_preload($cat);
- $catcontext = get_context_instance(CONTEXT_COURSECAT, $cat->id);
+ $catcontext = context_coursecat::instance($cat->id);
if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
$categories[$cat->id] = $cat;
}
@@ -949,7 +949,7 @@ function get_course_category($catid=0) {
$cat->timemodified = time();
$catid = $DB->insert_record('course_categories', $cat);
// make sure category context exists
- get_context_instance(CONTEXT_COURSECAT, $catid);
+ context_coursecat::instance($catid);
mark_context_dirty('/'.SYSCONTEXTID);
fix_course_sortorder(); // Required to build course_categories.depth and .path.
$category = $DB->get_record('course_categories', array('id'=>$catid));
@@ -1032,7 +1032,7 @@ function fix_course_sortorder() {
$defaultcat = reset($topcats);
foreach ($frontcourses as $course) {
$DB->set_field('course', 'category', $defaultcat->id, array('id'=>$course->id));
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
$fixcontexts[$context->id] = $context;
}
unset($frontcourses);
@@ -1178,7 +1178,7 @@ function _fix_course_cats($children, &$sortorder, $parent, $depth, $path, &$fixc
$update = true;
// make sure context caches are rebuild and dirty contexts marked
- $context = get_context_instance(CONTEXT_COURSECAT, $cat->id);
+ $context = context_coursecat::instance($cat->id);
$fixcontexts[$context->id] = $context;
}
if ($cat->sortorder != $sortorder) {
@@ -1620,15 +1620,15 @@ function coursemodule_visible_for_user($cm, $userid=0) {
if (empty($userid)) {
$userid = $USER->id;
}
- if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id), $userid)) {
return false;
}
if ($CFG->enableavailability) {
require_once($CFG->libdir.'/conditionlib.php');
$ci=new condition_info($cm,CONDITION_MISSING_EXTRATABLE);
if(!$ci->is_available($cm->availableinfo,false,$userid) and
!has_capability('moodle/course:viewhiddenactivities',
- get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+ context_module::instance($cm->id), $userid)) {
return false;
}
}
@@ -2010,7 +2010,7 @@ function user_can_create_courses() {
global $DB;
$catsrs = $DB->get_recordset('course_categories');
foreach ($catsrs as $cat) {
- if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $cat->id))) {
+ if (has_capability('moodle/course:create', context_coursecat::instance($cat->id))) {
$catsrs->close();
return true;
}
View
@@ -75,7 +75,7 @@ function filter_text($text, $courseid = NULL) {
$courseid = $COURSE->id;
}
- if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
+ if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
return $text;
}
@@ -312,7 +312,7 @@ function get_teacher() {
* @return array of user
*/
function get_course_participants($courseid) {
- return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
+ return get_enrolled_users(context_course::instance($courseid));
}
/**
@@ -324,7 +324,7 @@ function get_course_participants($courseid) {
* @return boolean
*/
function is_course_participant($userid, $courseid) {
- return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
+ return is_enrolled(context_course::instance($courseid), $userid);
}
/**
@@ -341,7 +341,7 @@ function is_course_participant($userid, $courseid) {
function get_recent_enrolments($courseid, $timestart) {
global $DB;
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
FROM {user} u, {role_assignments} ra, {log} l
@@ -2601,7 +2601,7 @@ function update_module_button($cmid, $ignored, $string) {
//NOTE: DO NOT call new output method because it needs the module name we do not have here!
- if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
+ if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
$string = get_string('updatethis', '', $string);
$url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
@@ -92,7 +92,7 @@ protected function get_init_params($elementid, array $options=null) {
$lang = current_language();
$contentcss = $PAGE->theme->editor_css_url()->out(false);
- $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context'];
+ $context = empty($options['context']) ? context_system::instance() : $options['context'];
$config = get_config('editor_tinymce');
View
@@ -389,7 +389,7 @@ function enrol_course_updated($inserted, $course, $data) {
function enrol_add_course_navigation(navigation_node $coursenode, $course) {
global $CFG;
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$instances = enrol_get_instances($course->id, true);
$plugins = enrol_get_plugins(true);
@@ -604,7 +604,7 @@ function enrol_get_my_courses($fields = NULL, $sort = 'visible DESC,sortorder AS
foreach ($courses as $id=>$course) {
context_instance_preload($course);
if (!$course->visible) {
- if (!$context = get_context_instance(CONTEXT_COURSE, $id)) {
+ if (!$context = context_course::instance($id, IGNORE_MISSING)) {
unset($courses[$id]);
continue;
}
@@ -1018,7 +1018,7 @@ public function get_instance_name($instance) {
$enrol = $this->get_name();
return get_string('pluginname', 'enrol_'.$enrol);
} else {
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
+ $context = context_course::instance($instance->courseid);
return format_string($instance->name, true, array('context'=>$context));
}
}
@@ -1215,7 +1215,7 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
if ($instance->enrol !== $name) {
throw new coding_exception('invalid enrol instance!');
}
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
+ $context = context_course::instance($instance->courseid, MUST_EXIST);
$inserted = false;
$updated = false;
@@ -1352,7 +1352,7 @@ public function unenrol_user(stdClass $instance, $userid) {
if ($instance->enrol !== $name) {
throw new coding_exception('invalid enrol instance!');
}
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
+ $context = context_course::instance($instance->courseid, MUST_EXIST);
if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
// weird, user not enrolled
@@ -1484,7 +1484,7 @@ public function get_unenrolself_link($instance) {
return NULL;
}
- $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
+ $context = context_course::instance($instance->courseid, MUST_EXIST);
if (!has_capability("enrol/$name:unenrolself", $context)) {
return NULL;
View
@@ -328,7 +328,7 @@ protected static function validate_context($context) {
throw new invalid_parameter_exception('Context does not exist');
}
if (empty(self::$contextrestriction)) {
- self::$contextrestriction = get_context_instance(CONTEXT_SYSTEM);
+ self::$contextrestriction = context_system::instance();
}
$rcontext = self::$contextrestriction;
@@ -73,7 +73,7 @@ class file_browser {
*/
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
if (!$context) {
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
}
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
@@ -383,7 +383,7 @@ public function get_children() {
if (empty($cminfo->uservisible)) {
continue;
}
- $modcontext = get_context_instance(CONTEXT_MODULE, $cminfo->id);
+ $modcontext = context_module::instance($cminfo->id, IGNORE_MISSING);
if ($child = $this->browser->get_file_info($modcontext)) {
$children[] = $child;
}
@@ -65,7 +65,7 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
if (empty($component)) {
// we can not list the category contents, so try parent, or top system
if ($this->category->parent and $pc = $DB->get_record('course_categories', array('id'=>$this->category->parent))) {
- $parent = get_context_instance(CONTEXT_COURSECAT, $pc->id);
+ $parent = context_coursecat::instance($pc->id, IGNORE_MISSING);
return $this->browser->get_file_info($parent);
} else {
return $this->browser->get_file_info();
@@ -165,7 +165,7 @@ public function get_children() {
$course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder', 'id,visible');
foreach ($course_cats as $category) {
- $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $context = context_coursecat::instance($category->id);
if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) {
continue;
}
@@ -176,7 +176,7 @@ public function get_children() {
$courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder', 'id,visible');
foreach ($courses as $course) {
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
continue;
}
@@ -101,7 +101,7 @@ public function get_children() {
$course_cats = $DB->get_records('course_categories', array('parent'=>0), 'sortorder', 'id,visible');
foreach ($course_cats as $category) {
- $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $context = context_coursecat::instance($category->id);
if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) {
continue;
}
@@ -115,7 +115,7 @@ public function get_children() {
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
continue;
}
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
if ($child = $this->browser->get_file_info($context)) {
$children[] = $child;
}
Oops, something went wrong.

0 comments on commit b0c6dc1

Please sign in to comment.