Commit 87dd647f authored by Dan Poltawski's avatar Dan Poltawski
Browse files

Merge branch 'wip-MDL-34465-master' of git://github.com/abgreeve/moodle

parents 31e81667 b0c6dc1c
......@@ -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 =