mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-34465 - lib - Replacing get_context_instance with context_XXXX::instance (group 8)
This commit is contained in:
parent
55a568fa7d
commit
b0c6dc1cac
@ -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 @@ class admin_externalpage implements part_of_admin_tree {
|
||||
*/
|
||||
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 @@ class admin_settingpage implements part_of_admin_tree {
|
||||
*/
|
||||
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 @@ class admin_setting_users_with_capability extends admin_setting_configmultiselec
|
||||
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 @@ try {
|
||||
// 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);
|
||||
|
@ -657,7 +657,7 @@ class block_manager {
|
||||
$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 @@ class block_manager {
|
||||
$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);
|
||||
|
||||
|
@ -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,7 +1620,7 @@ 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) {
|
||||
@ -1628,7 +1628,7 @@ function coursemodule_visible_for_user($cm, $userid=0) {
|
||||
$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;
|
||||
}
|
||||
|
@ -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 @@ class tinymce_texteditor extends texteditor {
|
||||
$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');
|
||||
|
||||
|
@ -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 @@ abstract class enrol_plugin {
|
||||
$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 @@ abstract class enrol_plugin {
|
||||
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 @@ abstract class enrol_plugin {
|
||||
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 @@ abstract class enrol_plugin {
|
||||
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;
|
||||
|
@ -328,7 +328,7 @@ class external_api {
|
||||
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 @@ class file_info_context_course extends file_info {
|
||||
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 @@ class file_info_context_coursecat extends file_info {
|
||||
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 @@ class file_info_context_coursecat extends file_info {
|
||||
|
||||
$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 @@ class file_info_context_coursecat extends file_info {
|
||||
|
||||
$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 @@ class file_info_context_system extends file_info {
|
||||
|
||||
$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 @@ class file_info_context_system extends file_info {
|
||||
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;
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ function file_get_unused_draft_itemid() {
|
||||
print_error('noguest');
|
||||
}
|
||||
|
||||
$contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
|
||||
$contextid = context_user::instance($USER->id)->id;
|
||||
|
||||
$fs = get_file_storage();
|
||||
$draftitemid = rand(1, 999999999);
|
||||
@ -357,7 +357,7 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare
|
||||
$options['forcehttps'] = false;
|
||||
}
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (empty($draftitemid)) {
|
||||
@ -465,7 +465,7 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
|
||||
function file_get_draft_area_info($draftitemid) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$results = array();
|
||||
@ -490,7 +490,7 @@ function file_get_draft_area_info($draftitemid) {
|
||||
function file_get_user_used_space() {
|
||||
global $DB, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$sql = "SELECT SUM(files1.filesize) AS totalbytes FROM {files} files1
|
||||
JOIN (SELECT contenthash, filename, MAX(id) AS id
|
||||
FROM {files}
|
||||
@ -526,7 +526,7 @@ function file_correct_filepath($str) { //TODO: what is this? (skodak)
|
||||
function file_get_drafarea_folders($draftitemid, $filepath, &$data) {
|
||||
global $USER, $OUTPUT, $CFG;
|
||||
$data->children = array();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) {
|
||||
foreach ($files as $file) {
|
||||
@ -558,7 +558,7 @@ function file_get_drafarea_folders($draftitemid, $filepath, &$data) {
|
||||
function file_get_drafarea_files($draftitemid, $filepath = '/') {
|
||||
global $USER, $OUTPUT, $CFG;
|
||||
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$data = new stdClass();
|
||||
@ -711,7 +711,7 @@ function file_restore_source_field_from_draft_file($storedfile) {
|
||||
function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
|
||||
global $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$options = (array)$options;
|
||||
@ -905,7 +905,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
|
||||
function file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps = false) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
|
||||
$wwwroot = $CFG->wwwroot;
|
||||
if ($forcehttps) {
|
||||
@ -3763,7 +3763,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
|
||||
|
||||
while (!$canview && count($courses) > 0) {
|
||||
$course = array_shift($courses);
|
||||
if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if (has_capability('moodle/user:viewdetails', context_course::instance($course->id))) {
|
||||
$canview = true;
|
||||
}
|
||||
}
|
||||
@ -3780,7 +3780,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
|
||||
|
||||
} else if ($filearea === 'profile' and $context->contextlevel == CONTEXT_COURSE) {
|
||||
$userid = (int)array_shift($args);
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $userid);
|
||||
$usercontext = context_user::instance($userid);
|
||||
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
|
@ -605,7 +605,7 @@ function filter_set_global_state($filter, $state, $sortorder = false) {
|
||||
}
|
||||
|
||||
// See if there is an existing record.
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
$rec = $DB->get_record('filter_active', array('filter' => $filter, 'contextid' => $syscontext->id));
|
||||
if (empty($rec)) {
|
||||
$insert = true;
|
||||
@ -747,7 +747,7 @@ function filter_set_local_state($filter, $contextid, $state) {
|
||||
"Must be one of TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_INHERIT.");
|
||||
}
|
||||
|
||||
if ($contextid == get_context_instance(CONTEXT_SYSTEM)->id) {
|
||||
if ($contextid == context_system::instance()->id) {
|
||||
throw new coding_exception('You cannot use filter_set_local_state ' .
|
||||
'with $contextid equal to the system context id.');
|
||||
}
|
||||
@ -847,7 +847,7 @@ function filter_get_local_config($filter, $contextid) {
|
||||
*/
|
||||
function filter_get_all_local_settings($contextid) {
|
||||
global $DB;
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
return array(
|
||||
$DB->get_records('filter_active', array('contextid' => $contextid), 'filter', 'filter,active'),
|
||||
$DB->get_records('filter_config', array('contextid' => $contextid), 'filter,name', 'filter,name,value'),
|
||||
@ -940,13 +940,13 @@ function filter_preload_activities(course_modinfo $modinfo) {
|
||||
$cmcontexts = array();
|
||||
$cmcontextids = array();
|
||||
foreach ($modinfo->get_cms() as $cm) {
|
||||
$modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$modulecontext = context_module::instance($cm->id);
|
||||
$cmcontextids[] = $modulecontext->id;
|
||||
$cmcontexts[] = $modulecontext;
|
||||
}
|
||||
|
||||
// Get course context and all other parents...
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $modinfo->get_course_id());
|
||||
$coursecontext = context_course::instance($modinfo->get_course_id());
|
||||
$parentcontextids = explode('/', substr($coursecontext->path, 1));
|
||||
$allcontextids = array_merge($cmcontextids, $parentcontextids);
|
||||
|
||||
@ -1094,7 +1094,7 @@ function filter_get_available_in_context($context) {
|
||||
*/
|
||||
function filter_get_global_states() {
|
||||
global $DB;
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
return $DB->get_records('filter_active', array('contextid' => $context->id), 'sortorder', 'filter,active,sortorder');
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
|
||||
}
|
||||
if (!$this->_options['context']) {
|
||||
$this->_options['context'] = get_context_instance(CONTEXT_SYSTEM);
|
||||
$this->_options['context'] = context_system::instance();
|
||||
}
|
||||
$this->_options['trusted'] = trusttext_trusted($this->_options['context']);
|
||||
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
|
@ -321,7 +321,7 @@ class form_filemanager implements renderable {
|
||||
$this->options = file_get_drafarea_files($options->itemid, '/');
|
||||
|
||||
// calculate file count
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
|
||||
$filecount = count($files);
|
||||
$this->options->filecount = $filecount;
|
||||
|
@ -126,9 +126,9 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
}
|
||||
|
||||
if ($COURSE->id == SITEID) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
$context = context_course::instance($COURSE->id);
|
||||
}
|
||||
|
||||
$client_id = uniqid();
|
||||
@ -191,7 +191,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
// make sure max one file is present and it is not too big
|
||||
if (!is_null($draftitemid)) {
|
||||
$fs = get_file_storage();
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) {
|
||||
$file = array_shift($files);
|
||||
if ($this->_options['maxbytes']
|
||||
|
@ -130,7 +130,7 @@ class MoodleQuickForm_tags extends MoodleQuickForm_group {
|
||||
|
||||
// If the user can manage official tags, give them a link to manage them.
|
||||
$label = get_string('otags', 'tag');
|
||||
if (has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('moodle/tag:manage', context_system::instance())) {
|
||||
$url = $CFG->wwwroot .'/tag/manage.php';
|
||||
$label .= ' (' . $OUTPUT->action_link(
|
||||
$url,
|
||||
|
@ -97,9 +97,9 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
$strsaved = get_string('filesaved', 'repository');
|
||||
$straddlink = get_string('choosealink', 'repository');
|
||||
if ($COURSE->id == SITEID) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
$context = context_course::instance($COURSE->id);
|
||||
}
|
||||
$client_id = uniqid();
|
||||
|
||||
|
@ -395,7 +395,7 @@ abstract class moodleform {
|
||||
if ($rule['type'] == 'required') {
|
||||
$draftid = (int)$mform->getSubmitValue($elementname);
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
$errors[$elementname] = $rule['message'];
|
||||
}
|
||||
@ -673,7 +673,7 @@ abstract class moodleform {
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
@ -721,7 +721,7 @@ abstract class moodleform {
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
@ -784,7 +784,7 @@ abstract class moodleform {
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return null;
|
||||
}
|
||||
@ -828,7 +828,7 @@ abstract class moodleform {
|
||||
return false;
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
@ -890,7 +890,7 @@ abstract class moodleform {
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class grade_outcome extends grade_object {
|
||||
$DB->delete_records('grade_outcomes_courses', array('outcomeid' => $this->id, 'courseid' => $this->courseid));
|
||||
}
|
||||
if (parent::delete($source)) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'grade', 'outcome', $this->id);
|
||||
foreach ($files as $file) {
|
||||
@ -299,7 +299,7 @@ class grade_outcome extends grade_object {
|
||||
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'outcome', $this->id);
|
||||
return format_text($description, $this->descriptionformat, $options);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class grade_scale extends grade_object {
|
||||
public function delete($source=null) {
|
||||
global $DB;
|
||||
if (parent::delete($source)) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id);
|
||||
foreach ($files as $file) {
|
||||
@ -337,7 +337,7 @@ class grade_scale extends grade_object {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $this->id);
|
||||
|
@ -758,7 +758,7 @@ function grade_format_gradevalue_percentage($value, $grade_item, $decimals, $loc
|
||||
* @return string
|
||||
*/
|
||||
function grade_format_gradevalue_letter($value, $grade_item) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid);
|
||||
$context = context_course::instance($grade_item->courseid, IGNORE_MISSING);
|
||||
if (!$letters = grade_get_letters($context)) {
|
||||
return ''; // no letters??
|
||||
}
|
||||
@ -939,7 +939,7 @@ function grade_recover_history_grades($userid, $courseid) {
|
||||
//Check the user is enrolled in this course
|
||||
//Dont bother checking if they have a gradeable role. They may get one later so recover
|
||||
//whatever grades they have now just in case.
|
||||
$course_context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$course_context = context_course::instance($courseid);
|
||||
if (!is_enrolled($course_context, $userid)) {
|
||||
debugging('Attempting to recover the grades of a user who is deleted or not enrolled. Skipping recover.');
|
||||
return false;
|
||||
@ -1228,7 +1228,7 @@ function remove_course_grades($courseid, $showfeedback) {
|
||||
|
||||
$course_category = grade_category::fetch_course_category($courseid);
|
||||
$course_category->delete('coursedelete');
|
||||
$fs->delete_area_files(get_context_instance(CONTEXT_COURSE, $courseid)->id, 'grade', 'feedback');
|
||||
$fs->delete_area_files(context_course::instance($courseid)->id, 'grade', 'feedback');
|
||||
if ($showfeedback) {
|
||||
echo $OUTPUT->notification($strdeleted.' - '.get_string('grades', 'grades').', '.get_string('items', 'grades').', '.get_string('categories', 'grades'), 'notifysuccess');
|
||||
}
|
||||
@ -1269,7 +1269,7 @@ function remove_course_grades($courseid, $showfeedback) {
|
||||
function grade_course_category_delete($categoryid, $newparentid, $showfeedback) {
|
||||
global $DB;
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $categoryid);
|
||||
$context = context_coursecat::instance($categoryid);
|
||||
$DB->delete_records('grade_letters', array('contextid'=>$context->id));
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ function groups_print_course_menu($course, $urlroot, $return=false) {
|
||||
}
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
$aag = has_capability('moodle/site:accessallgroups', $context);
|
||||
|
||||
if ($groupmode == VISIBLEGROUPS or $aag) {
|
||||
@ -548,7 +548,7 @@ function groups_print_activity_menu($cm, $urlroot, $return=false, $hideallpartic
|
||||
}
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
$aag = has_capability('moodle/site:accessallgroups', $context);
|
||||
|
||||
if ($groupmode == VISIBLEGROUPS or $aag) {
|
||||
@ -617,7 +617,7 @@ function groups_get_course_group($course, $update=false, $allowedgroups=null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
if (has_capability('moodle/site:accessallgroups', $context)) {
|
||||
$groupmode = 'aag';
|
||||
}
|
||||
@ -669,7 +669,7 @@ function groups_get_activity_group($cm, $update=false, $allowedgroups=null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
if (has_capability('moodle/site:accessallgroups', $context)) {
|
||||
$groupmode = 'aag';
|
||||
}
|
||||
@ -725,7 +725,7 @@ function groups_get_activity_allowed_groups($cm,$userid=0) {
|
||||
|
||||
// If visible groups mode, or user has the accessallgroups capability,
|
||||
// then they can access all groups for the activity...
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) {
|
||||
return groups_get_all_groups($cm->course, 0, $cm->groupingid);
|
||||
} else {
|
||||
@ -756,7 +756,7 @@ function groups_course_module_visible($cm, $userid=null) {
|
||||
if (empty($cm->groupmembersonly)) {
|
||||
return true;
|
||||
}
|
||||
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid) or groups_has_membership($cm, $userid)) {
|
||||
if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id), $userid) or groups_has_membership($cm, $userid)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -388,7 +388,7 @@ function message_get_my_providers() {
|
||||
function message_get_providers_for_user($userid) {
|
||||
global $DB, $CFG;
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
|
||||
$providers = get_message_providers();
|
||||
|
||||
|
@ -973,7 +973,7 @@ class cm_info extends stdClass {
|
||||
$this->icon = isset($mod->icon) ? $mod->icon : '';
|
||||
$this->iconcomponent = isset($mod->iconcomponent) ? $mod->iconcomponent : '';
|
||||
$this->customdata = isset($mod->customdata) ? $mod->customdata : '';
|
||||
$this->context = get_context_instance(CONTEXT_MODULE, $mod->cm);
|
||||
$this->context = context_module::instance($mod->cm);
|
||||
$this->showdescription = isset($mod->showdescription) ? $mod->showdescription : 0;
|
||||
$this->state = self::STATE_BASIC;
|
||||
|
||||
@ -1091,7 +1091,7 @@ class cm_info extends stdClass {
|
||||
*/
|
||||
private function update_user_visible() {
|
||||
global $CFG;
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
|
||||
$modcontext = context_module::instance($this->id);
|
||||
$userid = $this->modinfo->get_user_id();
|
||||
$this->uservisible = true;
|
||||
// Check visibility/availability conditions.
|
||||
|
@ -1443,7 +1443,7 @@ function get_users_from_config($value, $capability, $includeadmins = true) {
|
||||
// we have to make sure that users still have the necessary capability,
|
||||
// it should be faster to fetch them all first and then test if they are present
|
||||
// instead of validating them one-by-one
|
||||
$users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), $capability);
|
||||
$users = get_users_by_capability(context_system::instance(), $capability);
|
||||
if ($includeadmins) {
|
||||
$admins = get_admins();
|
||||
foreach ($admins as $admin) {
|
||||
@ -2864,10 +2864,10 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
|
||||
}
|
||||
|
||||
// Fetch the system context, the course context, and prefetch its child contexts
|
||||
$sysctx = get_context_instance(CONTEXT_SYSTEM);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
|
||||
$sysctx = context_system::instance();
|
||||
$coursecontext = context_course::instance($course->id, MUST_EXIST);
|
||||
if ($cm) {
|
||||
$cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
|
||||
$cmcontext = context_module::instance($cm->id, MUST_EXIST);
|
||||
} else {
|
||||
$cmcontext = null;
|
||||
}
|
||||
@ -4452,7 +4452,7 @@ function delete_course($courseorid, $showfeedback = true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
|
||||
// frontpage course can not be deleted!!
|
||||
if ($courseid == SITEID) {
|
||||
@ -4788,7 +4788,7 @@ function reset_course_userdata($data) {
|
||||
require_once($CFG->dirroot.'/group/lib.php');
|
||||
|
||||
$data->courseid = $data->id;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
||||
$context = context_course::instance($data->courseid);
|
||||
|
||||
// calculate the time shift of dates
|
||||
if (!empty($data->reset_start_date)) {
|
||||
@ -5618,7 +5618,7 @@ function send_password_change_info($user) {
|
||||
|
||||
$site = get_site();
|
||||
$supportuser = generate_email_supportuser();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
|
||||
$data = new stdClass();
|
||||
$data->firstname = $user->firstname;
|
||||
|
@ -1131,7 +1131,7 @@ class global_navigation extends navigation_node {
|
||||
$addedcategories[$category->id] = $categoryparent->add($category->name, $url, self::TYPE_CATEGORY, $category->name, $category->id);
|
||||
|
||||
if (!$category->visible) {
|
||||
if (!has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_COURSECAT, $category->parent))) {
|
||||
if (!has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->parent))) {
|
||||
$addedcategories[$category->id]->display = false;
|
||||
} else {
|
||||
$addedcategories[$category->id]->hidden = true;
|
||||
@ -1230,7 +1230,7 @@ class global_navigation extends navigation_node {
|
||||
$isparent = false;
|
||||
if ($this->useridtouseforparentchecks) {
|
||||
if ($this->useridtouseforparentchecks != $USER->id) {
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $this->useridtouseforparentchecks, MUST_EXIST);
|
||||
$usercontext = context_user::instance($this->useridtouseforparentchecks, MUST_EXIST);
|
||||
if ($DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))
|
||||
and has_capability('moodle/user:viewdetails', $usercontext)) {
|
||||
$isparent = true;
|
||||
@ -1601,7 +1601,7 @@ class global_navigation extends navigation_node {
|
||||
continue;
|
||||
}
|
||||
context_instance_preload($course);
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
|
||||
continue;
|
||||
}
|
||||
$coursenodes[$course->id] = $this->add_course($course);
|
||||
@ -1637,7 +1637,7 @@ class global_navigation extends navigation_node {
|
||||
break;
|
||||
}
|
||||
context_instance_preload($course);
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
|
||||
continue;
|
||||
}
|
||||
$coursenodes[$course->id] = $this->add_course($course);
|
||||
@ -1661,7 +1661,7 @@ class global_navigation extends navigation_node {
|
||||
continue;
|
||||
}
|
||||
context_instance_preload($course);
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
|
||||
continue;
|
||||
}
|
||||
$coursenodes[$course->id] = $this->add_course($course);
|
||||
@ -1843,7 +1843,7 @@ class global_navigation extends navigation_node {
|
||||
return;
|
||||
}
|
||||
$url = new moodle_url('/course/category.php', array('id' => $category->id));
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$categoryname = format_string($category->name, true, array('context' => $context));
|
||||
$categorynode = $parent->add($categoryname, $url, self::TYPE_CATEGORY, $categoryname, $category->id);
|
||||
if (empty($category->visible)) {
|
||||
@ -2076,7 +2076,7 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
// Prepare the default name and url for the node
|
||||
$activityname = format_string($activity->name, true, array('context' => get_context_instance(CONTEXT_MODULE, $activity->id)));
|
||||
$activityname = format_string($activity->name, true, array('context' => context_module::instance($activity->id)));
|
||||
$action = new moodle_url($activity->url);
|
||||
|
||||
// Check if the onclick property is set (puke!)
|
||||
@ -2223,7 +2223,7 @@ class global_navigation extends navigation_node {
|
||||
|
||||
$iscurrentuser = ($user->id == $USER->id);
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
$usercontext = context_user::instance($user->id);
|
||||
|
||||
// Get the course set against the page, by default this will be the site
|
||||
$course = $this->page->course;
|
||||
@ -2231,11 +2231,11 @@ class global_navigation extends navigation_node {
|
||||
if ($course->id != $SITE->id && (!$iscurrentuser || $forceforcontext)) {
|
||||
$coursenode = $this->load_course($course);
|
||||
$baseargs['course'] = $course->id;
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$issitecourse = false;
|
||||
} else {
|
||||
// Load all categories and get the context for the system
|
||||
$coursecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$coursecontext = context_system::instance();
|
||||
$issitecourse = true;
|
||||
}
|
||||
|
||||
@ -2244,7 +2244,7 @@ class global_navigation extends navigation_node {
|
||||
// If it's the current user the information will go under the profile root node
|
||||
$usernode = $this->rootnodes['myprofile'];
|
||||
$course = get_site();
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$issitecourse = true;
|
||||
} else {
|
||||
if (!$issitecourse) {
|
||||
@ -2327,7 +2327,7 @@ class global_navigation extends navigation_node {
|
||||
$usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
if ($iscurrentuser && has_capability('moodle/user:manageownfiles', $context)) {
|
||||
$url = new moodle_url('/user/files.php');
|
||||
$usernode->add(get_string('myfiles'), $url, self::TYPE_SETTING);
|
||||
@ -2399,7 +2399,7 @@ class global_navigation extends navigation_node {
|
||||
$userscoursesnode = $usernode->add(get_string('courses'));
|
||||
|
||||
foreach ($userscourses as $usercourse) {
|
||||
$usercoursecontext = get_context_instance(CONTEXT_COURSE, $usercourse->id);
|
||||
$usercoursecontext = context_course::instance($usercourse->id);
|
||||
$usercourseshortname = format_string($usercourse->shortname, true, array('context' => $usercoursecontext));
|
||||
$usercoursenode = $userscoursesnode->add($usercourseshortname, new moodle_url('/user/view.php', array('id'=>$user->id, 'course'=>$usercourse->id)), self::TYPE_CONTAINER);
|
||||
|
||||
@ -2497,7 +2497,7 @@ class global_navigation extends navigation_node {
|
||||
return $this->addedcourses[$course->id];
|
||||
}
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
if ($course->id != $SITE->id && !$course->visible) {
|
||||
if (is_role_switched($course->id)) {
|
||||
@ -2544,7 +2544,7 @@ class global_navigation extends navigation_node {
|
||||
$coursenode = $parent->add($shortname, $url, self::TYPE_COURSE, $shortname, $course->id);
|
||||
$coursenode->nodetype = self::NODETYPE_BRANCH;
|
||||
$coursenode->hidden = (!$course->visible);
|
||||
$coursenode->title(format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))));
|
||||
$coursenode->title(format_string($course->fullname, true, array('context' => context_course::instance($course->id))));
|
||||
if (!$forcegeneric) {
|
||||
$this->addedcourses[$course->id] = $coursenode;
|
||||
}
|
||||
@ -2595,7 +2595,7 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
$filterselect = clean_param($filterselect, PARAM_INT);
|
||||
if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())))
|
||||
and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
and has_capability('moodle/blog:view', context_system::instance())) {
|
||||
$blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect));
|
||||
$participants->add(get_string('blogscourse','blog'), $blogsurls->out());
|
||||
}
|
||||
@ -2660,7 +2660,7 @@ class global_navigation extends navigation_node {
|
||||
// Blogs
|
||||
if (!empty($CFG->bloglevel)
|
||||
and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())))
|
||||
and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
and has_capability('moodle/blog:view', context_system::instance())) {
|
||||
$blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect));
|
||||
$coursenode->add(get_string('blogssite','blog'), $blogsurls->out());
|
||||
}
|
||||
@ -2856,7 +2856,7 @@ class global_navigation_for_ajax extends global_navigation {
|
||||
case self::TYPE_COURSE :
|
||||
$course = $DB->get_record('course', array('id' => $this->instanceid), '*', MUST_EXIST);
|
||||
require_course_login($course, true, null, false, true);
|
||||
$this->page->set_context(get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
$this->page->set_context(context_course::instance($course->id));
|
||||
$coursenode = $this->add_course($course);
|
||||
$this->add_course_essentials($coursenode, $course);
|
||||
if ($this->format_display_course_content($course->format)) {
|
||||
@ -2870,7 +2870,7 @@ class global_navigation_for_ajax extends global_navigation {
|
||||
WHERE cs.id = ?';
|
||||
$course = $DB->get_record_sql($sql, array($this->instanceid), MUST_EXIST);
|
||||
require_course_login($course, true, null, false, true);
|
||||
$this->page->set_context(get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
$this->page->set_context(context_course::instance($course->id));
|
||||
$coursenode = $this->add_course($course);
|
||||
$this->add_course_essentials($coursenode, $course);
|
||||
$sections = $this->load_course_sections($course, $coursenode);
|
||||
@ -2887,7 +2887,7 @@ class global_navigation_for_ajax extends global_navigation {
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$cm = $modinfo->get_cm($this->instanceid);
|
||||
require_course_login($course, true, $cm, false, true);
|
||||
$this->page->set_context(get_context_instance(CONTEXT_MODULE, $cm->id));
|
||||
$this->page->set_context(context_module::instance($cm->id));
|
||||
$coursenode = $this->load_course($course);
|
||||
if ($course->id == $SITE->id) {
|
||||
$modulenode = $this->load_activity($cm, $course, $coursenode->find($cm->id, self::TYPE_ACTIVITY));
|
||||
@ -3540,7 +3540,7 @@ class settings_navigation extends navigation_node {
|
||||
global $CFG;
|
||||
|
||||
$course = $this->page->course;
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
// note: do not test if enrolled or viewing here because we need the enrol link in Course administration section
|
||||
|
||||
@ -4017,13 +4017,13 @@ class settings_navigation extends navigation_node {
|
||||
$course = $SITE;
|
||||
}
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
|
||||
$coursecontext = context_course::instance($course->id); // Course context
|
||||
$systemcontext = get_system_context();
|
||||
$currentuser = ($USER->id == $userid);
|
||||
|
||||
if ($currentuser) {
|
||||
$user = $USER;
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context
|
||||
$usercontext = context_user::instance($user->id); // User context
|
||||
} else {
|
||||
$select = context_helper::get_preload_record_columns_sql('ctx');
|
||||
$sql = "SELECT u.*, $select
|
||||
@ -4038,7 +4038,7 @@ class settings_navigation extends navigation_node {
|
||||
context_helper::preload_from_record($user);
|
||||
|
||||
// Check that the user can view the profile
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context
|
||||
$usercontext = context_user::instance($user->id); // User context
|
||||
$canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
|
||||
|
||||
if ($course->id == $SITE->id) {
|
||||
@ -4199,7 +4199,7 @@ class settings_navigation extends navigation_node {
|
||||
if ($currentuser && !empty($CFG->bloglevel)) {
|
||||
$blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
|
||||
$blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
|
||||
if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', context_system::instance())) {
|
||||
$blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
|
||||
$blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
|
||||
}
|
||||
@ -4340,7 +4340,7 @@ class settings_navigation extends navigation_node {
|
||||
global $SITE, $CFG;
|
||||
|
||||
$course = clone($SITE);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
|
||||
$coursecontext = context_course::instance($course->id); // Course context
|
||||
|
||||
$frontpage = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage');
|
||||
if ($forceopen) {
|
||||
|
@ -92,7 +92,7 @@ class file_picker implements renderable {
|
||||
$options->currentfile = '';
|
||||
if (!empty($options->itemid)) {
|
||||
$fs = get_file_storage();
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
if (empty($options->filename)) {
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id DESC', false)) {
|
||||
$file = reset($files);
|
||||
|
@ -457,7 +457,7 @@ class core_renderer extends renderer_base {
|
||||
if (!empty($CFG->debugpageinfo)) {
|
||||
$output .= '<div class="performanceinfo pageinfo">This page is: ' . $this->page->debug_summary() . '</div>';
|
||||
}
|
||||
if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { // Only in developer mode
|
||||
if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', context_system::instance())) { // Only in developer mode
|
||||
// Add link to profiling report if necessary
|
||||
if (function_exists('profiling_is_running') && profiling_is_running()) {
|
||||
$txt = get_string('profiledscript', 'admin');
|
||||
@ -535,7 +535,7 @@ class core_renderer extends renderer_base {
|
||||
// $course->id is not defined during installation
|
||||
return '';
|
||||
} else if (isloggedin()) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
$fullname = fullname($USER, true);
|
||||
// Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
|
||||
@ -579,7 +579,7 @@ class core_renderer extends renderer_base {
|
||||
} else {
|
||||
$loggedinas .= get_string('failedloginattemptsall', '', $count);
|
||||
}
|
||||
if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
|
||||
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/report/log/index.php'.
|
||||
'?chooselog=1&id=1&modid=site_errors">'.get_string('logs').'</a>)';
|
||||
}
|
||||
@ -2075,7 +2075,7 @@ EOD;
|
||||
*/
|
||||
public function update_module_button($cmid, $modulename) {
|
||||
global $CFG;
|
||||
if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
|
||||
if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
|
||||
$modulename = get_string('modulename', $modulename);
|
||||
$string = get_string('updatethis', '', $modulename);
|
||||
$url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
|
||||
|
@ -449,7 +449,7 @@ class moodle_page {
|
||||
.'to call require_login() or $PAGE->set_context(). The page may not display '
|
||||
.'correctly as a result');
|
||||
}
|
||||
$this->_context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$this->_context = context_system::instance();
|
||||
}
|
||||
return $this->_context;
|
||||
}
|
||||
@ -862,7 +862,7 @@ class moodle_page {
|
||||
}
|
||||
|
||||
if (!$this->_context) {
|
||||
$this->set_context(get_context_instance(CONTEXT_COURSE, $this->_course->id));
|
||||
$this->set_context(context_course::instance($this->_course->id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -876,7 +876,7 @@ class moodle_page {
|
||||
// extremely ugly hack which sets context to some value in order to prevent warnings,
|
||||
// use only for core error handling!!!!
|
||||
if (!$this->_context) {
|
||||
$this->_context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$this->_context = context_system::instance();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -933,7 +933,7 @@ class moodle_page {
|
||||
|
||||
// unfortunately the context setting is a mess, let's try to work around some common block problems and show some debug messages
|
||||
if (empty($this->_context) or $this->_context->contextlevel != CONTEXT_BLOCK) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
$this->set_context($context);
|
||||
}
|
||||
|
||||
@ -1096,7 +1096,7 @@ class moodle_page {
|
||||
$this->ensure_theme_not_set();
|
||||
$this->set_course($SITE);
|
||||
$this->load_category($categoryid);
|
||||
$this->set_context(get_context_instance(CONTEXT_COURSECAT, $categoryid));
|
||||
$this->set_context(context_coursecat::instance($categoryid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1096,7 +1096,7 @@ function portfolio_insane_notify_admins($insane, $instances=false) {
|
||||
$site = get_site();
|
||||
|
||||
$a = new StdClass;
|
||||
$a->sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$a->sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID)));
|
||||
$a->fixurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageportfolios";
|
||||
$a->htmllist = portfolio_report_insane($insane, $instances, true);
|
||||
$a->textlist = '';
|
||||
|
@ -355,7 +355,7 @@ function question_delete_course($course, $feedback=true) {
|
||||
|
||||
//Cache some strings
|
||||
$strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$categoriescourse = $DB->get_records('question_categories',
|
||||
array('contextid' => $coursecontext->id), 'parent', 'id, parent, name, contextid');
|
||||
|
||||
@ -407,7 +407,7 @@ function question_delete_course($course, $feedback=true) {
|
||||
function question_delete_course_category($category, $newcategory, $feedback=true) {
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
||||
$context = context_coursecat::instance($category->id);
|
||||
if (empty($newcategory)) {
|
||||
$feedbackdata = array(); // To store feedback to be showed at the end of the process
|
||||
$rescueqcategory = null; // See the code around the call to question_save_from_deletion.
|
||||
@ -464,7 +464,7 @@ function question_delete_course_category($category, $newcategory, $feedback=true
|
||||
|
||||
} else {
|
||||
// Move question categories ot the new context.
|
||||
if (!$newcontext = get_context_instance(CONTEXT_COURSECAT, $newcategory->id)) {
|
||||
if (!$newcontext = context_coursecat::instance($newcategory->id)) {
|
||||
return false;
|
||||
}
|
||||
$DB->set_field('question_categories', 'contextid', $newcontext->id,
|
||||
@ -529,7 +529,7 @@ function question_delete_activity($cm, $feedback=true) {
|
||||
|
||||
//Cache some strings
|
||||
$strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$modcontext = context_module::instance($cm->id);
|
||||
if ($categoriesmods = $DB->get_records('question_categories',
|
||||
array('contextid' => $modcontext->id), 'parent', 'id, parent, name, contextid')) {
|
||||
//Sort categories following their tree (parent-child) relationships
|
||||
|
@ -67,10 +67,10 @@ function resourcelib_try_file_migration($filepath, $cmid, $courseid, $component,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
|
||||
if (!$context = context_module::instance($cmid)) {
|
||||
return false;
|
||||
}
|
||||
if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid)) {
|
||||
if (!$coursecontext = context_course::instance($courseid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ function stats_cron_daily($maxdays=1) {
|
||||
|
||||
$now = time();
|
||||
|
||||
$fpcontext = get_context_instance(CONTEXT_COURSE, SITEID, MUST_EXIST);
|
||||
$fpcontext = context_course::instance(SITEID, MUST_EXIST);
|
||||
|
||||
// read last execution date from db
|
||||
if (!$timestart = get_config(NULL, 'statslastdaily')) {
|
||||
@ -1332,7 +1332,7 @@ function stats_get_report_options($courseid,$mode) {
|
||||
switch ($mode) {
|
||||
case STATS_MODE_GENERAL:
|
||||
$reportoptions[STATS_REPORT_ACTIVITY] = get_string('statsreport'.STATS_REPORT_ACTIVITY);
|
||||
if ($courseid != SITEID && $context = get_context_instance(CONTEXT_COURSE, $courseid)) {
|
||||
if ($courseid != SITEID && $context = context_course::instance($courseid)) {
|
||||
$sql = 'SELECT r.id, r.name FROM {role} r JOIN {stats_daily} s ON s.roleid = r.id WHERE s.courseid = :courseid GROUP BY r.id, r.name';
|
||||
if ($roles = $DB->get_records_sql($sql, array('courseid' => $courseid))) {
|
||||
foreach ($roles as $role) {
|
||||
@ -1350,13 +1350,13 @@ function stats_get_report_options($courseid,$mode) {
|
||||
case STATS_MODE_DETAILED:
|
||||
$reportoptions[STATS_REPORT_USER_ACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ACTIVITY);
|
||||
$reportoptions[STATS_REPORT_USER_ALLACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ALLACTIVITY);
|
||||
if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('report/stats:view', context_system::instance())) {
|
||||
$site = get_site();
|
||||
$reportoptions[STATS_REPORT_USER_LOGINS] = get_string('statsreport'.STATS_REPORT_USER_LOGINS);
|
||||
}
|
||||
break;
|
||||
case STATS_MODE_RANKED:
|
||||
if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('report/stats:view', context_system::instance())) {
|
||||
$reportoptions[STATS_REPORT_ACTIVE_COURSES] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES);
|
||||
$reportoptions[STATS_REPORT_ACTIVE_COURSES_WEIGHTED] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES_WEIGHTED);
|
||||
$reportoptions[STATS_REPORT_PARTICIPATORY_COURSES] = get_string('statsreport'.STATS_REPORT_PARTICIPATORY_COURSES);
|
||||
|
@ -2336,14 +2336,14 @@ class accesslib_testcase extends advanced_testcase {
|
||||
accesslib_clear_all_caches(false);
|
||||
$DB->delete_records('cache_flags', array());
|
||||
$course = $DB->get_record('course', array('id'=>$testcourses[2]));
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
$oldpath = $context->path;
|
||||
$miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
|
||||
$categorycontext = context_coursecat::instance($miscid);
|
||||
$course->category = $miscid;
|
||||
$DB->update_record('course', $course);
|
||||
context_moved($context, $categorycontext);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
$this->assertEquals($context->get_parent_context(), $categorycontext);
|
||||
|
||||
$this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2])));
|
||||
@ -2353,7 +2353,7 @@ class accesslib_testcase extends advanced_testcase {
|
||||
$name = get_contextlevel_name(CONTEXT_COURSE);
|
||||
$this->assertFalse(empty($name));
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $testcourses[2]);
|
||||
$context = context_course::instance($testcourses[2]);
|
||||
$name = print_context_name($context);
|
||||
$this->assertFalse(empty($name));
|
||||
|
||||
@ -2361,7 +2361,7 @@ class accesslib_testcase extends advanced_testcase {
|
||||
$this->assertFalse($url instanceof modole_url);
|
||||
|
||||
$page = $DB->get_record('page', array('id'=>$testpages[7]));
|
||||
$context = get_context_instance(CONTEXT_MODULE, $page->id);
|
||||
$context = context_module::instance($page->id);
|
||||
$coursecontext = get_course_context($context);
|
||||
$this->assertEquals($coursecontext->contextlevel, CONTEXT_COURSE);
|
||||
$this->assertEquals(get_courseid_from_context($context), $page->course);
|
||||
|
@ -56,7 +56,7 @@ class moodle_block_manager_testcase extends basic_testcase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->testpage = new moodle_page();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$this->testpage->set_context(context_system::instance());
|
||||
$this->blockmanager = new testable_block_manager($this->testpage);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
|
||||
// Set up fixture.
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array('a-region'),
|
||||
get_context_instance(CONTEXT_SYSTEM), 'page-type');
|
||||
context_system::instance(), 'page-type');
|
||||
// Exercise SUT.
|
||||
$blockmanager->load_blocks();
|
||||
// Validate.
|
||||
@ -219,7 +219,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
// Set up fixture.
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
|
||||
$context, 'page-type');
|
||||
@ -238,7 +238,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
// Set up fixture.
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
|
||||
$context, 'page-type');
|
||||
@ -257,7 +257,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
$this->purge_blocks();
|
||||
|
||||
// Set up fixture.
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
$cat = new stdClass();
|
||||
$cat->name = 'testcategory';
|
||||
$cat->parent = 0;
|
||||
@ -286,7 +286,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
$this->purge_blocks();
|
||||
|
||||
// Set up fixture.
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
$childcontext = context_coursecat::instance(1);
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
@ -307,7 +307,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
$this->purge_blocks();
|
||||
|
||||
// Set up fixture.
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
|
||||
@ -329,7 +329,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
// Set up fixture.
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
|
||||
$syscontext, 'page-type', 'sub-page');
|
||||
@ -349,7 +349,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
// Set up fixture.
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
|
||||
$syscontext, 'page-type', 'sub-page');
|
||||
@ -369,7 +369,7 @@ class moodle_block_manager_test_saving_loading_testcase extends advanced_testcas
|
||||
// Set up fixture.
|
||||
$regionname = 'a-region';
|
||||
$blockname = $this->get_a_known_block_type();
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
|
||||
$syscontext, 'page-type', 'sub-page');
|
||||
|
@ -298,7 +298,7 @@ class filter_active_local_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_throws_exception_when_setting_global() {
|
||||
// Exercise SUT.
|
||||
filter_set_local_state('filter/name', get_context_instance(CONTEXT_SYSTEM)->id, TEXTFILTER_INHERIT);
|
||||
filter_set_local_state('filter/name', context_system::instance()->id, TEXTFILTER_INHERIT);
|
||||
}
|
||||
|
||||
public function test_local_inherit_deletes_existing() {
|
||||
|
@ -26,7 +26,7 @@ require(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/pdflib.php');
|
||||
|
||||
require_login();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
$getpdf = optional_param('getpdf', 0, PARAM_INT);
|
||||
|
@ -27,7 +27,7 @@
|
||||
require(dirname(__FILE__) . '/../../../config.php');
|
||||
|
||||
require_login();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
$PAGE->set_url('/lib/tests/other/todochecker.php');
|
||||
|
@ -65,7 +65,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
public function test_setting_course_works() {
|
||||
// Setup fixture
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context.
|
||||
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
|
||||
// Exercise SUT
|
||||
$this->testpage->set_course($course);
|
||||
// Validate
|
||||
@ -76,7 +76,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
global $COURSE, $PAGE;
|
||||
// Setup fixture
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context.
|
||||
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
|
||||
$PAGE = $this->testpage;
|
||||
// Exercise SUT
|
||||
$this->testpage->set_course($course);
|
||||
@ -89,7 +89,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
$originalcourse = $COURSE;
|
||||
// Setup fixture
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context.
|
||||
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
|
||||
// Exercise SUT
|
||||
$this->testpage->set_course($course);
|
||||
// Validate
|
||||
@ -118,7 +118,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
public function test_cannot_set_category_once_course_set() {
|
||||
// Setup fixture
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context.
|
||||
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
|
||||
$this->testpage->set_course($course);
|
||||
// Set expectation.
|
||||
$this->setExpectedException('coding_exception');
|
||||
@ -129,7 +129,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
public function test_categories_array_empty_for_front_page() {
|
||||
global $SITE;
|
||||
// Setup fixture
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM)); // Avoid trying to set the context.
|
||||
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
|
||||
$this->testpage->set_course($SITE);
|
||||
// Exercise SUT and validate.
|
||||
$this->assertEquals(array(), $this->testpage->categories);
|
||||
@ -137,7 +137,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
|
||||
public function test_set_state_normal_path() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$this->testpage->set_context(context_system::instance());
|
||||
$this->testpage->set_course($course);
|
||||
|
||||
$this->assertEquals(moodle_page::STATE_BEFORE_HEADER, $this->testpage->state);
|
||||
@ -166,7 +166,7 @@ class moodle_page_test extends advanced_testcase {
|
||||
|
||||
public function test_header_printed_becomes_true() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$this->testpage->set_context(context_system::instance());
|
||||
$this->testpage->set_course($course);
|
||||
|
||||
// Exercise SUT
|
||||
@ -564,7 +564,7 @@ class moodle_page_editing_test extends advanced_testcase {
|
||||
parent::setUp();
|
||||
$this->setAdminUser();
|
||||
$this->testpage = new testable_moodle_page();
|
||||
$this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$this->testpage->set_context(context_system::instance());
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ require(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/ddllib.php');
|
||||
|
||||
require_login();
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
require_capability('moodle/site:config', $syscontext);
|
||||
|
||||
$baseurl = new moodle_url('/lib/tests/performance/filtersettingsperformancetester.php');
|
||||
|
@ -650,7 +650,7 @@ function clam_scan_moodle_file(&$file, $course) {
|
||||
case 1: // bad wicked evil, we have a virus.
|
||||
$info = new stdClass();
|
||||
if (!empty($course)) {
|
||||
$info->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$info->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
|
||||
}
|
||||
else {
|
||||
$info->course = 'No course';
|
||||
|
@ -713,7 +713,7 @@ class moodle_url {
|
||||
public static function make_draftfile_url($draftid, $pathname, $filename, $forcedownload = false) {
|
||||
global $CFG, $USER;
|
||||
$urlbase = "$CFG->httpswwwroot/draftfile.php";
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
|
||||
return self::make_file_url($urlbase, "/$context->id/user/draft/$draftid".$pathname.$filename, $forcedownload);
|
||||
}
|
||||
@ -1076,7 +1076,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_
|
||||
}
|
||||
} else if ($courseid_do_not_use) {
|
||||
// legacy courseid
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid_do_not_use);
|
||||
$context = context_course::instance($courseid_do_not_use);
|
||||
} else {
|
||||
// fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
|
||||
$context = $PAGE->context;
|
||||
@ -1272,7 +1272,7 @@ function format_string($string, $striplinks = true, $options = NULL) {
|
||||
|
||||
if (is_numeric($options)) {
|
||||
// legacy courseid usage
|
||||
$options = array('context'=>get_context_instance(CONTEXT_COURSE, $options));
|
||||
$options = array('context'=>context_course::instance($options));
|
||||
} else {
|
||||
$options = (array)$options; // detach object, we can not modify it
|
||||
}
|
||||
@ -1412,7 +1412,7 @@ function format_text_email($text, $format) {
|
||||
function format_module_intro($module, $activity, $cmid, $filter=true) {
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$context = context_module::instance($cmid);
|
||||
$options = array('noclean'=>true, 'para'=>false, 'filter'=>$filter, 'context'=>$context, 'overflowdiv'=>true);
|
||||
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, 'mod_'.$module, 'intro', null);
|
||||
return trim(format_text($intro, $activity->introformat, $options, null));
|
||||
@ -2076,7 +2076,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
|
||||
}
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
|
||||
// If there is no picture, do nothing
|
||||
if (!$group->picture) {
|
||||
@ -2132,7 +2132,7 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false, $
|
||||
$output = '';
|
||||
|
||||
if (is_null($viewfullnames)) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
}
|
||||
|
||||
@ -2185,7 +2185,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
|
||||
$menu = array();
|
||||
$doneheading = false;
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
$menu[] = '<ul class="navmenulist"><li class="jumpto section"><span>'.$strjumpto.'</span><ul>';
|
||||
foreach ($modinfo->cms as $mod) {
|
||||
|
@ -33,7 +33,7 @@
|
||||
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
// end moodle modification
|
||||
|
||||
// by default assume that xhprof_html & xhprof_lib directories
|
||||
|
@ -35,7 +35,7 @@
|
||||
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
// end moodle modification
|
||||
|
||||
// by default assume that xhprof_html & xhprof_lib directories
|
||||
|
@ -25,7 +25,7 @@
|
||||
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
// end moodle modification
|
||||
|
||||
// by default assume that xhprof_html & xhprof_lib directories
|
||||
|
Loading…
x
Reference in New Issue
Block a user