Permalink
Browse files

MDL-34471 libraries: Replace all uses of get_context_instance() with …

…respective context_XXXX::instance() method
  • Loading branch information...
1 parent 470d47f commit bf0f06b1beb2bc2f88b0391aeaa656b6b1fbc76f @ankitagarwal ankitagarwal committed Aug 2, 2012
Showing with 189 additions and 189 deletions.
  1. +1 −1 auth/fc/auth.php
  2. +3 −3 auth/ldap/auth.php
  3. +1 −1 auth/ldap/ntlmsso_attempt.php
  4. +1 −1 auth/ldap/ntlmsso_finish.php
  5. +1 −1 auth/ldap/ntlmsso_magic.php
  6. +3 −3 auth/mnet/auth.php
  7. +1 −1 auth/shibboleth/index.php
  8. +1 −1 comment/index.php
  9. +2 −2 completion/criteria/completion_criteria_course.php
  10. +1 −1 file.php
  11. +1 −1 group/assign.php
  12. +2 −2 group/autogroup.php
  13. +1 −1 group/autogroup_form.php
  14. +1 −1 group/delete.php
  15. +7 −7 group/externallib.php
  16. +1 −1 group/group.php
  17. +1 −1 group/grouping.php
  18. +1 −1 group/groupings.php
  19. +2 −2 group/import.php
  20. +1 −1 group/index.php
  21. +11 −11 group/lib.php
  22. +1 −1 group/members.php
  23. +1 −1 group/overview.php
  24. +1 −1 help.php
  25. +3 −3 index.php
  26. +2 −2 iplookup/index.php
  27. +2 −2 message/defaultoutputs.php
  28. +3 −3 message/edit.php
  29. +1 −1 message/externallib.php
  30. +2 −2 message/index.php
  31. +4 −4 message/lib.php
  32. +1 −1 message/search_advanced.html
  33. +4 −4 mod/forum/discuss.php
  34. +6 −6 mod/forum/index.php
  35. +59 −59 mod/forum/lib.php
  36. +2 −2 mod/forum/locallib.php
  37. +10 −10 mod/forum/post.php
  38. +1 −1 mod/forum/post_form.php
  39. +2 −2 mod/forum/search.php
  40. +1 −1 mod/forum/subscribe.php
  41. +1 −1 mod/forum/subscribers.php
  42. +1 −1 mod/forum/unsubscribeall.php
  43. +4 −4 mod/forum/user.php
  44. +2 −2 mod/forum/view.php
  45. +2 −2 mod/resource/lib.php
  46. +3 −3 mod/resource/locallib.php
  47. +1 −1 mod/resource/mod_form.php
  48. +1 −1 mod/resource/view.php
  49. +4 −4 my/index.php
  50. +1 −1 my/indexsys.php
  51. +4 −4 my/lib.php
  52. +2 −2 notes/delete.php
  53. +2 −2 notes/edit.php
  54. +1 −1 notes/externallib.php
  55. +8 −8 notes/index.php
  56. +2 −2 notes/lib.php
