Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-34460 Librairies: Replaced deprecated get_context_instance()

  • Loading branch information...
commit 4373103084527e9ca33cc98e388d5e7b2fba39a3 1 parent 42b60b2
@FMCorz FMCorz authored
Showing with 106 additions and 106 deletions.
  1. +1 −1  rss/file.php
  2. +1 −1  tag/coursetags_add.php
  3. +2 −2 tag/coursetags_edit.php
  4. +3 −3 tag/coursetags_more.php
  5. +1 −1  tag/coursetagslib.php
  6. +1 −1  tag/edit.php
  7. +1 −1  tag/edit_form.php
  8. +1 −1  tag/index.php
  9. +1 −1  tag/lib.php
  10. +4 −4 tag/locallib.php
  11. +2 −2 tag/manage.php
  12. +2 −2 tag/search.php
  13. +5 −5 theme/mymobile/renderers.php
  14. +1 −1  user/addnote.php
  15. +5 −5 user/edit.php
  16. +2 −2 user/edit_form.php
  17. +6 −6 user/editadvanced.php
  18. +1 −1  user/editadvanced_form.php
  19. +1 −1  user/editlib.php
  20. +1 −1  user/emailupdate.php
  21. +5 −5 user/externallib.php
  22. +1 −1  user/files.php
  23. +1 −1  user/filters/courserole.php
  24. +1 −1  user/filters/globalrole.php
  25. +1 −1  user/groupaddnote.php
  26. +7 −7 user/index.php
  27. +6 −6 user/lib.php
  28. +1 −1  user/managetoken.php
  29. +3 −3 user/messageselect.php
  30. +1 −1  user/pix.php
  31. +1 −1  user/policy.php
  32. +1 −1  user/portfolio.php
  33. +1 −1  user/portfoliologs.php
  34. +5 −5 user/profile.php
  35. +1 −1  user/profile/field/checkbox/field.class.php
  36. +1 −1  user/profile/field/menu/field.class.php
  37. +6 −6 user/profile/lib.php
  38. +1 −1  user/profilesys.php
  39. +1 −1  user/renderer.php
  40. +1 −1  user/repository.php
  41. +3 −3 user/selector/lib.php
  42. +1 −1  user/selector/search.php
  43. +4 −4 user/view.php
  44. +1 −1  userpix/index.php
  45. +1 −1  webservice/externallib.php
  46. +6 −6 webservice/lib.php
  47. +1 −1  webservice/upload.php
  48. +1 −1  webservice/wsdoc.php
