From 55bcef2954b589279379a0f3c2fbc852029d0c3e Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 23 Jul 2012 16:08:41 +0800 Subject: [PATCH] MDL-34461 Librairies: Replaced deprecated get_context_instance() --- enrol/ajax.php | 2 +- enrol/authorize/localfuncs.php | 8 ++++---- enrol/authorize/locallib.php | 10 +++++----- enrol/authorize/uploadcsv.php | 6 +++--- enrol/bulkchange.php | 2 +- enrol/category/locallib.php | 12 ++++++------ enrol/cohort/addinstance.php | 2 +- enrol/cohort/addinstance_form.php | 2 +- enrol/cohort/ajax.php | 2 +- enrol/cohort/lib.php | 4 ++-- enrol/cohort/settings.php | 2 +- enrol/database/lib.php | 6 +++--- enrol/database/settings.php | 2 +- enrol/externallib.php | 8 ++++---- enrol/flatfile/lib.php | 2 +- enrol/guest/addinstance.php | 2 +- enrol/guest/lib.php | 8 ++++---- enrol/imsenterprise/importnow.php | 4 ++-- enrol/imsenterprise/lib.php | 2 +- enrol/imsenterprise/settings.php | 2 +- enrol/index.php | 2 +- enrol/instances.php | 2 +- enrol/ldap/lib.php | 4 ++-- enrol/locallib.php | 2 +- enrol/manual/ajax.php | 2 +- enrol/manual/edit.php | 2 +- enrol/manual/editenrolment.php | 2 +- enrol/manual/externallib.php | 2 +- enrol/manual/lib.php | 8 ++++---- enrol/manual/manage.php | 2 +- enrol/manual/settings.php | 2 +- enrol/manual/unenrolself.php | 2 +- enrol/meta/addinstance.php | 2 +- enrol/meta/addinstance_form.php | 4 ++-- enrol/meta/lib.php | 2 +- enrol/mnet/addinstance.php | 2 +- enrol/mnet/addinstance_form.php | 2 +- enrol/mnet/enrol.php | 2 +- enrol/mnet/lib.php | 4 ++-- enrol/mnet/settings.php | 2 +- enrol/otherusers.php | 2 +- enrol/paypal/edit.php | 2 +- enrol/paypal/ipn.php | 4 ++-- enrol/paypal/lib.php | 8 ++++---- enrol/paypal/return.php | 2 +- enrol/paypal/settings.php | 2 +- enrol/paypal/unenrolself.php | 2 +- enrol/self/edit.php | 2 +- enrol/self/editenrolment.php | 2 +- enrol/self/lib.php | 10 +++++----- enrol/self/settings.php | 2 +- enrol/self/unenrolself.php | 2 +- enrol/users.php | 2 +- enrol/users_forms.php | 4 ++-- 54 files changed, 93 insertions(+), 93 deletions(-) diff --git a/enrol/ajax.php b/enrol/ajax.php index 8a0bdfc09a7..0460061e2e3 100644 --- a/enrol/ajax.php +++ b/enrol/ajax.php @@ -40,7 +40,7 @@ $action = required_param('action', PARAM_ACTION); $PAGE->set_url(new moodle_url('/enrol/ajax.php', array('id'=>$id, 'action'=>$action))); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { throw new moodle_exception('invalidcourse'); diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php index 6a5a1e57452..f6b2935329d 100644 --- a/enrol/authorize/localfuncs.php +++ b/enrol/authorize/localfuncs.php @@ -206,7 +206,7 @@ function send_welcome_messages($orderdata) { $sender = get_admin(); } else { - $context = get_context_instance(CONTEXT_COURSE, $ei->courseid); + $context = context_course::instance($ei->courseid); $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1'); $sender = array_shift($paymentmanagers); } @@ -217,7 +217,7 @@ function send_welcome_messages($orderdata) { $lastuserid = $ei->userid; while ($ei && $ei->userid == $lastuserid) { - $context = get_context_instance(CONTEXT_COURSE, $ei->courseid); + $context = context_course::instance($ei->courseid); $usercourses[] = format_string($ei->fullname, true, array('context' => $context)); if (!$rs->valid()) { break; @@ -233,7 +233,7 @@ function send_welcome_messages($orderdata) { $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid"; $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid"; $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a); - $subject = get_string("enrolmentnew", 'enrol', format_string($SITE->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)))); + $subject = get_string("enrolmentnew", 'enrol', format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)))); $eventdata = new stdClass(); $eventdata->modulename = 'moodle'; @@ -269,7 +269,7 @@ function authorize_verify_account() { $original_antest = $plugin->get_config('an_test'); $plugin->set_config('an_test', 1); // Test mode - $shortname = format_string($SITE->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))); + $shortname = format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID))); $order = new stdClass(); $order->id = -1; diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php index 058b1b08d15..6dc03e2d792 100644 --- a/enrol/authorize/locallib.php +++ b/enrol/authorize/locallib.php @@ -54,7 +54,7 @@ function authorize_print_orders($courseid, $userid) { $searchtype = optional_param('searchtype', 'orderid', PARAM_ALPHA); $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); - $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $coursecontext = context_course::instance($courseid); $searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour); $buttons = "
"; @@ -63,7 +63,7 @@ function authorize_print_orders($courseid, $userid) { $buttons .= ""; $buttons .= "
"; - if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) { + if (has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) { $buttons .= "
"; } @@ -275,7 +275,7 @@ function authorize_print_order($orderid) print_error('nousers', '', "$CFG->wwwroot/enrol/authorize/index.php"); } - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); if ($USER->id != $order->userid) { // Current user viewing someone else's order require_capability('enrol/authorize:managepayments', $coursecontext); } @@ -288,7 +288,7 @@ function authorize_print_order($orderid) if (empty($do)) { if (empty($statusandactions->actions)) { - if ((AN_METHOD_ECHECK == $order->paymentmethod) && has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) { + if ((AN_METHOD_ECHECK == $order->paymentmethod) && has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) { $buttons .= "
"; } } @@ -574,7 +574,7 @@ function authorize_get_status_action($order) $ret = new stdClass(); $ret->actions = array(); - $canmanage = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $order->courseid)); + $canmanage = has_capability('enrol/authorize:managepayments', context_course::instance($order->courseid)); if (floatval($order->transid) == 0) { // test transaction or new order if ($order->timecreated < $newordertime) { diff --git a/enrol/authorize/uploadcsv.php b/enrol/authorize/uploadcsv.php index 95c940bb9e0..d21cfb9a5d1 100644 --- a/enrol/authorize/uploadcsv.php +++ b/enrol/authorize/uploadcsv.php @@ -33,7 +33,7 @@ require_once('import_form.php'); /// Require capabilities require_login(); -require_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_SYSTEM)); +require_capability('enrol/authorize:uploadcsv', context_system::instance()); /// Print header $struploadcsv = get_string('uploadcsv', 'enrol_authorize'); @@ -202,7 +202,7 @@ function authorize_process_csv($filename) { $ignoredlines .= $transid . ": Could not find this course: " . $order->courseid . "\n"; continue; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id, IGNORE_MISSING); if (!$coursecontext) { $ignored++; $ignoredlines .= $transid . ": Could not find course context: " . $order->courseid . "\n"; @@ -248,7 +248,7 @@ function authorize_process_csv($filename) { $eventdata->name = 'authorize_enrolment'; $eventdata->userfrom = $admin; $eventdata->userto = $admin; - $eventdata->subject = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))).': Authorize.net CSV ERROR LOG'; + $eventdata->subject = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID))).': Authorize.net CSV ERROR LOG'; $eventdata->fullmessage = $ignoredlines; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; diff --git a/enrol/bulkchange.php b/enrol/bulkchange.php index d033a56ed67..a07130e4ffb 100644 --- a/enrol/bulkchange.php +++ b/enrol/bulkchange.php @@ -36,7 +36,7 @@ $action = optional_param('action', '', PARAM_ACTION); $filter = optional_param('ifilter', 0, PARAM_INT); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { redirect(new moodle_url('/')); diff --git a/enrol/category/locallib.php b/enrol/category/locallib.php index 6a7671b7dbd..b44f9d8323b 100644 --- a/enrol/category/locallib.php +++ b/enrol/category/locallib.php @@ -48,7 +48,7 @@ class enrol_category_handler { // make sure the role is to be actually synchronised // please note we are ignoring overrides of the synchronised capability (for performance reasons in full sync) - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); if (!$DB->record_exists('role_capabilities', array('contextid'=>$syscontext->id, 'roleid'=>$ra->roleid, 'capability'=>'enrol/category:synchronised', 'permission'=>CAP_ALLOW))) { return true; } @@ -98,7 +98,7 @@ class enrol_category_handler { } // now this is going to be a bit slow, take all enrolments in child courses and verify each separately - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); if (!$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext)) { return true; } @@ -117,7 +117,7 @@ class enrol_category_handler { $params['userid'] = $ra->userid; foreach ($rs as $instance) { - $coursecontext = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $coursecontext = context_course::instance($instance->courseid); $contextids = get_parent_contexts($coursecontext); array_pop($contextids); // remove system context, we are interested in categories only @@ -152,7 +152,7 @@ function enrol_category_sync_course($course) { $plugin = enrol_get_plugin('category'); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); $roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext); if (!$roles) { @@ -166,7 +166,7 @@ function enrol_category_sync_course($course) { } // first find out if any parent category context contains interesting role assignments - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $contextids = get_parent_contexts($coursecontext); array_pop($contextids); // remove system context, we are interested in categories only @@ -246,7 +246,7 @@ function enrol_category_sync_full() { $plugin = enrol_get_plugin('category'); - $syscontext = get_context_instance(CONTEXT_SYSTEM); + $syscontext = context_system::instance(); // any interesting roles worth synchronising? if (!$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext)) { diff --git a/enrol/cohort/addinstance.php b/enrol/cohort/addinstance.php index bafb7167016..ebb06fca87f 100644 --- a/enrol/cohort/addinstance.php +++ b/enrol/cohort/addinstance.php @@ -31,7 +31,7 @@ require_once("$CFG->dirroot/enrol/cohort/locallib.php"); $id = required_param('id', PARAM_INT); // course id $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('moodle/course:enrolconfig', $context); diff --git a/enrol/cohort/addinstance_form.php b/enrol/cohort/addinstance_form.php index 7e157559fb3..e9015a2883c 100644 --- a/enrol/cohort/addinstance_form.php +++ b/enrol/cohort/addinstance_form.php @@ -34,7 +34,7 @@ class enrol_cohort_addinstance_form extends moodleform { $mform = $this->_form; $course = $this->_customdata; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $enrol = enrol_get_plugin('cohort'); diff --git a/enrol/cohort/ajax.php b/enrol/cohort/ajax.php index e65d1ed8456..48dbe96db4a 100644 --- a/enrol/cohort/ajax.php +++ b/enrol/cohort/ajax.php @@ -40,7 +40,7 @@ $action = required_param('action', PARAM_ACTION); $PAGE->set_url(new moodle_url('/enrol/cohort/ajax.php', array('id'=>$id, 'action'=>$action))); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { throw new moodle_exception('invalidcourse'); diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index 20098671f71..9f986f9e238 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -47,7 +47,7 @@ class enrol_cohort_plugin extends enrol_plugin { } else if (empty($instance->name)) { $enrol = $this->get_name(); if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) { - $role = role_get_name($role, get_context_instance(CONTEXT_COURSE, $instance->courseid)); + $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)); return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($DB->get_field('cohort', 'name', array('id'=>$instance->customint1))) . ' - ' . $role .')'; } else { return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($DB->get_field('cohort', 'name', array('id'=>$instance->customint1))) . ')'; @@ -81,7 +81,7 @@ class enrol_cohort_plugin extends enrol_plugin { protected function can_add_new_instances($courseid) { global $DB; - $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $coursecontext = context_course::instance($courseid); if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) { return false; } diff --git a/enrol/cohort/settings.php b/enrol/cohort/settings.php index 8bfc71c5894..db9702a7eed 100644 --- a/enrol/cohort/settings.php +++ b/enrol/cohort/settings.php @@ -33,7 +33,7 @@ if ($ADMIN->fulltree) { //--- enrol instance defaults ---------------------------------------------------------------------------- if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_cohort/roleid', diff --git a/enrol/database/lib.php b/enrol/database/lib.php index 1755a89df19..e53600b15fb 100644 --- a/enrol/database/lib.php +++ b/enrol/database/lib.php @@ -214,7 +214,7 @@ class enrol_database_plugin extends enrol_plugin { $this->enrol_user($instance, $user->id, $roleid, 0, 0, ENROL_USER_ACTIVE); } - if (!$context = get_context_instance(CONTEXT_COURSE, $instance->courseid)) { + if (!$context = context_course::instance($instance->courseid, IGNORE_MISSING)) { //weird continue; } @@ -247,7 +247,7 @@ class enrol_database_plugin extends enrol_plugin { continue; } - if (!$context = get_context_instance(CONTEXT_COURSE, $instance->courseid)) { + if (!$context = context_course::instance($instance->courseid, IGNORE_MISSING)) { //weird continue; } @@ -416,7 +416,7 @@ class enrol_database_plugin extends enrol_plugin { if (!$instance = $DB->get_record('enrol', array('id'=>$course->enrolid))) { continue; //weird } - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); // get current list of enrolled users with their roles $current_roles = array(); diff --git a/enrol/database/settings.php b/enrol/database/settings.php index 369bd3952ea..3b45e8dc9d1 100644 --- a/enrol/database/settings.php +++ b/enrol/database/settings.php @@ -81,7 +81,7 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configtext('enrol_database/remoterolefield', get_string('remoterolefield', 'enrol_database'), get_string('remoterolefield_desc', 'enrol_database'), '')); if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_database/defaultrole', get_string('defaultrole', 'enrol_database'), get_string('defaultrole_desc', 'enrol_database'), $student->id, $options)); diff --git a/enrol/externallib.php b/enrol/externallib.php index 1b842cca39c..ae969d6b494 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -73,7 +73,7 @@ class core_enrol_external extends external_api { $result = array(); foreach ($courses as $course) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id, IGNORE_MISSING); try { self::validate_context($context); } catch (Exception $e) { @@ -195,7 +195,7 @@ class core_enrol_external extends external_api { } $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); - $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $coursecontext = context_course::instance($courseid, IGNORE_MISSING); if ($courseid == SITEID) { $context = get_system_context(); } else { @@ -531,9 +531,9 @@ class moodle_enrol_external extends external_api { 'onlyactive'=>$onlyactive) ); - $coursecontext = get_context_instance(CONTEXT_COURSE, $params['courseid']); + $coursecontext = context_course::instance($params['courseid'], IGNORE_MISSING); if ($courseid == SITEID) { - $context = get_context_instance(CONTEXT_SYSTEM); + $context = context_system::instance(); } else { $context = $coursecontext; } diff --git a/enrol/flatfile/lib.php b/enrol/flatfile/lib.php index 73762e29acd..3c839d0854c 100644 --- a/enrol/flatfile/lib.php +++ b/enrol/flatfile/lib.php @@ -229,7 +229,7 @@ class enrol_flatfile_plugin extends enrol_plugin { unset($elog); // Create/resurrect a context object - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); if ($action == 'add') { $instance = $DB->get_record('enrol', diff --git a/enrol/guest/addinstance.php b/enrol/guest/addinstance.php index 156e4e70a76..ce196320ae8 100644 --- a/enrol/guest/addinstance.php +++ b/enrol/guest/addinstance.php @@ -28,7 +28,7 @@ require('../../config.php'); $id = required_param('id', PARAM_INT); // course id $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('moodle/course:enrolconfig', $context); diff --git a/enrol/guest/lib.php b/enrol/guest/lib.php index cdeab859a75..02aec702549 100644 --- a/enrol/guest/lib.php +++ b/enrol/guest/lib.php @@ -85,7 +85,7 @@ class enrol_guest_plugin extends enrol_plugin { if ($allow) { // Temporarily assign them some guest role for this context - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); load_temp_course_role($context, $CFG->guestroleid); return ENROL_MAX_TIMESTAMP; } @@ -101,7 +101,7 @@ class enrol_guest_plugin extends enrol_plugin { public function get_newinstance_link($courseid) { global $DB; - $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/guest:config', $context)) { return NULL; @@ -140,7 +140,7 @@ class enrol_guest_plugin extends enrol_plugin { if ($instance->id == $instanceid) { if ($data = $form->get_data()) { // add guest role - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); $USER->enrol_guest_passwords[$instance->id] = $data->guestpassword; // this is a hack, ideally we should not add stuff to $USER... if (isset($USER->enrol['tempguest'][$instance->courseid])) { remove_temp_course_roles($context); @@ -280,7 +280,7 @@ class enrol_guest_plugin extends enrol_plugin { public function course_updated($inserted, $course, $data) { global $DB; - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); if (has_capability('enrol/guest:config', $context)) { if ($inserted) { diff --git a/enrol/imsenterprise/importnow.php b/enrol/imsenterprise/importnow.php index e9379bc2225..102d038ea93 100644 --- a/enrol/imsenterprise/importnow.php +++ b/enrol/imsenterprise/importnow.php @@ -1,12 +1,12 @@ set_context(get_context_instance(CONTEXT_SYSTEM)); +$PAGE->set_context(context_system::instance()); $PAGE->set_url('/enrol/imsenterprise/importnow.php'); $PAGE->set_title(get_string('importimsfile', 'enrol_imsenterprise')); diff --git a/enrol/imsenterprise/lib.php b/enrol/imsenterprise/lib.php index 284608a7267..785d613105a 100644 --- a/enrol/imsenterprise/lib.php +++ b/enrol/imsenterprise/lib.php @@ -635,7 +635,7 @@ function process_membership_tag($tagcontents){ // The actual processing (ensuring a group record exists, etc) occurs below, in the enrol-a-student clause } - $rolecontext = get_context_instance(CONTEXT_COURSE, $ship->courseid); + $rolecontext = context_course::instance($ship->courseid); $rolecontext = $rolecontext->id; // All we really want is the ID //$this->log_line("Context instance for course $ship->courseid is..."); //print_r($rolecontext); diff --git a/enrol/imsenterprise/settings.php b/enrol/imsenterprise/settings.php index 977a61c4211..9040b21dd67 100644 --- a/enrol/imsenterprise/settings.php +++ b/enrol/imsenterprise/settings.php @@ -56,7 +56,7 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_heading('enrol_imsenterprise_usersettings_roles', get_string('roles', 'enrol_imsenterprise'), get_string('imsrolesdescription', 'enrol_imsenterprise'))); if (!during_initial_install()) { - $coursecontext = get_context_instance(CONTEXT_COURSE, SITEID); + $coursecontext = context_course::instance(SITEID); $assignableroles = get_assignable_roles($coursecontext); $assignableroles = array('0' => get_string('ignore', 'enrol_imsenterprise')) + $assignableroles; $imsroles = new imsenterprise_roles(); diff --git a/enrol/index.php b/enrol/index.php index 5c3caa82f8e..501b1a8f4f7 100644 --- a/enrol/index.php +++ b/enrol/index.php @@ -36,7 +36,7 @@ if (!isloggedin()) { } $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); // Everybody is enrolled on the frontpage if ($course->id == SITEID) { diff --git a/enrol/instances.php b/enrol/instances.php index 3f8b2dbccdd..14e86249aac 100644 --- a/enrol/instances.php +++ b/enrol/instances.php @@ -31,7 +31,7 @@ $instanceid = optional_param('instance', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { redirect("$CFG->wwwroot/"); diff --git a/enrol/ldap/lib.php b/enrol/ldap/lib.php index f3678bc07fe..f9ab2236a4b 100644 --- a/enrol/ldap/lib.php +++ b/enrol/ldap/lib.php @@ -250,7 +250,7 @@ class enrol_ldap_plugin extends enrol_plugin { // Deal with unenrolments. $transaction = $DB->start_delegated_transaction(); foreach ($enrolments[$role->id]['current'] as $course) { - $context = get_context_instance(CONTEXT_COURSE, $course->courseid); + $context = context_course::instance($course->courseid); $instance = $DB->get_record('enrol', array('id'=>$course->enrolid)); switch ($this->get_config('unenrolaction')) { case ENROL_EXT_REMOVED_UNENROL: @@ -448,7 +448,7 @@ class enrol_ldap_plugin extends enrol_plugin { JOIN {enrol} e ON (e.id = ue.enrolid) WHERE u.deleted = 0 AND e.courseid = :courseid "; $params = array('roleid'=>$role->id, 'courseid'=>$course_obj->id); - $context = get_context_instance(CONTEXT_COURSE, $course_obj->id); + $context = context_course::instance($course_obj->id); if (!empty($ldapmembers)) { list($ldapml, $params2) = $DB->get_in_or_equal($ldapmembers, SQL_PARAMS_NAMED, 'm', false); $sql .= "AND u.idnumber $ldapml"; diff --git a/enrol/locallib.php b/enrol/locallib.php index a819ce9000f..1c71e657ad9 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -112,7 +112,7 @@ class course_enrolment_manager { */ public function __construct(moodle_page $moodlepage, $course, $instancefilter = null) { $this->moodlepage = $moodlepage; - $this->context = get_context_instance(CONTEXT_COURSE, $course->id); + $this->context = context_course::instance($course->id); $this->course = $course; $this->instancefilter = $instancefilter; } diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index a9d5bb7f804..5150182d691 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -39,7 +39,7 @@ $action = required_param('action', PARAM_ACTION); $PAGE->set_url(new moodle_url('/enrol/ajax.php', array('id'=>$id, 'action'=>$action))); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { throw new moodle_exception('invalidcourse'); diff --git a/enrol/manual/edit.php b/enrol/manual/edit.php index 24079a93067..978a6eb4983 100644 --- a/enrol/manual/edit.php +++ b/enrol/manual/edit.php @@ -31,7 +31,7 @@ require_once('edit_form.php'); $courseid = required_param('courseid', PARAM_INT); $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); require_login($course); require_capability('enrol/manual:config', $context); diff --git a/enrol/manual/editenrolment.php b/enrol/manual/editenrolment.php index e749fab6cdf..2d8a7003751 100644 --- a/enrol/manual/editenrolment.php +++ b/enrol/manual/editenrolment.php @@ -57,7 +57,7 @@ if ($course->id == SITEID) { // Obviously require_login($course); // Make sure the user can manage manual enrolments for this course -require_capability("enrol/manual:manage", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST)); +require_capability("enrol/manual:manage", context_course::instance($course->id, MUST_EXIST)); // Get the enrolment manager for this course $manager = new course_enrolment_manager($PAGE, $course, $filter); diff --git a/enrol/manual/externallib.php b/enrol/manual/externallib.php index 44d90acc519..94fde810072 100644 --- a/enrol/manual/externallib.php +++ b/enrol/manual/externallib.php @@ -93,7 +93,7 @@ class enrol_manual_external extends external_api { foreach ($params['enrolments'] as $enrolment) { // Ensure the current user is allowed to run this function in the enrolment context - $context = get_context_instance(CONTEXT_COURSE, $enrolment['courseid']); + $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING); self::validate_context($context); //check that the user has the permission to manual enrol diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 9c3a5d64772..45e33affda7 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -65,7 +65,7 @@ class enrol_manual_plugin extends enrol_plugin { return NULL; } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); + $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) { return NULL; @@ -88,7 +88,7 @@ class enrol_manual_plugin extends enrol_plugin { throw new coding_exception('Invalid enrol instance type!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); if (has_capability('enrol/manual:config', $context)) { $managelink = new moodle_url('/enrol/manual/edit.php', array('courseid'=>$instance->courseid)); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); @@ -106,7 +106,7 @@ class enrol_manual_plugin extends enrol_plugin { if ($instance->enrol !== 'manual') { throw new coding_exception('invalid enrol instance!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); $icons = array(); @@ -130,7 +130,7 @@ class enrol_manual_plugin extends enrol_plugin { public function get_newinstance_link($courseid) { global $DB; - $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/manual:config', $context)) { return NULL; diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 94fdc632a9a..a466f780cc6 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -33,7 +33,7 @@ $extendbase = optional_param('extendbase', 3, PARAM_INT); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('enrol/manual:enrol', $context); diff --git a/enrol/manual/settings.php b/enrol/manual/settings.php index 90bb4cb4612..5ef1b519122 100644 --- a/enrol/manual/settings.php +++ b/enrol/manual/settings.php @@ -48,7 +48,7 @@ if ($ADMIN->fulltree) { get_string('defaultperiod', 'enrol_manual'), get_string('defaultperiod_desc', 'enrol_manual'), 0, PARAM_INT)); if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_manual/roleid', diff --git a/enrol/manual/unenrolself.php b/enrol/manual/unenrolself.php index 4431ac8ca61..fb1744de716 100644 --- a/enrol/manual/unenrolself.php +++ b/enrol/manual/unenrolself.php @@ -31,7 +31,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login(); if (!is_enrolled($context)) { diff --git a/enrol/meta/addinstance.php b/enrol/meta/addinstance.php index 448480443f0..b1bd857a7c1 100644 --- a/enrol/meta/addinstance.php +++ b/enrol/meta/addinstance.php @@ -31,7 +31,7 @@ require_once("$CFG->dirroot/enrol/meta/locallib.php"); $id = required_param('id', PARAM_INT); // course id $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); $PAGE->set_url('/enrol/meta/addinstance.php', array('id'=>$course->id)); $PAGE->set_pagelayout('admin'); diff --git a/enrol/meta/addinstance_form.php b/enrol/meta/addinstance_form.php index ee9538764ad..f2b9bbff49f 100644 --- a/enrol/meta/addinstance_form.php +++ b/enrol/meta/addinstance_form.php @@ -46,7 +46,7 @@ class enrol_meta_addinstance_form extends moodleform { if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) { continue; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $c->id); + $coursecontext = context_course::instance($c->id); if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) { continue; } @@ -79,7 +79,7 @@ class enrol_meta_addinstance_form extends moodleform { if (!$c = $DB->get_record('course', array('id'=>$data['link']))) { $errors['link'] = get_string('required'); } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $c->id); + $coursecontext = context_course::instance($c->id); $existing = $DB->get_records('enrol', array('enrol'=>'meta', 'courseid'=>$this->course->id), '', 'customint1, id'); if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) { $errors['link'] = get_string('error'); diff --git a/enrol/meta/lib.php b/enrol/meta/lib.php index c400bc32630..10f277bf138 100644 --- a/enrol/meta/lib.php +++ b/enrol/meta/lib.php @@ -58,7 +58,7 @@ class enrol_meta_plugin extends enrol_plugin { * @return moodle_url page url */ public function get_newinstance_link($courseid) { - $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/meta:config', $context)) { return NULL; } diff --git a/enrol/mnet/addinstance.php b/enrol/mnet/addinstance.php index 227bf823c5c..b7d75f4a423 100644 --- a/enrol/mnet/addinstance.php +++ b/enrol/mnet/addinstance.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php'); $id = required_param('id', PARAM_INT); // course id $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('moodle/course:enrolconfig', $context); diff --git a/enrol/mnet/addinstance_form.php b/enrol/mnet/addinstance_form.php index 9e30ce196cb..e6d13d12a82 100644 --- a/enrol/mnet/addinstance_form.php +++ b/enrol/mnet/addinstance_form.php @@ -36,7 +36,7 @@ class enrol_mnet_addinstance_form extends moodleform { $course = $this->_customdata['course']; $enrol = $this->_customdata['enrol']; $service = $this->_customdata['service']; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $subscribers = $service->get_remote_subscribers(); $hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet')); diff --git a/enrol/mnet/enrol.php b/enrol/mnet/enrol.php index 2fb785c5b70..58fd876a385 100644 --- a/enrol/mnet/enrol.php +++ b/enrol/mnet/enrol.php @@ -88,7 +88,7 @@ class enrol_mnet_mnetservice_enrol { // use the record if it does not exist yet or is host-specific if (empty($courses[$course->remoteid]) or ($course->customint1 > 0)) { unset($course->customint1); // the client does not need to know this - $context = get_context_instance(CONTEXT_COURSE, $course->remoteid); + $context = context_course::instance($course->remoteid); // Rewrite file URLs so that they are correct $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false); $courses[$course->remoteid] = $course; diff --git a/enrol/mnet/lib.php b/enrol/mnet/lib.php index d49bcf4c43e..0a507293f71 100644 --- a/enrol/mnet/lib.php +++ b/enrol/mnet/lib.php @@ -47,7 +47,7 @@ class enrol_mnet_plugin extends enrol_plugin { } else if (empty($instance->name)) { $enrol = $this->get_name(); if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) { - $role = role_get_name($role, get_context_instance(CONTEXT_COURSE, $instance->courseid)); + $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)); } else { $role = get_string('error'); } @@ -79,7 +79,7 @@ class enrol_mnet_plugin extends enrol_plugin { if (!$service->is_available()) { return null; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $coursecontext = context_course::instance($courseid); if (!has_capability('moodle/course:enrolconfig', $coursecontext)) { return null; } diff --git a/enrol/mnet/settings.php b/enrol/mnet/settings.php index acce3fed2e0..fc022046dd0 100644 --- a/enrol/mnet/settings.php +++ b/enrol/mnet/settings.php @@ -33,7 +33,7 @@ if ($ADMIN->fulltree) { //--- enrol instance defaults ---------------------------------------------------------------------------- if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect_with_advanced('enrol_mnet/roleid', diff --git a/enrol/otherusers.php b/enrol/otherusers.php index 52b34bfe829..94a40f72639 100644 --- a/enrol/otherusers.php +++ b/enrol/otherusers.php @@ -33,7 +33,7 @@ $action = optional_param('action', '', PARAM_ACTION); $filter = optional_param('ifilter', 0, PARAM_INT); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('moodle/role:assign', $context); diff --git a/enrol/paypal/edit.php b/enrol/paypal/edit.php index 91c89e2fe24..b39e5b3146d 100644 --- a/enrol/paypal/edit.php +++ b/enrol/paypal/edit.php @@ -32,7 +32,7 @@ $courseid = required_param('courseid', PARAM_INT); $instanceid = optional_param('id', 0, PARAM_INT); // instanceid $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); require_login($course); require_capability('enrol/paypal:config', $context); diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index b4a6bf42403..2a28c245e90 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -76,7 +76,7 @@ if (! $course = $DB->get_record("course", array("id"=>$data->courseid))) { die; } -if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { +if (! $context = context_course::instance($course->id, IGNORE_MISSING)) { message_paypal_error_to_admin("Not a valid context id", $data); die; } @@ -187,7 +187,7 @@ while (!feof($fp)) { die; } - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id, IGNORE_MISSING); // Check that amount paid is the correct amount if ( (float) $plugin_instance->cost <= 0 ) { diff --git a/enrol/paypal/lib.php b/enrol/paypal/lib.php index d9f9d498d9b..69b9b399c78 100644 --- a/enrol/paypal/lib.php +++ b/enrol/paypal/lib.php @@ -80,7 +80,7 @@ class enrol_paypal_plugin extends enrol_plugin { throw new coding_exception('Invalid enrol instance type!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); if (has_capability('enrol/paypal:config', $context)) { $managelink = new moodle_url('/enrol/paypal/edit.php', array('courseid'=>$instance->courseid, 'id'=>$instance->id)); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); @@ -98,7 +98,7 @@ class enrol_paypal_plugin extends enrol_plugin { if ($instance->enrol !== 'paypal') { throw new coding_exception('invalid enrol instance!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); $icons = array(); @@ -116,7 +116,7 @@ class enrol_paypal_plugin extends enrol_plugin { * @return moodle_url page url */ public function get_newinstance_link($courseid) { - $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/paypal:config', $context)) { return NULL; @@ -151,7 +151,7 @@ class enrol_paypal_plugin extends enrol_plugin { } $course = $DB->get_record('course', array('id'=>$instance->courseid)); - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $shortname = format_string($course->shortname, true, array('context' => $context)); $strloginto = get_string("loginto", "", $shortname); diff --git a/enrol/paypal/return.php b/enrol/paypal/return.php index a8a65570c4c..81357161381 100644 --- a/enrol/paypal/return.php +++ b/enrol/paypal/return.php @@ -34,7 +34,7 @@ if (!$course = $DB->get_record("course", array("id"=>$id))) { redirect($CFG->wwwroot); } -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login(); diff --git a/enrol/paypal/settings.php b/enrol/paypal/settings.php index 3352d2b9713..80ac4c81bfa 100644 --- a/enrol/paypal/settings.php +++ b/enrol/paypal/settings.php @@ -61,7 +61,7 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configselect('enrol_paypal/currency', get_string('currency', 'enrol_paypal'), '', 'USD', $paypalcurrencies)); if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_paypal/roleid', diff --git a/enrol/paypal/unenrolself.php b/enrol/paypal/unenrolself.php index 9984d586306..c884733ee3d 100644 --- a/enrol/paypal/unenrolself.php +++ b/enrol/paypal/unenrolself.php @@ -31,7 +31,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'paypal'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login(); if (!is_enrolled($context)) { diff --git a/enrol/self/edit.php b/enrol/self/edit.php index 4affcb7979a..4b38df4daba 100644 --- a/enrol/self/edit.php +++ b/enrol/self/edit.php @@ -32,7 +32,7 @@ $courseid = required_param('courseid', PARAM_INT); $instanceid = optional_param('id', 0, PARAM_INT); // instanceid $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); require_login($course); require_capability('enrol/self:config', $context); diff --git a/enrol/self/editenrolment.php b/enrol/self/editenrolment.php index 4449d342c00..418359ea9df 100644 --- a/enrol/self/editenrolment.php +++ b/enrol/self/editenrolment.php @@ -57,7 +57,7 @@ if ($course->id == SITEID) { // Obvioulsy require_login($course); // The user must be able to manage self enrolments within the course -require_capability("enrol/self:manage", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST)); +require_capability("enrol/self:manage", context_course::instance($course->id, MUST_EXIST)); // Get the enrolment manager for this course $manager = new course_enrolment_manager($PAGE, $course, $filter); diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 32c9d48e643..4c9246b3c2b 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -74,7 +74,7 @@ class enrol_self_plugin extends enrol_plugin { if (empty($instance->name)) { if (!empty($instance->roleid) and $role = $DB->get_record('role', array('id'=>$instance->roleid))) { - $role = ' (' . role_get_name($role, get_context_instance(CONTEXT_COURSE, $instance->courseid)) . ')'; + $role = ' (' . role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)) . ')'; } else { $role = ''; } @@ -115,7 +115,7 @@ class enrol_self_plugin extends enrol_plugin { throw new coding_exception('Invalid enrol instance type!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); if (has_capability('enrol/self:config', $context)) { $managelink = new moodle_url('/enrol/self/edit.php', array('courseid'=>$instance->courseid, 'id'=>$instance->id)); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); @@ -133,7 +133,7 @@ class enrol_self_plugin extends enrol_plugin { if ($instance->enrol !== 'self') { throw new coding_exception('invalid enrol instance!'); } - $context = get_context_instance(CONTEXT_COURSE, $instance->courseid); + $context = context_course::instance($instance->courseid); $icons = array(); @@ -151,7 +151,7 @@ class enrol_self_plugin extends enrol_plugin { * @return moodle_url page url */ public function get_newinstance_link($courseid) { - $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/self:config', $context)) { return NULL; @@ -282,7 +282,7 @@ class enrol_self_plugin extends enrol_plugin { $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname)); - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $rusers = array(); if (!empty($CFG->coursecontact)) { $croles = explode(',', $CFG->coursecontact); diff --git a/enrol/self/settings.php b/enrol/self/settings.php index dc9a874e74f..0b11ccd487c 100644 --- a/enrol/self/settings.php +++ b/enrol/self/settings.php @@ -58,7 +58,7 @@ if ($ADMIN->fulltree) { get_string('groupkey', 'enrol_self'), get_string('groupkey_desc', 'enrol_self'), 0, $options)); if (!during_initial_install()) { - $options = get_default_enrol_roles(get_context_instance(CONTEXT_SYSTEM)); + $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_self/roleid', diff --git a/enrol/self/unenrolself.php b/enrol/self/unenrolself.php index 5fd6062d785..02670f6abb2 100644 --- a/enrol/self/unenrolself.php +++ b/enrol/self/unenrolself.php @@ -31,7 +31,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'self'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); require_login(); if (!is_enrolled($context)) { diff --git a/enrol/users.php b/enrol/users.php index 2ebbab5ec8b..03bafb9cb42 100644 --- a/enrol/users.php +++ b/enrol/users.php @@ -34,7 +34,7 @@ $action = optional_param('action', '', PARAM_ACTION); $filter = optional_param('ifilter', 0, PARAM_INT); $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); +$context = context_course::instance($course->id, MUST_EXIST); if ($course->id == SITEID) { redirect(new moodle_url('/')); diff --git a/enrol/users_forms.php b/enrol/users_forms.php index 7263688fdde..92f11553cc8 100644 --- a/enrol/users_forms.php +++ b/enrol/users_forms.php @@ -36,7 +36,7 @@ class enrol_users_assign_form extends moodleform { $user = $this->_customdata['user']; $course = $this->_customdata['course']; - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id); $assignable = $this->_customdata['assignable']; $assignable = array_reverse($assignable, true); // students first @@ -87,7 +87,7 @@ class enrol_users_addmember_form extends moodleform { $user = $this->_customdata['user']; $course = $this->_customdata['course']; - $context = get_context_instance(CONTEXT_COURSE, $course->id); + $context = context_course::instance($course->id, IGNORE_MISSING); $allgroups = $this->_customdata['allgroups']; $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');