View
2 auth/fc/auth.php
@@ -180,7 +180,7 @@ function sync_roles($user) {
if ($roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
if ($iscreator) { // Following calls will not create duplicates
role_assign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc');
View
6 auth/ldap/auth.php
@@ -771,7 +771,7 @@ function sync_users($do_updates=true) {
if (!empty($users)) {
print_string('userentriestoupdate', 'auth_ldap', count($users));
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute)
and $roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
@@ -820,7 +820,7 @@ function sync_users($do_updates=true) {
if (!empty($add_users)) {
print_string('userentriestoadd', 'auth_ldap', count($add_users));
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute)
and $roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
@@ -1649,7 +1649,7 @@ function sync_roles($user) {
if ($roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = context_system::instance();
if ($iscreator) { // Following calls will not create duplicates
role_assign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth);
View
2 auth/ldap/ntlmsso_attempt.php
@@ -6,7 +6,7 @@
$PAGE->https_required();
$PAGE->set_url('/auth/ldap/ntlmsso_attempt.php');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
// Define variables used in page
$site = get_site();
View
2 auth/ldap/ntlmsso_finish.php
@@ -6,7 +6,7 @@
$PAGE->https_required();
$PAGE->set_url('/auth/ldap/ntlmsso_finish.php');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
// Define variables used in page
$site = get_site();
View
2 auth/ldap/ntlmsso_magic.php
@@ -11,7 +11,7 @@
//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$authsequence = get_enabled_auth_plugins(true); // auths, in sequence
if (!in_array('ldap', $authsequence, true)) {
View
6 auth/mnet/auth.php
@@ -81,7 +81,7 @@ function user_authorise($token, $useragent) {
if (array_key_exists('picture', $userdata) && !empty($user->picture)) {
$fs = get_file_storage();
- $usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
+ $usercontext = context_user::instance($user->id, MUST_EXIST);
if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$userdata['_mnet_userpicture_timemodified'] = $usericonfile->get_timemodified();
$userdata['_mnet_userpicture_mimetype'] = $usericonfile->get_mimetype();
@@ -299,7 +299,7 @@ function confirm_mnet_session($token, $remotepeer) {
if ($key == '_mnet_userpicture_timemodified' and empty($CFG->disableuserimages) and isset($remoteuser->picture)) {
// update the user picture if there is a newer verion at the identity provider
- $usercontext = get_context_instance(CONTEXT_USER, $localuser->id, MUST_EXIST);
+ $usercontext = context_user::instance($localuser->id, MUST_EXIST);
if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$localtimemodified = $usericonfile->get_timemodified();
} else if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.jpg')) {
@@ -1136,7 +1136,7 @@ function fetch_user_image($username) {
if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
$fs = get_file_storage();
- $usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
+ $usercontext = context_user::instance($user->id, MUST_EXIST);
$return = array();
if ($f1 = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$return['f1'] = base64_encode($f1->get_content());
View
2 auth/shibboleth/index.php
@@ -72,7 +72,7 @@
}
/// Go to my-moodle page instead of homepage if defaulthomepage enabled
- if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) {
+ if (!has_capability('moodle/site:config',context_system::instance()) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/';
}
View
2 comment/index.php
@@ -29,7 +29,7 @@
require_login();
admin_externalpage_setup('comments', '', null, '', array('pagelayout'=>'report'));
-$context = get_context_instance(CONTEXT_SYSTEM);
+$context = context_system::instance();
require_capability('moodle/comment:delete', $context);
$PAGE->requires->js_init_call('M.core_comment.init_admin', null, true);
View
4 completion/criteria/completion_criteria_course.php
@@ -135,7 +135,7 @@ public function get_title_detailed() {
global $DB;
$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
- $coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
+ $coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
return shorten_text(urldecode($fullname));
}
@@ -215,7 +215,7 @@ public function get_details($completion) {
$info = new completion_info($course);
$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
- $coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
+ $coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
$prereq_info = new completion_info($prereq);
View
2 file.php
@@ -83,7 +83,7 @@
}
}
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
$fs = get_file_storage();
View
2 group/assign.php
@@ -40,7 +40,7 @@
$courseid = $course->id;
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $courseid);
+$context = context_course::instance($courseid);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
View
4 group/autogroup.php
@@ -41,8 +41,8 @@
// Make sure that the user has permissions to manage groups.
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $courseid);
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$context = context_course::instance($courseid);
+$systemcontext = context_system::instance();
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id;
View
2 group/autogroup_form.php
@@ -59,7 +59,7 @@ function definition() {
$mform->setDefault('roleid', $student->id);
}
- $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+ $context = context_course::instance($COURSE->id);
if (has_capability('moodle/cohort:view', $context)) {
$options = cohort_get_visible_list($COURSE);
if ($options) {
View
2 group/delete.php
@@ -38,7 +38,7 @@
print_error('invalidcourseid');
}
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$changeidnumber = has_capability('moodle/course:changeidnumber', $context);
View
14 group/externallib.php
@@ -89,7 +89,7 @@ public static function create_groups($groups) {
}
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -168,7 +168,7 @@ public static function get_groups($groupids) {
$group = groups_get_group($groupid, 'id, courseid, name, description, descriptionformat, enrolmentkey', MUST_EXIST);
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -235,7 +235,7 @@ public static function get_course_groups($courseid) {
$params = self::validate_parameters(self::get_course_groups_parameters(), array('courseid'=>$courseid));
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $params['courseid']);
+ $context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -318,7 +318,7 @@ public static function delete_groups($groupids) {
}
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -376,7 +376,7 @@ public static function get_group_members($groupids) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -456,7 +456,7 @@ public static function add_group_members($members) {
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -534,7 +534,7 @@ public static function delete_group_members($members) {
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
View
2 group/group.php
@@ -71,7 +71,7 @@
}
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
View
2 group/grouping.php
@@ -63,7 +63,7 @@
$PAGE->set_url($url);
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
View
2 group/groupings.php
@@ -35,7 +35,7 @@
}
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$strgrouping = get_string('grouping', 'group');
View
4 group/import.php
@@ -35,7 +35,7 @@
$PAGE->set_url('/group/import.php', array('id'=>$id));
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $id);
+$context = context_course::instance($id);
require_capability('moodle/course:managegroups', $context);
@@ -160,7 +160,7 @@
if (isset($newgroup->courseid)) {
$linenum++;
$groupname = $newgroup->name;
- $newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid);
+ $newgrpcoursecontext = context_course::instance($newgroup->courseid);
///Users cannot upload groups in courses they cannot update.
if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext) or (!is_enrolled($newgrpcoursecontext) and !has_capability('moodle/course:view', $newgrpcoursecontext))) {
View
2 group/index.php
@@ -59,7 +59,7 @@
$PAGE->requires->yui2_lib('connection');
$PAGE->requires->js('/group/clientlib.js');
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
if (!has_capability('moodle/course:managegroups', $context)) {
redirect('/course/view.php', array('id'=>$course->id)); // Not allowed to manage all groups
}
View
22 group/lib.php
@@ -56,7 +56,7 @@ function groups_add_member($grouporid, $userorid) {
}
//check if the user a participant of the group course
- if (!is_enrolled(get_context_instance(CONTEXT_COURSE, $group->courseid), $userid)) {
+ if (!is_enrolled(context_course::instance($group->courseid), $userid)) {
return false;
}
@@ -140,7 +140,7 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {
//check that courseid exists
$course = $DB->get_record('course', array('id' => $data->courseid), '*', MUST_EXIST);
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
$data->timecreated = time();
$data->timemodified = $data->timecreated;
@@ -236,7 +236,7 @@ function groups_update_group_icon($group, $data, $editform) {
require_once("$CFG->libdir/gdlib.php");
$fs = get_file_storage();
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid, MUST_EXIST);
+ $context = context_course::instance($group->courseid, MUST_EXIST);
//TODO: it would make sense to allow picture deleting too (skodak)
@@ -264,7 +264,7 @@ function groups_update_group_icon($group, $data, $editform) {
function groups_update_group($data, $editform = false, $editoroptions = false) {
global $CFG, $DB;
- $context = get_context_instance(CONTEXT_COURSE, $data->courseid);
+ $context = context_course::instance($data->courseid);
$data->timemodified = time();
$data->name = trim($data->name);
@@ -353,7 +353,7 @@ function groups_delete_group($grouporid) {
$DB->delete_records('groups', array('id'=>$groupid));
// Delete all files associated with this group
- $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
+ $context = context_course::instance($group->courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group', 'description', $groupid);
$fs->delete_area_files($context->id, 'group', 'icon', $groupid);
@@ -393,7 +393,7 @@ function groups_delete_grouping($groupingorid) {
//group itself last
$DB->delete_records('groupings', array('id'=>$groupingid));
- $context = get_context_instance(CONTEXT_COURSE, $grouping->courseid);
+ $context = context_course::instance($grouping->courseid);
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'grouping', 'description', $groupingid);
foreach ($files as $file) {
@@ -484,15 +484,15 @@ function groups_delete_groups($courseid, $showfeedback=false) {
groups_delete_group_members($courseid, 0, $showfeedback);
// delete group pictures and descriptions
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');
// delete group calendar events
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
$DB->delete_records_select('event', "groupid IN ($groupssql)", array($courseid));
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');
@@ -529,7 +529,7 @@ function groups_delete_groupings($courseid, $showfeedback=false) {
$DB->set_field('course_modules', 'groupingid', 0, array('course'=>$courseid));
// Delete all files associated with groupings for this course
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'grouping');
@@ -574,7 +574,7 @@ function groups_get_possible_roles($context) {
function groups_get_potential_members($courseid, $roleid = null, $cohortid = null, $orderby = 'lastname ASC, firstname ASC') {
global $DB;
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
// we are looking for all users with this role assigned in this context or higher
$listofcontexts = get_related_contexts_string($context);
@@ -689,7 +689,7 @@ function groups_get_members_by_role($groupid, $courseid, $fields='u.*',
// Retrieve information about all users and their roles on the course or
// parent ('related') contexts
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
if ($extrawheretest) {
$extrawheretest = ' AND ' . $extrawheretest;
View
2 group/members.php
@@ -38,7 +38,7 @@
$PAGE->set_pagelayout('standard');
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
View
2 group/overview.php
@@ -49,7 +49,7 @@
// Make sure that the user has permissions to manage groups.
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $courseid);
+$context = context_course::instance($courseid);
require_capability('moodle/course:managegroups', $context);
$strgroups = get_string('groups');
View
2 help.php
@@ -44,7 +44,7 @@
$PAGE->set_url('/help.php');
$PAGE->set_pagelayout('popup');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
if ($ajax) {
@header('Content-Type: text/plain; charset=utf-8');
View
6 index.php
@@ -50,7 +50,7 @@
user_accesstime_log();
}
- $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+ $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
/// If the site is currently under maintenance, then print a message
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
@@ -128,7 +128,7 @@
echo '</font></p>';
}
- $context = get_context_instance(CONTEXT_COURSE, SITEID);
+ $context = context_course::instance(SITEID);
$summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
$summaryformatoptions = new stdClass();
$summaryformatoptions->noclean = true;
@@ -176,7 +176,7 @@
// fetch news forum context for proper filtering to happen
$newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
- $newsforumcontext = get_context_instance(CONTEXT_MODULE, $newsforumcm->id, MUST_EXIST);
+ $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
$forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
View
4 iplookup/index.php
@@ -41,7 +41,7 @@
$PAGE->set_url('/iplookup/index.php', array('id'=>$ip, 'user'=>$user));
$PAGE->set_pagelayout('popup');
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$info = array($ip);
$note = array();
@@ -68,7 +68,7 @@
if ($user) {
if ($user = $DB->get_record('user', array('id'=>$user, 'deleted'=>0))) {
// note: better not show full names to everybody
- if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_USER, $user->id))) {
+ if (has_capability('moodle/user:viewdetails', context_user::instance($user->id))) {
array_unshift($info['title'], fullname($user));
}
}
View
4 message/defaultoutputs.php
@@ -29,7 +29,7 @@
admin_externalpage_setup('defaultmessageoutputs');
// Require site configuration capability
-require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+require_capability('moodle/site:config', context_system::instance());
// Fetch processors
$processors = get_message_processors(true);
@@ -98,7 +98,7 @@
// Page settings
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$PAGE->requires->js_init_call('M.core_message.init_defaultoutputs');
// Grab the renderer
View
6 message/edit.php
@@ -59,9 +59,9 @@
print_error('invaliduserid');
}
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
-$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+$systemcontext = context_system::instance();
+$personalcontext = context_user::instance($user->id);
+$coursecontext = context_course::instance($course->id);
$PAGE->set_context($personalcontext);
$PAGE->set_pagelayout('course');
View
2 message/externallib.php
@@ -77,7 +77,7 @@ public static function send_instant_messages($messages = array()) {
}
// 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/site:sendmessage', $context);
View
4 message/index.php
@@ -82,14 +82,14 @@
$PAGE->set_url($url);
-$PAGE->set_context(get_context_instance(CONTEXT_USER, $USER->id));
+$PAGE->set_context(context_user::instance($USER->id));
$PAGE->navigation->extend_for_user($USER);
$PAGE->set_pagelayout('course');
// Disable message notification popups while the user is viewing their messages
$PAGE->set_popup_notification_allowed(false);
-$context = get_context_instance(CONTEXT_SYSTEM);
+$context = context_system::instance();
$user1 = null;
$currentuser = true;
View
8 message/lib.php
@@ -523,7 +523,7 @@ function message_get_course_contexts($courses) {
$coursecontexts = array();
foreach($courses as $course) {
- $coursecontexts[$course->id] = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontexts[$course->id] = context_course::instance($course->id);
}
return $coursecontexts;
@@ -1498,7 +1498,7 @@ function message_search_users($courseid, $searchtext, $sort='', $exceptions='')
$order", $params);
} else {
//TODO: add enabled enrolment join here (skodak)
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $context = context_course::instance($courseid);
$contextlists = get_related_contexts_string($context);
// everyone who has a role assignment in this course or higher
@@ -1535,7 +1535,7 @@ function message_search($searchterms, $fromme=true, $tome=true, $courseid='none'
global $CFG, $USER, $DB;
// If user is searching all messages check they are allowed to before doing anything else
- if ($courseid == SITEID && !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
+ if ($courseid == SITEID && !has_capability('moodle/site:readallmessages', context_system::instance())) {
print_error('accessdenied','admin');
}
@@ -2031,7 +2031,7 @@ function message_post_message($userfrom, $userto, $message, $format) {
$eventdata->smallmessage = $message;//store the message unfiltered. Clean up on output.
$s = new stdClass();
- $s->sitename = format_string($SITE->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $s->sitename = format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
$s->url = $CFG->wwwroot.'/message/index.php?user='.$userto->id.'&id='.$userfrom->id;
$emailtagline = get_string_manager()->get_string('emailtagline', 'message', $s, $userto->lang);
View
2 message/search_advanced.html
@@ -42,7 +42,7 @@
<tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" id="keywordsoption2" value="fromme" /><label for="keywordsoption2"><?php print_string('onlyfromme', 'message') ?></label></td></tr>
<tr><td>&nbsp;</td><td colspan="2"><input type="radio" checked="checked" name="keywordsoption" id="keywordsoption3" value="allmine" /><label for="keywordsoption3"><?php print_string('allmine', 'message') ?></label></td></tr>
- <?php if (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { ?>
+ <?php if (has_capability('moodle/site:readallmessages', context_system::instance())) { ?>
<tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" id="keywordsoption4" value="allusers" /><label for="keywordsoption4"><?php print_string('allusers', 'message') ?></label></td></tr>
<?php } ?>
View
8 mod/forum/discuss.php
@@ -54,13 +54,13 @@
// move this down fix for MDL-6926
require_once($CFG->dirroot.'/mod/forum/lib.php');
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum');
if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
require_once("$CFG->libdir/rsslib.php");
- $rsstitle = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . ': %fullname%';
+ $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': %fullname%';
rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle);
}
@@ -98,7 +98,7 @@
print_error('cannotmovenotvisible', 'forum', $return);
}
- require_capability('mod/forum:startdiscussion', get_context_instance(CONTEXT_MODULE,$cmto->id));
+ require_capability('mod/forum:startdiscussion', context_module::instance($cmto->id));
if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
@@ -229,7 +229,7 @@
$forumcheck = $DB->get_records('forum', array('course' => $course->id),'', 'id, type');
foreach ($modinfo->instances['forum'] as $forumcm) {
if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion',
- get_context_instance(CONTEXT_MODULE,$forumcm->id))) {
+ context_module::instance($forumcm->id))) {
continue;
}
$section = $forumcm->sectionnum;
View
12 mod/forum/index.php
@@ -46,7 +46,7 @@
require_course_login($course);
$PAGE->set_pagelayout('incourse');
-$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+$coursecontext = context_course::instance($course->id);
unset($SESSION->fromdiscussion);
@@ -129,7 +129,7 @@
$forum = $forums[$forumid];
- if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+ if (!$context = context_module::instance($cm->id)) {
continue; // Shouldn't happen
}
@@ -158,7 +158,7 @@
// Can proceed now, the user is not guest and is enrolled
foreach ($modinfo->instances['forum'] as $forumid=>$cm) {
$forum = $forums[$forumid];
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$cansub = false;
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
@@ -179,7 +179,7 @@
}
}
$returnto = forum_go_back_to("index.php?id=$course->id");
- $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
if ($subscribe) {
add_to_log($course->id, 'forum', 'subscribeall', "index.php?id=$course->id", $course->id);
redirect($returnto, get_string('nowallsubscribed', 'forum', $shortname), 1);
@@ -194,7 +194,7 @@
if ($generalforums) {
foreach ($generalforums as $forum) {
$cm = $modinfo->instances['forum'][$forum->id];
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$count = forum_count_discussions($forum, $cm, $course);
@@ -321,7 +321,7 @@
$currentsection = '';
foreach ($learningforums as $forum) {
$cm = $modinfo->instances['forum'][$forum->id];
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$count = forum_count_discussions($forum, $cm, $course);
View
118 mod/forum/lib.php
@@ -77,7 +77,7 @@ function forum_add_instance($forum, $mform = null) {
}
$forum->id = $DB->insert_record('forum', $forum);
- $modcontext = get_context_instance(CONTEXT_MODULE, $forum->coursemodule);
+ $modcontext = context_module::instance($forum->coursemodule);
if ($forum->type == 'single') { // Create related discussion.
$discussion = new stdClass();
@@ -87,7 +87,7 @@ function forum_add_instance($forum, $mform = null) {
$discussion->assessed = $forum->assessed;
$discussion->message = $forum->intro;
$discussion->messageformat = $forum->introformat;
- $discussion->messagetrust = trusttext_trusted(get_context_instance(CONTEXT_COURSE, $forum->course));
+ $discussion->messagetrust = trusttext_trusted(context_course::instance($forum->course));
$discussion->mailnow = false;
$discussion->groupid = -1;
@@ -191,7 +191,7 @@ function forum_update_instance($forum, $mform) {
}
$cm = get_coursemodule_from_instance('forum', $forum->id);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
+ $modcontext = context_module::instance($cm->id, MUST_EXIST);
if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
// ugly hack - we need to copy the files somehow
@@ -244,7 +244,7 @@ function forum_delete_instance($id) {
return false;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
// now get rid of all files
$fs = get_file_storage();
@@ -509,7 +509,7 @@ function forum_cron() {
// caching subscribed users of each forum
if (!isset($subscribedusers[$forumid])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $coursemodules[$forumid]->id);
+ $modcontext = context_module::instance($coursemodules[$forumid]->id);
if ($subusers = forum_subscribed_users($courses[$courseid], $forums[$forumid], 0, $modcontext, "u.*")) {
foreach ($subusers as $postuser) {
// this user is subscribed to this forum
@@ -620,11 +620,11 @@ function forum_cron() {
// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$userto->viewfullnames[$forum->id] = has_capability('moodle/site:viewfullnames', $modcontext);
}
if (!isset($userto->canpost[$discussion->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$userto->canpost[$discussion->id] = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext);
}
if (!isset($userfrom->groups[$forum->id])) {
@@ -691,7 +691,7 @@ function forum_cron() {
$userfrom->customheaders[] = 'References: '.forum_get_email_message_id($post->parent, $userto->id, $hostname);
}
- $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$postsubject = html_to_text("$shortname: ".format_string($post->subject, true));
$posttext = forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto);
@@ -903,18 +903,18 @@ function forum_cron() {
// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$userto->viewfullnames[$forum->id] = has_capability('moodle/site:viewfullnames', $modcontext);
}
if (!isset($userto->canpost[$discussion->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$userto->canpost[$discussion->id] = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext);
}
$strforums = get_string('forums', 'forum');
$canunsubscribe = ! forum_is_forcesubscribed($forum);
$canreply = $userto->canpost[$discussion->id];
- $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$posttext .= "\n \n";
$posttext .= '=====================================================================';
@@ -1074,7 +1074,7 @@ function forum_cron() {
function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $bare = false) {
global $CFG, $USER;
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!isset($userto->viewfullnames[$forum->id])) {
$viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
@@ -1101,7 +1101,7 @@ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfro
$posttext = '';
if (!$bare) {
- $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$posttext = "$shortname -> $strforums -> ".format_string($forum->name,true);
if ($discussion->name != $forum->name) {
@@ -1165,7 +1165,7 @@ function forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfro
$strforums = get_string('forums', 'forum');
$canunsubscribe = ! forum_is_forcesubscribed($forum);
- $shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$posthtml = '<head>';
/* foreach ($CFG->stylesheets as $stylesheet) {
@@ -1477,7 +1477,7 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
if (!$cm->uservisible) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $context)) {
continue;
@@ -1902,7 +1902,7 @@ function forum_get_readable_forums($userid, $courseid=0) {
if (!$cm->uservisible or !isset($courseforums[$forumid])) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$forum = $courseforums[$forumid];
$forum->context = $context;
$forum->cm = $cm;
@@ -2205,7 +2205,7 @@ function forum_get_user_posts($forumid, $userid) {
if (!empty($CFG->forum_enabletimedposts)) {
$cm = get_coursemodule_from_instance('forum', $forumid);
- if (!has_capability('mod/forum:viewhiddentimedposts' , get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (!has_capability('mod/forum:viewhiddentimedposts' , context_module::instance($cm->id))) {
$now = time();
$timedsql = "AND (d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?))";
$params[] = $now;
@@ -2241,7 +2241,7 @@ function forum_get_user_involved_discussions($forumid, $userid) {
$params = array($forumid, $userid);
if (!empty($CFG->forum_enabletimedposts)) {
$cm = get_coursemodule_from_instance('forum', $forumid);
- if (!has_capability('mod/forum:viewhiddentimedposts' , get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (!has_capability('mod/forum:viewhiddentimedposts' , context_module::instance($cm->id))) {
$now = time();
$timedsql = "AND (d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?))";
$params[] = $now;
@@ -2274,7 +2274,7 @@ function forum_count_user_posts($forumid, $userid) {
$params = array($forumid, $userid);
if (!empty($CFG->forum_enabletimedposts)) {
$cm = get_coursemodule_from_instance('forum', $forumid);
- if (!has_capability('mod/forum:viewhiddentimedposts' , get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (!has_capability('mod/forum:viewhiddentimedposts' , context_module::instance($cm->id))) {
$now = time();
$timedsql = "AND (d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?))";
$params[] = $now;
@@ -2464,7 +2464,7 @@ function forum_count_discussions($forum, $cm, $course) {
return $cache[$course->id][$forum->id];
}
- if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id))) {
return $cache[$course->id][$forum->id];
}
@@ -2576,7 +2576,7 @@ function forum_get_discussions($cm, $forumsort="d.timemodified DESC", $fullpost=
$now = round(time(), -2);
$params = array($cm->instance);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $modcontext)) { /// User must have perms to view discussions
return array();
@@ -2612,7 +2612,7 @@ function forum_get_discussions($cm, $forumsort="d.timemodified DESC", $fullpost=
if ($groupmode) {
if (empty($modcontext)) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
@@ -2687,7 +2687,7 @@ function forum_get_discussions_unread($cm) {
$currentgroup = groups_get_activity_group($cm);
if ($groupmode) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($currentgroup) {
@@ -2757,7 +2757,7 @@ function forum_get_discussions_count($cm) {
$currentgroup = groups_get_activity_group($cm);
if ($groupmode) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($currentgroup) {
@@ -2786,7 +2786,7 @@ function forum_get_discussions_count($cm) {
if (!empty($CFG->forum_enabletimedposts)) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewhiddentimedposts', $modcontext)) {
$timelimit = " AND ((d.timestart <= ? AND (d.timeend = 0 OR d.timeend > ?))";
@@ -2914,7 +2914,7 @@ function forum_subscribed_users($course, $forum, $groupid=0, $context = null, $f
if (empty($context)) {
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
if (forum_is_forcesubscribed($forum)) {
@@ -3047,7 +3047,7 @@ function forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfro
global $CFG, $OUTPUT;
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!isset($userto->viewfullnames[$forum->id])) {
$viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
@@ -3182,7 +3182,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
// String cache
static $str;
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$post->course = $course->id;
$post->forum = $forum->id;
@@ -3577,7 +3577,7 @@ function forum_rating_validate($params) {
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id , false, MUST_EXIST);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
// Make sure the context provided is the context of the forum
if ($context->id != $params['context']->id) {
@@ -3669,7 +3669,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
print_error('invalidcoursemodule');
}
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
}
if (!isset($rowcount)) {
@@ -3933,8 +3933,8 @@ function forum_move_attachments($discussion, $forumfrom, $forumto) {
$newcm = get_coursemodule_from_instance('forum', $forumto);
$oldcm = get_coursemodule_from_instance('forum', $forumfrom);
- $newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id);
- $oldcontext = get_context_instance(CONTEXT_MODULE, $oldcm->id);
+ $newcontext = context_module::instance($newcm->id);
+ $oldcontext = context_module::instance($oldcm->id);
// loop through all posts, better not use attachment flag ;-)
if ($posts = $DB->get_records('forum_posts', array('discussion'=>$discussion->id), '', 'id, attachment')) {
@@ -3980,7 +3980,7 @@ function forum_print_attachments($post, $cm, $type) {
return $type !== 'separateimages' ? '' : array('', '');
}
- if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+ if (!$context = context_module::instance($cm->id)) {
return $type !== 'separateimages' ? '' : array('', '');
}
$strattachment = get_string('attachment', 'forum');
@@ -4257,7 +4257,7 @@ function forum_add_attachment($post, $forum, $cm, $mform=null, &$message=null) {
return true; // Nothing to do
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$info = file_get_draft_area_info($post->attachments);
$present = ($info['filecount']>0) ? '1' : '';
@@ -4286,7 +4286,7 @@ function forum_add_new_post($post, $mform, &$message) {
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
$forum = $DB->get_record('forum', array('id' => $discussion->forum));
$cm = get_coursemodule_from_instance('forum', $forum->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$post->created = $post->modified = time();
$post->mailed = "0";
@@ -4330,7 +4330,7 @@ function forum_update_post($post, $mform, &$message) {
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
$forum = $DB->get_record('forum', array('id' => $discussion->forum));
$cm = get_coursemodule_from_instance('forum', $forum->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$post->modified = time();
@@ -4410,7 +4410,7 @@ function forum_add_discussion($discussion, $mform=null, &$message=null, $userid=
// TODO: Fix the calling code so that there always is a $cm when this function is called
if (!empty($cm->id) && !empty($discussion->itemid)) { // In "single simple discussions" this may not exist yet
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id,
mod_forum_post_form::editor_options(), $post->message);
$DB->set_field('forum_posts', 'message', $text, array('id'=>$post->id));
@@ -4511,7 +4511,7 @@ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompleti
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if ($children !== 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent'=>$post->id)))) {
if ($children) {
@@ -4791,7 +4791,7 @@ function forum_post_subscription($post, $forum) {
return "";
} elseif (($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE)
- && !has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $forum->course), $USER->id)) {
+ && !has_capability('moodle/course:manageactivities', context_course::instance($forum->course), $USER->id)) {
if ($subscribed) {
$action = 'unsubscribe'; // sanity check, following MDL-14558
} else {
@@ -5066,7 +5066,7 @@ function forum_user_can_post_discussion($forum, $currentgroup=null, $unused=-1,
}
if (!$context) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
if ($currentgroup === null) {
@@ -5159,7 +5159,7 @@ function forum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $course=
}
if (!$context) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
// normal users with temporary guest access can not post, suspended users can not post either
@@ -5224,7 +5224,7 @@ function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $use
$user = $USER;
}
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $modcontext)) {
return false;
}
@@ -5332,8 +5332,8 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
$user = $USER;
}
- $canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_MODULE, $cm->id), $user->id);
- if (!$canviewdiscussion && !has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), get_context_instance(CONTEXT_USER, $post->userid))) {
+ $canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', context_module::instance($cm->id), $user->id);
+ if (!$canviewdiscussion && !has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), context_user::instance($post->userid))) {
return false;
}
@@ -5349,7 +5349,7 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
if ($forum->type == 'qanda') {
$firstpost = forum_get_firstpost_from_discussion($discussion->id);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$userfirstpost = forum_get_user_posted_time($discussion->id, $user->id);
return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) ||
@@ -5385,7 +5385,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $di
print_error('invalidcoursemodule');
}
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if (empty($sort)) {
$sort = "d.timemodified DESC";
@@ -5614,7 +5614,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $di
if ($discussion->replies) {
$link = true;
} else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$link = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
}
@@ -5672,7 +5672,7 @@ function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode,
$ownpost = (isloggedin() && $USER->id == $post->userid);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if ($canreply === NULL) {
$reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
} else {
@@ -5819,7 +5819,7 @@ function forum_print_posts_threaded($course, &$cm, $forum, $discussion, $parent,
if (!empty($posts[$parent->id]->children)) {
$posts = $posts[$parent->id]->children;
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$canviewfullnames = has_capability('moodle/site:viewfullnames', $modcontext);
foreach ($posts as $post) {
@@ -5951,7 +5951,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
}
$groupmode = groups_get_activity_groupmode($cm, $course);
- $cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cm_context = context_module::instance($cm->id);
$viewhiddentimed = has_capability('mod/forum:viewhiddentimedposts', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
@@ -6610,7 +6610,7 @@ function forum_tp_count_forum_unread_posts($cm, $course) {
return $readcache[$course->id][$forumid];
}
- if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id))) {
return $readcache[$course->id][$forumid];
}
@@ -6995,7 +6995,7 @@ function forum_check_throttling($forum, $cm=null) {
}
}
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if(has_capability('mod/forum:postwithoutthrottling', $modcontext)) {
return true;
}
@@ -7128,7 +7128,7 @@ function forum_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_forum', 'attachment');
$fs->delete_area_files($context->id, 'mod_forum', 'post');
@@ -7175,7 +7175,7 @@ function forum_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
//remove ratings
$ratingdeloptions->contextid = $context->id;
@@ -7308,7 +7308,7 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
$forum->type = 'general';
$DB->update_record('forum', $forum);
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
// Create overrides for default student and guest roles (prevent).
foreach ($studentroles as $studentrole) {
@@ -7362,7 +7362,7 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
$cmid = $cm->id;
}
}
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
// $forum->open defines what students can do:
// 0 = No discussions, no replies
@@ -7602,7 +7602,7 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
$forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
if (empty($PAGE->cm->context)) {
- $PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
+ $PAGE->cm->context = context_module::instance($PAGE->cm->instance);
}
// for some actions you need to be enrolled, beiing admin is not enough sometimes here
@@ -8104,15 +8104,15 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false,
// Checkout whether or not the current user has capabilities over the requested
// user and if so they have the capabilities required to view the requested
// users content.
- $usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
+ $usercontext = context_user::instance($user->id, MUST_EXIST);
$hascapsonuser = !$iscurrentuser && $DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id));
$hascapsonuser = $hascapsonuser && has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), $usercontext);
// Before we actually search each course we need to check the user's access to the
// course. If the user doesn't have the appropraite access then we either throw an
// error if a particular course was requested or we just skip over the course.
foreach ($courses as $course) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+ $coursecontext = context_course::instance($course->id, MUST_EXIST);
if ($iscurrentuser || $hascapsonuser) {
// If it is the current user, or the current user has capabilities to the
// requested user then all we need to do is check the requested users
View
4 mod/forum/locallib.php
@@ -91,7 +91,7 @@ public function load_data() {
throw new portfolio_caller_exception('invalidcoursemodule');
}
- $this->modcontext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $this->modcontext = context_module::instance($this->cm->id);
$fs = get_file_storage();
if ($this->post) {
if ($this->attachment) {
@@ -372,7 +372,7 @@ function expected_time() {
* @return bool
*/
function check_permissions() {
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ $context = context_module::instance($this->cm->id);
if ($this->post) {
return (has_capability('mod/forum:exportpost', $context)
|| ($this->post->userid == $this->user->id
View
20 mod/forum/post.php
@@ -49,7 +49,7 @@
//these page_params will be passed as hidden variables later in the form.
$page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
-$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+$sitecontext = context_system::instance();
if (!isloggedin() or isguestuser()) {
@@ -80,7 +80,7 @@
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
print_error('invalidcoursemodule');
} else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
}
$PAGE->set_cm($cm, $course, $forum);
@@ -107,7 +107,7 @@
print_error("invalidcoursemodule");
}
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
if (!isguestuser()) {
@@ -175,8 +175,8 @@
// Ensure lang, theme, etc. is set up properly. MDL-6926
$PAGE->set_cm($cm, $course, $forum);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $coursecontext = context_course::instance($course->id);
+ $modcontext = context_module::instance($cm->id);
if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
if (!isguestuser()) {
@@ -252,7 +252,7 @@
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
print_error('invalidcoursemodule');
} else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
}
$PAGE->set_cm($cm, $course, $forum);
@@ -299,7 +299,7 @@
}
require_login($course, false, $cm);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if ( !(($post->userid == $USER->id && has_capability('mod/forum:deleteownpost', $modcontext))
|| has_capability('mod/forum:deleteanypost', $modcontext)) ) {
@@ -416,7 +416,7 @@
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
print_error('invalidcoursemodule');
} else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
}
if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
print_error('cannotsplit', 'forum');
@@ -484,7 +484,7 @@
if (!isset($coursecontext)) {
// Has not yet been set by post.php.
- $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
+ $coursecontext = context_course::instance($forum->course);
}
@@ -493,7 +493,7 @@
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
print_error('invalidcoursemodule');
}
-$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+$modcontext = context_module::instance($cm->id);
require_login($course, false, $cm);
if (isguestuser()) {
View
2 mod/forum/post_form.php
@@ -138,7 +138,7 @@ function definition() {
if (groups_get_activity_groupmode($cm, $course)) { // hack alert
$groupdata = groups_get_activity_allowed_groups($cm);
$groupcount = count($groupdata);
- $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modulecontext = context_module::instance($cm->id);
$contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
if ($contextcheck) {
$groupinfo = array('0' => get_string('allparticipants'));
View
4 mod/forum/search.php
@@ -241,7 +241,7 @@
//add the ratings information to the post
//Unfortunately seem to have do this individually as posts may be from different forums
if ($forum->assessed != RATING_AGGREGATE_NONE) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
$ratingoptions->context = $modcontext;
$ratingoptions->items = array($post);
$ratingoptions->aggregate = $forum->assessed;//the aggregation method
@@ -454,7 +454,7 @@ function forum_menu_list($course) {
if (!$cm->uservisible) {
continue;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $context)) {
continue;
}
View
2 mod/forum/subscribe.php
@@ -55,7 +55,7 @@
$forum = $DB->get_record('forum', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
if ($user) {
require_sesskey();
View
2 mod/forum/subscribers.php
@@ -47,7 +47,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewsubscribers', $context)) {
print_error('nopermissiontosubscribe', 'forum');
}
View
2 mod/forum/unsubscribeall.php
@@ -27,7 +27,7 @@
$confirm = optional_param('confirm', false, PARAM_BOOL);
$PAGE->set_url('/mod/forum/unsubscribeall.php');
-$PAGE->set_context(get_context_instance(CONTEX