View
2  rss/file.php
@@ -85,7 +85,7 @@
foreach ($modinfo->instances[$componentname] as $modinstanceid=>$cm) {
if ($modinstanceid==$instanceid) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id, IGNORE_MISSING);
break;
}
}
View
2  tag/coursetags_add.php
@@ -28,7 +28,7 @@
require_login();
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
require_capability('moodle/tag:create', $systemcontext);
if (empty($CFG->usetags)) {
View
4 tag/coursetags_edit.php
@@ -59,7 +59,7 @@
}
// Permissions
-$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+$sitecontext = context_system::instance();
require_login($course);
$canedit = has_capability('moodle/tag:create', $sitecontext);
@@ -85,7 +85,7 @@
// The title and breadcrumb
$title = get_string('edittitle', $tagslang);
$coursefullname = format_string($course->fullname);
-$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$PAGE->navbar->add($title);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
View
6 tag/coursetags_more.php
@@ -65,7 +65,7 @@
}
if ($courseid) {
- $PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid));
+ $PAGE->set_context(context_course::instance($courseid));
} else {
$PAGE->set_context(get_system_context());
}
@@ -86,7 +86,7 @@
// The title and breadcrumb
if ($courseid) {
- $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
+ $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid)));
$PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
}
$PAGE->navbar->add($title);
@@ -183,7 +183,7 @@
}
}
if ($courseid) {
- $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
if ($show == 'course') {
$link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
} else {
View
2  tag/coursetagslib.php
@@ -232,7 +232,7 @@ function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_siz
$step = ($max_size - $min_size)/($spread);
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
$can_manage_tags = has_capability('moodle/tag:manage', $systemcontext);
//prints the tag cloud
View
2  tag/edit.php
@@ -36,7 +36,7 @@
}
//Editing a tag requires moodle/tag:edit capability
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
require_capability('moodle/tag:edit', $systemcontext);
if ($tag_name) {
View
2  tag/edit_form.php
@@ -51,7 +51,7 @@ function definition () {
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
if (has_capability('moodle/tag:manage', $systemcontext)) {
$mform->addElement('text', 'rawname', get_string('name', 'tag'),
View
2  tag/index.php
@@ -41,7 +41,7 @@
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', 24, PARAM_INT);
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
if ($tagname) {
$tag = tag_get('name', $tagname, '*');
View
2  tag/lib.php
@@ -600,7 +600,7 @@ function tag_delete($tagids) {
}
$success = true;
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
foreach ($tagids as $tagid) {
if (is_null($tagid)) { // can happen if tag doesn't exists
continue;
View
8 tag/locallib.php
@@ -39,7 +39,7 @@
function tag_print_cloud($nr_of_tags=150, $return=false) {
global $CFG, $DB;
- $can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM));
+ $can_manage_tags = has_capability('moodle/tag:manage', context_system::instance());
if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
@@ -146,7 +146,7 @@ function tag_print_description_box($tag_object, $return=false) {
$options = new stdClass();
$options->para = false;
$options->overflowdiv = true;
- $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag', 'description', $tag_object->id);
+ $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id);
$output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
}
@@ -190,7 +190,7 @@ function tag_print_management_box($tag_object, $return=false) {
if (!isguestuser()) {
$output .= $OUTPUT->box_start('box','tag-management-box');
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
$links = array();
// Add a link for users to add/remove this from their interests
@@ -356,7 +356,7 @@ function tag_print_tagged_users_table($tag_object, $limitfrom='', $limitnum='',
function tag_print_user_box($user, $return=false) {
global $CFG, $OUTPUT;
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $usercontext = context_user::instance($user->id);
$profilelink = '';
if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) {
View
4 tag/manage.php
@@ -41,7 +41,7 @@
print_error('tagsaredisabled', 'tag');
}
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
require_capability('moodle/tag:manage', $systemcontext);
$params = array();
@@ -151,7 +151,7 @@
// tag exists, change the type
tag_type_set($new_otag_id, 'official');
} else {
- require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM));
+ require_capability('moodle/tag:create', context_system::instance());
tag_add($new_otag, 'official');
}
$notice .= get_string('addedotag', 'tag', $new_otag) .' ';
View
4 tag/search.php
@@ -47,10 +47,10 @@
$params['perpage'] = $perpage;
}
$PAGE->set_url(new moodle_url('/tag/search.php', $params));
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
$manage_link = '&nbsp;';
$PAGE->set_title(get_string('tags', 'tag'));
View
10 theme/mymobile/renderers.php
@@ -44,7 +44,7 @@ class theme_mymobile_renderer extends plugin_renderer_base {
*/
public function settings_tree(settings_navigation $navigation) {
$content = $this->navigation_node($navigation, array('class' => 'settings'));
- if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('moodle/site:config', context_system::instance())) {
// TODO: Work out whether something is missing from here.
}
return $content;
@@ -326,7 +326,7 @@ public function login_info() {
// $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)
@@ -364,7 +364,7 @@ public function login_info() {
} 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.'/course/report/log/index.php?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
@@ -405,7 +405,7 @@ public function login_info_footer() {
// $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)
@@ -447,7 +447,7 @@ public function login_info_footer() {
} else {
$loggedinas .= get_string('failedloginattemptsall', '', $count);
}
- if (has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('report/log:view', context_system::instance())) {
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
View
2  user/addnote.php
@@ -37,7 +37,7 @@
print_error('invalidcourseid');
}
-$context = get_context_instance(CONTEXT_COURSE, $id);
+$context = context_course::instance($id);
require_login($course);
// to create notes the current user needs a capability
View
10 user/edit.php
@@ -97,12 +97,12 @@
}
if ($course->id == SITEID) {
- $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
+ $coursecontext = context_system::instance(); // SYSTEM context
} else {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
+ $coursecontext = context_course::instance($course->id); // Course context
}
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
+$systemcontext = context_system::instance();
+$personalcontext = context_user::instance($user->id);
// check access control
if ($user->id == $USER->id) {
@@ -244,7 +244,7 @@
$a = new stdClass();
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
- $a->site = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID)));
$a->fullname = fullname($user, true);
$emailupdatemessage = get_string('emailupdatemessage', 'auth', $a);
View
4 user/edit_form.php
@@ -83,7 +83,7 @@ function definition_after_data() {
// print picture
if (!empty($CFG->gdversion)) {
- $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
+ $context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg'));
if (!empty($user->picture) && $hasuploadedpicture) {
@@ -147,7 +147,7 @@ function validation($usernew, $files) {
$errors['email'] = get_string('toomanybounces');
}
- if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', context_system::instance())) {
$errorstr = email_is_not_allowed($usernew->email);
if ($errorstr !== false) {
$errors['email'] = $errorstr;
View
12 user/editadvanced.php
@@ -49,11 +49,11 @@
}
if ($course->id == SITEID) {
- $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
+ $coursecontext = context_system::instance(); // SYSTEM context
} else {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
+ $coursecontext = context_course::instance($course->id); // Course context
}
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
if ($id == -1) {
// creating new user
@@ -68,7 +68,7 @@
// editing existing user
require_capability('moodle/user:update', $systemcontext);
$user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST);
- $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
+ $PAGE->set_context(context_user::instance($user->id));
if ($user->id == $USER->id) {
if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) {
$node->make_active();
@@ -112,7 +112,7 @@
}
if ($user->id !== -1) {
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $usercontext = context_user::instance($user->id);
$editoroptions = array(
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $CFG->maxbytes,
@@ -203,7 +203,7 @@
$usercreated = false;
}
- $usercontext = get_context_instance(CONTEXT_USER, $usernew->id);
+ $usercontext = context_user::instance($usernew->id);
//update preferences
useredit_update_user_preference($usernew);
View
2  user/editadvanced_form.php
@@ -130,7 +130,7 @@ function definition_after_data() {
// print picture
if (!empty($CFG->gdversion) and empty($USER->newadminuser)) {
if ($user) {
- $context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
+ $context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg'));
if (!empty($user->picture) && $hasuploadedpicture) {
View
2  user/editlib.php
@@ -46,7 +46,7 @@ function useredit_update_picture(stdClass $usernew, moodleform $userform, $filem
global $CFG, $DB;
require_once("$CFG->libdir/gdlib.php");
- $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
+ $context = context_user::instance($usernew->id, MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST);
$newpicture = $user->picture;
View
2  user/emailupdate.php
@@ -31,7 +31,7 @@
$id = required_param('id', PARAM_INT);
$PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key));
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
if (!$user = $DB->get_record('user', array('id' => $id))) {
print_error('invaliduserid');
View
10 user/externallib.php
@@ -100,7 +100,7 @@ public static function create_users($users) {
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
// Ensure the current user is allowed to run this function
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
self::validate_context($context);
require_capability('moodle/user:create', $context);
@@ -226,7 +226,7 @@ public static function delete_users($userids) {
require_once($CFG->dirroot."/user/lib.php");
// Ensure the current user is allowed to run this function
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
require_capability('moodle/user:delete', $context);
self::validate_context($context);
@@ -324,7 +324,7 @@ public static function update_users($users) {
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
// Ensure the current user is allowed to run this function
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
require_capability('moodle/user:update', $context);
self::validate_context($context);
@@ -413,7 +413,7 @@ public static function get_users_by_id($userids) {
continue;
}
context_instance_preload($user);
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $usercontext = context_user::instance($user->id, IGNORE_MISSING);
self::validate_context($usercontext);
$currentuser = ($user->id == $USER->id);
@@ -576,7 +576,7 @@ public static function get_course_user_profiles($userlist) {
}
context_instance_preload($user);
$course = $courses[$courseids[$user->id]];
- $context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]);
+ $context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
self::validate_context($context);
if ($userarray = user_get_user_details($user, $course)) {
$result[] = $userarray;
View
2  user/files.php
@@ -38,7 +38,7 @@
$returnurl = new moodle_url('/user/files.php');
}
-$context = get_context_instance(CONTEXT_USER, $USER->id);
+$context = context_user::instance($USER->id);
require_capability('moodle/user:manageownfiles', $context);
$title = get_string('myfiles');
View
2  user/filters/courserole.php
@@ -21,7 +21,7 @@ function user_filter_courserole($name, $label, $advanced) {
* @return array of availble roles
*/
function get_roles() {
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
$roles = array(0=> get_string('anyrole','filters')) + get_default_enrol_roles($context);
return $roles;
}
View
2  user/filters/globalrole.php
@@ -22,7 +22,7 @@ function user_filter_globalrole($name, $label, $advanced) {
* @return array of availble roles
*/
function get_roles() {
- $context = get_context_instance(CONTEXT_SYSTEM);
+ $context = context_system::instance();
$roles = array(0=> get_string('anyrole','filters')) + get_assignable_roles($context);
return $roles;
}
View
2  user/groupaddnote.php
@@ -44,7 +44,7 @@
print_error('invalidcourseid');
}
-$context = get_context_instance(CONTEXT_COURSE, $id);
+$context = context_course::instance($id);
require_login($course);
// to create notes the current user needs a capability
View
14 user/index.php
@@ -41,7 +41,7 @@
$course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST);
} else {
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
- $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+ $context = context_course::instance($course->id, MUST_EXIST);
}
// not needed anymore
unset($contextid);
@@ -49,10 +49,10 @@
require_login($course);
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
$isfrontpage = ($course->id == SITEID);
- $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
+ $frontpagectx = context_course::instance(SITEID);
if ($isfrontpage) {
$PAGE->set_pagelayout('admin');
@@ -190,7 +190,7 @@
$courselist = array();
$popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast=');
foreach ($mycourses as $mycourse) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
+ $coursecontext = context_course::instance($mycourse->id);
$courselist[$mycourse->id] = format_string($mycourse->shortname, true, array('context' => $coursecontext));
}
if (has_capability('moodle/site:viewparticipants', $systemcontext)) {
@@ -579,8 +579,8 @@
context_instance_preload($user);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $context = context_course::instance($course->id);
+ $usercontext = context_user::instance($user->id);
$countries = get_string_manager()->get_list_of_countries();
@@ -719,7 +719,7 @@
}
}
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $usercontext = context_user::instance($user->id);
if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) {
$profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>';
View
12 user/lib.php
@@ -70,7 +70,7 @@ function user_create_user($user) {
$newuser = $DB->get_record('user', array('id' => $newuserid));
// create USER context for this user
- get_context_instance(CONTEXT_USER, $newuserid);
+ context_user::instance($newuserid);
// update user password if necessary
if (isset($userpassword)) {
@@ -225,11 +225,11 @@ function user_get_user_details($user, $course = null, array $userfields = array(
}
if (!empty($course)) {
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+ $context = context_course::instance($course->id);
+ $usercontext = context_user::instance($user->id);
$canviewdetailscap = (has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext));
} else {
- $context = get_context_instance(CONTEXT_USER, $user->id);
+ $context = context_user::instance($user->id);
$usercontext = $context;
$canviewdetailscap = has_capability('moodle/user:viewdetails', $usercontext);
}
@@ -448,10 +448,10 @@ function user_get_user_details($user, $course = null, array $userfields = array(
if ($mycourses = enrol_get_users_courses($user->id, true)) {
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
+ $coursecontext = context_course::instance($mycourse->id);
$enrolledcourse = array();
$enrolledcourse['id'] = $mycourse->id;
- $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $mycourse->id)));
+ $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => context_course::instance($mycourse->id)));
$enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext));
$enrolledcourses[] = $enrolledcourse;
}
View
2  user/managetoken.php
@@ -29,7 +29,7 @@
require_login();
require_sesskey();
-$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+$usercontext = context_user::instance($USER->id);
$PAGE->set_context($usercontext);
$PAGE->set_url('/user/managetoken.php');
View
6 user/messageselect.php
@@ -58,7 +58,7 @@
$url->param('deluser', $deluser);
}
$PAGE->set_url($url);
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
@@ -66,8 +66,8 @@
require_login();
-$coursecontext = get_context_instance(CONTEXT_COURSE, $id); // Course context
-$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
+$coursecontext = context_course::instance($id); // Course context
+$systemcontext = context_system::instance(); // SYSTEM context
require_capability('moodle/course:bulkmessaging', $coursecontext);
if (empty($SESSION->emailto)) {
View
2  user/pix.php
@@ -42,7 +42,7 @@
} else {
$image = 'f2';
}
- if ($usercontext = get_context_instance(CONTEXT_USER, $userid)) {
+ if ($usercontext = context_user::instance($userid, IGNORE_MISSING)) {
$url = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $image);
redirect($url);
}
View
2  user/policy.php
@@ -66,7 +66,7 @@
$strpolicyagreement = get_string('policyagreement');
$strpolicyagreementclick = get_string('policyagreementclick');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$PAGE->set_title($strpolicyagreement);
$PAGE->set_heading($SITE->fullname);
$PAGE->navbar->add($strpolicyagreement);
View
2  user/portfolio.php
@@ -58,7 +58,7 @@
require_login($course, false);
$PAGE->set_url($url);
-$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
+$PAGE->set_context(context_user::instance($user->id));
$PAGE->set_title("$course->fullname: $fullname: $strportfolios");
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('standard');
View
2  user/portfoliologs.php
@@ -60,7 +60,7 @@
$PAGE->set_url($url);
$PAGE->set_title("$course->fullname: $fullname: $strportfolios");
$PAGE->set_heading($course->fullname);
-$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
+$PAGE->set_context(context_user::instance($user->id));
$PAGE->set_pagelayout('standard');
echo $OUTPUT->header();
View
10 user/profile.php
@@ -59,7 +59,7 @@
$user = $DB->get_record('user', array('id' => $userid));
if ($user->deleted) {
- $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $PAGE->set_context(context_system::instance());
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted'));
echo $OUTPUT->footer();
@@ -67,7 +67,7 @@
}
$currentuser = ($user->id == $USER->id);
-$context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST);
+$context = $usercontext = context_user::instance($userid, MUST_EXIST);
if (!$currentuser &&
!empty($CFG->forceloginforprofiles) &&
@@ -76,7 +76,7 @@
// Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
$struser = get_string('user');
- $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $PAGE->set_context(context_system::instance());
$PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name
$PAGE->set_heading("$SITE->shortname: $struser");
$PAGE->set_url('/user/profile.php', array('id'=>$userid));
@@ -93,7 +93,7 @@
}
if (!$currentpage->userid) {
- $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks
+ $context = context_system::instance(); // A trick so that we even see non-sticky blocks
}
$PAGE->set_context($context);
@@ -306,7 +306,7 @@
if ($mycourse->category) {
$class = '';
if ($mycourse->visible == 0) {
- $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
+ $ccontext = context_course::instance($mycourse->id);
if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
continue;
}
View
2  user/profile/field/checkbox/field.class.php
@@ -29,7 +29,7 @@ function edit_field_add($mform) {
$checkbox->setChecked(true);
}
$mform->setType($this->inputname, PARAM_BOOL);
- if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
}
}
View
2  user/profile/field/menu/field.class.php
@@ -80,7 +80,7 @@ function edit_field_set_locked($mform) {
if (!$mform->elementExists($this->inputname)) {
return;
}
- if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->hardFreeze($this->inputname);
$mform->setConstant($this->inputname, $this->datakey);
}
View
12 user/profile/lib.php
@@ -67,7 +67,7 @@ function display_data() {
function edit_field($mform) {
if ($this->field->visible != PROFILE_VISIBLE_NONE
- or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ or has_capability('moodle/user:update', context_system::instance())) {
$this->edit_field_add($mform);
$this->edit_field_set_default($mform);
@@ -85,7 +85,7 @@ function edit_field($mform) {
function edit_after_data($mform) {
if ($this->field->visible != PROFILE_VISIBLE_NONE
- or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ or has_capability('moodle/user:update', context_system::instance())) {
$this->edit_field_set_locked($mform);
return true;
}
@@ -183,7 +183,7 @@ function edit_field_set_locked($mform) {
if (!$mform->elementExists($this->inputname)) {
return;
}
- if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ if ($this->is_locked() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->hardFreeze($this->inputname);
$mform->setConstant($this->inputname, $this->data);
}
@@ -283,11 +283,11 @@ function is_visible() {
return true;
} else {
return has_capability('moodle/user:viewalldetails',
- get_context_instance(CONTEXT_USER, $this->userid));
+ context_user::instance($this->userid));
}
default:
return has_capability('moodle/user:viewalldetails',
- get_context_instance(CONTEXT_USER, $this->userid));
+ context_user::instance($this->userid));
}
}
@@ -359,7 +359,7 @@ function profile_definition($mform, $userid = 0) {
global $CFG, $DB;
// if user is "admin" fields are displayed regardless
- $update = has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
+ $update = has_capability('moodle/user:update', context_system::instance());
if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
foreach ($categories as $category) {
View
2  user/profilesys.php
@@ -37,7 +37,7 @@
require_login();
-$context = get_context_instance(CONTEXT_SYSTEM);
+$context = context_system::instance();
require_capability('moodle/my:configsyspages', $context);
$PAGE->set_blocks_editing_capability('moodle/my:configsyspages');
$header = "$SITE->shortname: ".get_string('publicprofile')." (".get_string('myprofile', 'admin').")";
View
2  user/renderer.php
@@ -84,7 +84,7 @@ class user_files_tree implements renderable {
public $dir;
public function __construct() {
global $USER;
- $this->context = get_context_instance(CONTEXT_USER, $USER->id);
+ $this->context = context_user::instance($USER->id);
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
}
View
2  user/repository.php
@@ -46,7 +46,7 @@
$pluginstr = get_string('plugin', 'repository');
require_login($course, false);
-$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+$coursecontext = context_course::instance($course->id, MUST_EXIST);
$link = new moodle_url('/user/view.php', array('id'=>$user->id));
$PAGE->navbar->add($fullname, $link);
View
6 user/selector/lib.php
@@ -98,7 +98,7 @@ public function __construct($name, $options = array()) {
if (isset($options['accesscontext'])) {
$this->accesscontext = $options['accesscontext'];
} else {
- $this->accesscontext = get_context_instance(CONTEXT_SYSTEM);
+ $this->accesscontext = context_system::instance();
}
if (isset($options['extrafields'])) {
@@ -676,7 +676,7 @@ protected function initialise_javascript($search) {
*/
public function __construct($name, $options) {
global $CFG;
- $options['accesscontext'] = get_context_instance(CONTEXT_COURSE, $options['courseid']);
+ $options['accesscontext'] = context_course::instance($options['courseid']);
parent::__construct($name, $options);
$this->groupid = $options['groupid'];
$this->courseid = $options['courseid'];
@@ -809,7 +809,7 @@ public function find_users($search) {
global $DB;
// Get list of allowed roles.
- $context = get_context_instance(CONTEXT_COURSE, $this->courseid);
+ $context = context_course::instance($this->courseid);
if ($validroleids = groups_get_possible_roles($context)) {
list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r');
} else {
View
2  user/selector/search.php
@@ -26,7 +26,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/user/selector/lib.php');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$PAGE->set_url('/user/selector/search.php');
// In developer debug mode, when there is a debug=1 in the URL send as plain text
View
8 user/view.php
@@ -46,9 +46,9 @@
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
$currentuser = ($user->id == $USER->id);
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-$usercontext = get_context_instance(CONTEXT_USER, $user->id, IGNORE_MISSING);
+$systemcontext = context_system::instance();
+$coursecontext = context_course::instance($course->id);
+$usercontext = context_user::instance($user->id, IGNORE_MISSING);
// Require login first
if (isguestuser($user)) {
@@ -288,7 +288,7 @@
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
- $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);;
+ $ccontext = context_course::instance($mycourse->id);;
$cfullname = format_string($mycourse->fullname, true, array('context' => $ccontext));
if ($mycourse->id != $course->id){
$class = '';
View
2  userpix/index.php
@@ -13,7 +13,7 @@
require_login();
/// Remove the following three lines if you want everyone to access it
-$syscontext = get_context_instance(CONTEXT_SYSTEM);
+$syscontext = context_system::instance();
require_capability('moodle/site:config', $syscontext);
$title = get_string("users");
View
2  webservice/externallib.php
@@ -71,7 +71,7 @@ public function get_site_info($serviceshortnames = array()) {
array('serviceshortnames'=>$serviceshortnames));
$profileimageurl = moodle_url::make_pluginfile_url(
- get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1');
+ context_user::instance($USER->id)->id, 'user', 'icon', NULL, '/', 'f1');
//site information
$siteinfo = array(
View
12 webservice/lib.php
@@ -102,7 +102,7 @@ public function authenticate_user($token) {
}
//Non admin can not authenticate if maintenance mode
- $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user);
+ $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
//this is usually temporary, client want to implement code logic => moodle_exception
throw new moodle_exception('sitemaintenance', 'admin');
@@ -116,7 +116,7 @@ public function authenticate_user($token) {
}
//check if there is any required system capability
- if ($service->requiredcapability and !has_capability($service->requiredcapability, get_context_instance(CONTEXT_SYSTEM), $user)) {
+ if ($service->requiredcapability and !has_capability($service->requiredcapability, context_system::instance(), $user)) {
throw new webservice_access_exception('The capability ' . $service->requiredcapability . ' is required.');
}
@@ -262,7 +262,7 @@ public function generate_user_ws_tokens($userid) {
global $CFG, $DB;
// generate a token for non admin if web service are enable and the user has the capability to create a token
- if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', get_context_instance(CONTEXT_SYSTEM), $userid) && !empty($CFG->enablewebservices)) {
+ if (!is_siteadmin() && has_capability('moodle/webservice:createtoken', context_system::instance(), $userid) && !empty($CFG->enablewebservices)) {
// for every service than the user is authorised on, create a token (if it doesn't already exist)
// get all services which are set to all user (no restricted to specific users)
@@ -298,7 +298,7 @@ public function generate_user_ws_tokens($userid) {
$newtoken->userid = $userid;
$newtoken->externalserviceid = $serviceid;
// TODO MDL-31190 find a way to get the context - UPDATE FOLLOWING LINE
- $newtoken->contextid = get_context_instance(CONTEXT_SYSTEM)->id;
+ $newtoken->contextid = context_system::instance()->id;
$newtoken->creatorid = $userid;
$newtoken->timecreated = time();
@@ -835,7 +835,7 @@ protected function authenticate_user() {
throw new webservice_access_exception('The web service authentication plugin is missing.');
}
- $this->restricted_context = get_context_instance(CONTEXT_SYSTEM);
+ $this->restricted_context = context_system::instance();
if (!$this->username) {
throw new moodle_exception('missingusername', 'webservice');
@@ -860,7 +860,7 @@ protected function authenticate_user() {
}
//Non admin can not authenticate if maintenance mode
- $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $user);
+ $hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
throw new moodle_exception('sitemaintenance', 'admin');
}
View
2  webservice/upload.php
@@ -51,7 +51,7 @@
$authenticationinfo = $webservicelib->authenticate_user($token);
// check the user can manage his own files (can upload)
-$context = get_context_instance(CONTEXT_USER, $USER->id);
+$context = context_user::instance($USER->id);
require_capability('moodle/user:manageownfiles', $context);
$fs = get_file_storage();
View
2  webservice/wsdoc.php
@@ -29,7 +29,7 @@
require_login();
require_sesskey();
-$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
+$usercontext = context_user::instance($USER->id);
$tokenid = required_param('id', PARAM_INT);
// PAGE settings
Please sign in to comment.
Something went wrong with that request. Please try again.