diff --git a/calendar/delete.php b/calendar/delete.php index 9ca53742f19..4f72df71f05 100644 --- a/calendar/delete.php +++ b/calendar/delete.php @@ -55,7 +55,7 @@ if ($event->eventtype !== 'user' && $event->eventtype !== 'site') { $course = $DB->get_record('course', array('id'=>$courseid)); require_login($course); if (!$course) { - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong + $PAGE->set_context(context_system::instance()); //TODO: wrong } // Check the user has the required capabilities to edit an event diff --git a/calendar/export_execute.php b/calendar/export_execute.php index 229868237da..f4cb51cf410 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -162,7 +162,7 @@ foreach($events as $event) { $ev->add_property('dtend', Bennu::timestamp_to_datetime($event->timestart + $event->timeduration)); } if ($event->courseid != 0) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $event->courseid); + $coursecontext = context_course::instance($event->courseid); $ev->add_property('categories', format_string($courses[$event->courseid]->shortname, true, array('context' => $coursecontext))); } $ical->add_component($ev); diff --git a/calendar/lib.php b/calendar/lib.php index 6cff2a30108..dcb5e8a987a 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -580,7 +580,7 @@ function calendar_add_event_metadata($event) { } $icon = $OUTPUT->pix_url('icon', $event->modulename) . ''; - $context = get_context_instance(CONTEXT_COURSE, $module->course); + $context = context_course::instance($module->course); $fullname = format_string($coursecache[$module->course]->fullname, true, array('context' => $context)); $event->icon = ''.$eventtype.''; @@ -595,7 +595,7 @@ function calendar_add_event_metadata($event) { } else if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event calendar_get_course_cached($coursecache, $event->courseid); - $context = get_context_instance(CONTEXT_COURSE, $event->courseid); + $context = context_course::instance($event->courseid); $fullname = format_string($coursecache[$event->courseid]->fullname, true, array('context' => $context)); $event->icon = ''.get_string('courseevent', 'calendar').''; @@ -1374,7 +1374,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) { if (count($courseeventsfrom)==1) { $course = reset($courseeventsfrom); - if (has_any_capability($allgroupscaps, get_context_instance(CONTEXT_COURSE, $course->id))) { + if (has_any_capability($allgroupscaps, context_course::instance($course->id))) { $coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id'); $group = array_keys($coursegroups); } @@ -1430,7 +1430,7 @@ function calendar_edit_event_allowed($event) { return false; } - $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $sitecontext = context_system::instance(); // if user has manageentries at site level, return true if (has_capability('moodle/calendar:manageentries', $sitecontext)) { return true; @@ -1698,14 +1698,14 @@ function calendar_get_allowed_types(&$allowed, $course = null) { $allowed->user = has_capability('moodle/calendar:manageownentries', get_system_context()); $allowed->groups = false; // This may change just below $allowed->courses = false; // This may change just below - $allowed->site = has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, SITEID)); + $allowed->site = has_capability('moodle/calendar:manageentries', context_course::instance(SITEID)); if (!empty($course)) { if (!is_object($course)) { $course = $DB->get_record('course', array('id' => $course), '*', MUST_EXIST); } if ($course->id != SITEID) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $allowed->user = has_capability('moodle/calendar:manageownentries', $coursecontext); if (has_capability('moodle/calendar:manageentries', $coursecontext)) { @@ -1752,7 +1752,7 @@ function calendar_add_event_allowed($event) { return false; } - $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $sitecontext = context_system::instance(); // if user has manageentries at site level, always return true if (has_capability('moodle/calendar:manageentries', $sitecontext)) { return true; @@ -1953,20 +1953,20 @@ class calendar_event { $context = null; if (isset($data->courseid) && $data->courseid > 0) { - $context = get_context_instance(CONTEXT_COURSE, $data->courseid); + $context = context_course::instance($data->courseid); } else if (isset($data->course) && $data->course > 0) { - $context = get_context_instance(CONTEXT_COURSE, $data->course); + $context = context_course::instance($data->course); } else if (isset($data->groupid) && $data->groupid > 0) { $group = $DB->get_record('groups', array('id'=>$data->groupid)); - $context = get_context_instance(CONTEXT_COURSE, $group->courseid); + $context = context_course::instance($group->courseid); } else if (isset($data->userid) && $data->userid > 0 && $data->userid == $USER->id) { - $context = get_context_instance(CONTEXT_USER, $data->userid); + $context = context_user::instance($data->userid); } else if (isset($data->userid) && $data->userid > 0 && $data->userid != $USER->id && isset($data->instance) && $data->instance > 0) { $cm = get_coursemodule_from_instance($data->modulename, $data->instance, 0, false, MUST_EXIST); - $context = get_context_instance(CONTEXT_COURSE, $cm->course); + $context = context_course::instance($cm->course); } else { - $context = get_context_instance(CONTEXT_USER); + $context = context_user::instance(); } return $context; diff --git a/calendar/renderer.php b/calendar/renderer.php index a2f8a7b9a90..60e3a743174 100644 --- a/calendar/renderer.php +++ b/calendar/renderer.php @@ -687,7 +687,7 @@ class core_calendar_renderer extends plugin_renderer_base { return ''; } - if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) { + if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) { $courses = get_courses('all', 'c.shortname','c.id,c.shortname'); } else { $courses = enrol_get_my_courses(); @@ -698,7 +698,7 @@ class core_calendar_renderer extends plugin_renderer_base { $courseoptions = array(); $courseoptions[SITEID] = get_string('fulllistofcourses'); foreach ($courses as $course) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); } diff --git a/calendar/set.php b/calendar/set.php index c02069e07d7..255027e5610 100644 --- a/calendar/set.php +++ b/calendar/set.php @@ -53,7 +53,7 @@ if ($courseid != -1) { } $url = new moodle_url('/calendar/set.php', array('return'=>base64_encode($return->out(false)), 'course' => $courseid, 'var'=>$var, 'sesskey'=>sesskey())); $PAGE->set_url($url); -$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); switch($var) { case 'showgroups': diff --git a/cohort/edit_form.php b/cohort/edit_form.php index a030ce20232..fe3ce492461 100644 --- a/cohort/edit_form.php +++ b/cohort/edit_form.php @@ -93,12 +93,12 @@ class cohort_edit_form extends moodleform { $parentlist = array(); make_categories_list($displaylist, $parentlist, 'moodle/cohort:manage'); $options = array(); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); if (has_capability('moodle/cohort:manage', $syscontext)) { $options[$syscontext->id] = print_context_name($syscontext); } foreach ($displaylist as $cid=>$name) { - $context = get_context_instance(CONTEXT_COURSECAT, $cid, MUST_EXIST); + $context = context_coursecat::instance($cid, MUST_EXIST); $options[$context->id] = $name; } // always add current - this is not likely, but if the logic gets changed it might be a problem diff --git a/cohort/index.php b/cohort/index.php index 9c18bb72f01..026bcb855e9 100644 --- a/cohort/index.php +++ b/cohort/index.php @@ -37,7 +37,7 @@ require_login(); if ($contextid) { $context = get_context_instance_by_id($contextid, MUST_EXIST); } else { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); } if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) { diff --git a/cohort/lib.php b/cohort/lib.php index 367b19ec9de..ce512729766 100644 --- a/cohort/lib.php +++ b/cohort/lib.php @@ -110,14 +110,14 @@ function cohort_delete_category($category) { global $DB; // TODO: make sure that cohorts are really, really not used anywhere and delete, for now just move to parent or system context - $oldcontext = get_context_instance(CONTEXT_COURSECAT, $category->id, MUST_EXIST); + $oldcontext = context_coursecat::instance($category->id, MUST_EXIST); if ($category->parent and $parent = $DB->get_record('course_categories', array('id'=>$category->parent))) { - $parentcontext = get_context_instance(CONTEXT_COURSECAT, $parent->id, MUST_EXIST); + $parentcontext = context_coursecat::instance($parent->id, MUST_EXIST); $sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext"; $params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$parentcontext->id); } else { - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext"; $params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$syscontext->id); } @@ -165,7 +165,7 @@ function cohort_remove_member($cohortid, $userid) { function cohort_get_visible_list($course) { global $DB, $USER; - $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); + $context = context_course::instance($course->id, MUST_EXIST); list($esql, $params) = get_enrolled_sql($context); $parentsql = get_related_contexts_string($context); diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php index 67b715cc9ab..e133df159b6 100644 --- a/filter/algebra/algebradebug.php +++ b/filter/algebra/algebradebug.php @@ -15,7 +15,7 @@ require_once($CFG->dirroot.'/filter/tex/lib.php'); require_login(); - require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/site:config', context_system::instance()); $query = urldecode($_SERVER['QUERY_STRING']); diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php index 54ffaff5185..9ba698a55c9 100644 --- a/filter/algebra/filter.php +++ b/filter/algebra/filter.php @@ -73,7 +73,7 @@ function filter_algebra_image($imagefile, $tex= "", $height="", $width="", $alig } $anchorcontents .= "\" $style />"; - if (!file_exists("$CFG->dataroot/filter/algebra/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (!file_exists("$CFG->dataroot/filter/algebra/$imagefile") && has_capability('moodle/site:config', context_system::instance())) { $link = '/filter/algebra/algebradebug.php'; $action = null; } else { diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 0b62fc1e189..0999df263a4 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -92,7 +92,7 @@ function filter_text_image($imagefile, $tex, $height, $width, $align, $alt) { } $anchorcontents .= "\" $style/>"; - if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', context_system::instance())) { $link = '/filter/tex/texdebug.php'; $action = null; } else { diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php index b4a08dee34c..32004492a24 100644 --- a/filter/tex/texdebug.php +++ b/filter/tex/texdebug.php @@ -40,7 +40,7 @@ $texexp = optional_param('tex', '', PARAM_RAW); require_login(); - require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $USER->id); /// Required cap to run this. MDL-18552 + require_capability('moodle/site:config', context_system::instance(), $USER->id); /// Required cap to run this. MDL-18552 $output = '';