Permalink
Browse files

MDL-34470 course: Replace all instances of get_context_instance() wit…

…h context_xxx::instance() in course/
  • Loading branch information...
1 parent bc659e5 commit 9a5e297b4cba125d49a04788321894d0ce797e5e @ankitagarwal ankitagarwal committed Jul 23, 2012
View
@@ -93,7 +93,7 @@
// Some courses are being moved
// user must have category update in both cats to perform this
require_capability('moodle/category:manage', $context);
- require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveto));
+ require_capability('moodle/category:manage', context_coursecat::instance($moveto));
if (!$destcategory = $DB->get_record('course_categories', array('id' => $data->moveto))) {
print_error('cannotfindcategory', '', '', $data->moveto);
@@ -129,7 +129,7 @@
}
if ($course) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
require_capability('moodle/course:visibility', $coursecontext);
// Set the visibility of the course. we set the old flag when user manually changes visibility of course.
$DB->update_record('course', array('id' => $course->id, 'visible' => $visible, 'visibleold' => $visible, 'timemodified' => time()));
@@ -268,7 +268,7 @@
foreach ($subcategories as $subcategory) {
// Preload the context we will need it to format the category name shortly.
context_helper::preload_from_record($subcategory);
- $context = get_context_instance(CONTEXT_COURSECAT, $subcategory->id);
+ $context = context_coursecat::instance($subcategory->id);
// Prepare the things we need to create a link to the subcategory
$attributes = $subcategory->visible ? array() : array('class' => 'dimmed');
$text = format_string($subcategory->name, true, array('context' => $context));
@@ -332,7 +332,7 @@
$baseurl = new moodle_url('/course/category.php', $urlparams + array('sesskey' => sesskey()));
foreach ($courses as $acourse) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $acourse->id);
+ $coursecontext = context_course::instance($acourse->id);
$count++;
$up = ($count > 1 || !$atfirstpage);
@@ -447,7 +447,7 @@
}
if (!empty($CFG->enablecourserequests) && $category->id == $CFG->defaultrequestcategory) {
- print_course_request_buttons(get_context_instance(CONTEXT_SYSTEM));
+ print_course_request_buttons(context_system::instance());
}
echo '</div>';
View
@@ -53,7 +53,7 @@
print_error('invalidcourseid');
}
require_login($course);
- require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
+ require_capability('moodle/course:update', context_course::instance($course->id));
} else {
require_login();
@@ -105,7 +105,7 @@ function definition() {
$selectbox = array();
$selected = array();
foreach ($courses as $c) {
- $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $c->id)));
+ $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => context_course::instance($c->id)));
// If already selected
if ($c->selected) {
@@ -134,7 +134,7 @@ function definition() {
// Role completion criteria
$mform->addElement('header', 'roles', get_string('manualcompletionby', 'completion'));
- $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, get_context_instance(CONTEXT_COURSE, $course->id));
+ $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, context_course::instance($course->id));
if (!empty($roles)) {
$mform->addElement('select', 'role_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
View
@@ -8,7 +8,7 @@
$delete = optional_param('delete', '', PARAM_ALPHANUM); // delete confirmation hash
$PAGE->set_url('/course/delete.php', array('id' => $id));
- $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $PAGE->set_context(context_system::instance());
require_login();
$site = get_site();
@@ -25,15 +25,15 @@
print_error("invalidcourseid");
}
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
if (!can_delete_course($id)) {
print_error('cannotdeletecourse');
}
$category = $DB->get_record("course_categories", array("id"=>$course->category));
- $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
- $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
+ $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
+ $categoryname = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
$PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
@@ -16,7 +16,7 @@ function definition() {
$mform =& $this->_form;
$category = $this->_customdata;
- $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $categorycontext = context_coursecat::instance($category->id);
$this->_category = $category;
/// Check permissions, to see if it OK to give the option to delete
@@ -30,7 +30,7 @@ function definition() {
$checkcat = array_pop($tocheck);
$childcategoryids[] = $checkcat->id;
$tocheck = $tocheck + get_child_categories($checkcat->id);
- $chcontext = get_context_instance(CONTEXT_COURSECAT, $checkcat->id);
+ $chcontext = context_coursecat::instance($checkcat->id);
if ($candeletecontent && !has_capability('moodle/category:manage', $chcontext)) {
$candeletecontent = false;
}
View
@@ -44,15 +44,15 @@
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($course);
$category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
require_capability('moodle/course:update', $coursecontext);
$PAGE->url->param('id',$id);
} else if ($categoryid) { // creating new course in this category
$course = null;
require_login();
$category = $DB->get_record('course_categories', array('id'=>$categoryid), '*', MUST_EXIST);
- $catcontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $catcontext = context_coursecat::instance($category->id);
require_capability('moodle/course:create', $catcontext);
$PAGE->url->param('category',$categoryid);
$PAGE->set_context($catcontext);
@@ -109,7 +109,7 @@
$course = create_course($data, $editoroptions);
// Get the context of the newly created course
- $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
+ $context = context_course::instance($course->id, MUST_EXIST);
if (!empty($CFG->creatornewroleid) and !is_viewing($context, NULL, 'moodle/role:assign') and !is_enrolled($context, NULL, 'moodle/role:assign')) {
// deal with course creators - enrol them internally with default role
View
@@ -19,11 +19,11 @@ function definition() {
$editoroptions = $this->_customdata['editoroptions'];
$returnto = $this->_customdata['returnto'];
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
- $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $systemcontext = context_system::instance();
+ $categorycontext = context_coursecat::instance($category->id);
if (!empty($course->id)) {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
$context = $coursecontext;
} else {
$coursecontext = null;
View
@@ -40,7 +40,7 @@
print_error('unknowcategory');
}
$PAGE->set_url('/course/editcategory.php', array('id' => $id));
- $categorycontext = get_context_instance(CONTEXT_COURSECAT, $id);
+ $categorycontext = context_coursecat::instance($id);
$PAGE->set_context($categorycontext);
require_capability('moodle/category:manage', $categorycontext);
$strtitle = get_string('editcategorysettings');
@@ -54,7 +54,7 @@
if (!$DB->record_exists('course_categories', array('id' => $parent))) {
print_error('unknowcategory');
}
- $context = get_context_instance(CONTEXT_COURSECAT, $parent);
+ $context = context_coursecat::instance($parent);
} else {
$context = get_system_context();
}
View
@@ -41,7 +41,7 @@
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = context_course::instance($course->id);
require_capability('moodle/course:update', $context);
$editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
View
@@ -85,7 +85,7 @@ public static function get_course_contents($courseid, $options = array()) {
}
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -144,7 +144,7 @@ public static function get_course_contents($courseid, $options = array()) {
$module['modicon'] = $cm->get_icon_url()->out(false);
$module['indent'] = $cm->indent;
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $modcontext = context_module::instance($cm->id);
if (!empty($cm->showdescription)) {
$module['description'] = $cm->get_content();
@@ -157,7 +157,7 @@ public static function get_course_contents($courseid, $options = array()) {
}
$canviewhidden = has_capability('moodle/course:viewhiddenactivities',
- get_context_instance(CONTEXT_MODULE, $cm->id));
+ context_module::instance($cm->id));
//user that can view hidden module should know about the visibility
$module['visible'] = $cm->visible;
@@ -297,7 +297,7 @@ public static function get_courses($options = array()) {
foreach ($courses as $course) {
// now security checks
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -511,7 +511,7 @@ public static function create_courses($courses) {
foreach ($params['courses'] as $course) {
// Ensure the current user is allowed to run this function
- $context = get_context_instance(CONTEXT_COURSECAT, $course['categoryid']);
+ $context = context_coursecat::instance($course['categoryid']);
try {
self::validate_context($context);
} catch (Exception $e) {
@@ -9,7 +9,7 @@
if ($forum = forum_get_course_forum($course->id, 'social')) {
$cm = get_coursemodule_from_instance('forum', $forum->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
/// Print forum intro above posts MDL-18483
if (trim($forum->intro) != '') {
@@ -60,7 +60,7 @@ function callback_topics_definition() {
function callback_topics_get_section_name($course, $section) {
// We can't add a node without any text
if ((string)$section->name !== '') {
- return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ return format_string($section->name, true, array('context' => context_course::instance($course->id)));
} else if ($section->section == 0) {
return get_string('section0name', 'format_topics');
} else {
View
@@ -38,7 +38,7 @@
$site = get_site();
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$systemcontext = context_system::instance();
$PAGE->set_url('/course/index.php');
$PAGE->set_context($systemcontext);
@@ -121,7 +121,7 @@
if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) {
print_error('invalidcategoryid');
}
- $context = get_context_instance(CONTEXT_COURSECAT, $delete);
+ $context = context_coursecat::instance($delete);
require_capability('moodle/category:manage', $context);
require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent));
@@ -174,7 +174,7 @@
$tempcat = new stdClass();
$tempcat->name = get_string('miscellaneous');
$tempcat->id = $DB->insert_record('course_categories', $tempcat);
- $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id);
+ $tempcat->context = context_coursecat::instance($tempcat->id);
mark_context_dirty('/'.SYSCONTEXTID);
fix_course_sortorder(); // Required to build course_categories.depth and .path.
set_config('defaultrequestcategory', $tempcat->id);
@@ -215,14 +215,14 @@
$swapcategory = NULL;
if (!empty($moveup)) {
- require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveup));
+ require_capability('moodle/category:manage', context_coursecat::instance($moveup));
if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) {
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder<? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder DESC', '*', 0, 1)) {
$swapcategory = reset($swapcategory);
}
}
} else {
- require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $movedown));
+ require_capability('moodle/category:manage', context_coursecat::instance($movedown));
if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) {
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) {
$swapcategory = reset($swapcategory);
@@ -306,7 +306,7 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $
if (!empty($category)) {
if (!isset($category->context)) {
- $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $category->context = context_coursecat::instance($category->id);
}
echo '<tr><td align="left" class="name">';
View
@@ -28,7 +28,7 @@
require_login();
}
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $context = context_course::instance($course->id);
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
print_error('coursehidden', '', $CFG->wwwroot .'/');
}
Oops, something went wrong.

0 comments on commit 9a5e297

Please sign in to comment.