Skip to content

Commit

Permalink
MDL-34462 Librairies: Replaced deprecated get_context_instance()
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jul 23, 2012
1 parent bdaff20 commit 6ca657a
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion calendar/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
$course = $DB->get_record('course', array('id'=>$courseid));
require_login($course);
if (!$course) {
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong
$PAGE->set_context(context_system::instance()); //TODO: wrong
}

// Check the user has the required capabilities to edit an event
Expand Down
2 changes: 1 addition & 1 deletion calendar/export_execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
$ev->add_property('dtend', Bennu::timestamp_to_datetime($event->timestart + $event->timeduration));
}
if ($event->courseid != 0) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $event->courseid);
$coursecontext = context_course::instance($event->courseid);
$ev->add_property('categories', format_string($courses[$event->courseid]->shortname, true, array('context' => $coursecontext)));
}
$ical->add_component($ev);
Expand Down
26 changes: 13 additions & 13 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ function calendar_add_event_metadata($event) {
}
$icon = $OUTPUT->pix_url('icon', $event->modulename) . '';

$context = get_context_instance(CONTEXT_COURSE, $module->course);
$context = context_course::instance($module->course);
$fullname = format_string($coursecache[$module->course]->fullname, true, array('context' => $context));

$event->icon = '<img height="16" width="16" src="'.$icon.'" alt="'.$eventtype.'" title="'.$modulename.'" style="vertical-align: middle;" />';
Expand All @@ -595,7 +595,7 @@ function calendar_add_event_metadata($event) {
} else if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event
calendar_get_course_cached($coursecache, $event->courseid);

$context = get_context_instance(CONTEXT_COURSE, $event->courseid);
$context = context_course::instance($event->courseid);
$fullname = format_string($coursecache[$event->courseid]->fullname, true, array('context' => $context));

$event->icon = '<img height="16" width="16" src="'.$OUTPUT->pix_url('c/course') . '" alt="'.get_string('courseevent', 'calendar').'" style="vertical-align: middle;" />';
Expand Down Expand Up @@ -1374,7 +1374,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {

if (count($courseeventsfrom)==1) {
$course = reset($courseeventsfrom);
if (has_any_capability($allgroupscaps, get_context_instance(CONTEXT_COURSE, $course->id))) {
if (has_any_capability($allgroupscaps, context_course::instance($course->id))) {
$coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id');
$group = array_keys($coursegroups);
}
Expand Down Expand Up @@ -1430,7 +1430,7 @@ function calendar_edit_event_allowed($event) {
return false;
}

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sitecontext = context_system::instance();
// if user has manageentries at site level, return true
if (has_capability('moodle/calendar:manageentries', $sitecontext)) {
return true;
Expand Down Expand Up @@ -1698,14 +1698,14 @@ function calendar_get_allowed_types(&$allowed, $course = null) {
$allowed->user = has_capability('moodle/calendar:manageownentries', get_system_context());
$allowed->groups = false; // This may change just below
$allowed->courses = false; // This may change just below
$allowed->site = has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, SITEID));
$allowed->site = has_capability('moodle/calendar:manageentries', context_course::instance(SITEID));

if (!empty($course)) {
if (!is_object($course)) {
$course = $DB->get_record('course', array('id' => $course), '*', MUST_EXIST);
}
if ($course->id != SITEID) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontext = context_course::instance($course->id);
$allowed->user = has_capability('moodle/calendar:manageownentries', $coursecontext);

if (has_capability('moodle/calendar:manageentries', $coursecontext)) {
Expand Down Expand Up @@ -1752,7 +1752,7 @@ function calendar_add_event_allowed($event) {
return false;
}

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sitecontext = context_system::instance();
// if user has manageentries at site level, always return true
if (has_capability('moodle/calendar:manageentries', $sitecontext)) {
return true;
Expand Down Expand Up @@ -1953,20 +1953,20 @@ protected function calculate_context(stdClass $data) {

$context = null;
if (isset($data->courseid) && $data->courseid > 0) {
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
$context = context_course::instance($data->courseid);
} else if (isset($data->course) && $data->course > 0) {
$context = get_context_instance(CONTEXT_COURSE, $data->course);
$context = context_course::instance($data->course);
} else if (isset($data->groupid) && $data->groupid > 0) {
$group = $DB->get_record('groups', array('id'=>$data->groupid));
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
} else if (isset($data->userid) && $data->userid > 0 && $data->userid == $USER->id) {
$context = get_context_instance(CONTEXT_USER, $data->userid);
$context = context_user::instance($data->userid);
} else if (isset($data->userid) && $data->userid > 0 && $data->userid != $USER->id &&
isset($data->instance) && $data->instance > 0) {
$cm = get_coursemodule_from_instance($data->modulename, $data->instance, 0, false, MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
$context = context_course::instance($cm->course);
} else {
$context = get_context_instance(CONTEXT_USER);
$context = context_user::instance();
}

return $context;
Expand Down
4 changes: 2 additions & 2 deletions calendar/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ protected function course_filter_selector(moodle_url $returnurl, $label=null) {
return '';
}

if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) {
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
} else {
$courses = enrol_get_my_courses();
Expand All @@ -698,7 +698,7 @@ protected function course_filter_selector(moodle_url $returnurl, $label=null) {
$courseoptions = array();
$courseoptions[SITEID] = get_string('fulllistofcourses');
foreach ($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontext = context_course::instance($course->id);
$courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
}

Expand Down
2 changes: 1 addition & 1 deletion calendar/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
$url = new moodle_url('/calendar/set.php', array('return'=>base64_encode($return->out(false)), 'course' => $courseid, 'var'=>$var, 'sesskey'=>sesskey()));
$PAGE->set_url($url);
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());

switch($var) {
case 'showgroups':
Expand Down
4 changes: 2 additions & 2 deletions cohort/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ protected function get_category_options($currentcontextid) {
$parentlist = array();
make_categories_list($displaylist, $parentlist, 'moodle/cohort:manage');
$options = array();
$syscontext = get_context_instance(CONTEXT_SYSTEM);
$syscontext = context_system::instance();
if (has_capability('moodle/cohort:manage', $syscontext)) {
$options[$syscontext->id] = print_context_name($syscontext);
}
foreach ($displaylist as $cid=>$name) {
$context = get_context_instance(CONTEXT_COURSECAT, $cid, MUST_EXIST);
$context = context_coursecat::instance($cid, MUST_EXIST);
$options[$context->id] = $name;
}
// always add current - this is not likely, but if the logic gets changed it might be a problem
Expand Down
2 changes: 1 addition & 1 deletion cohort/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if ($contextid) {
$context = get_context_instance_by_id($contextid, MUST_EXIST);
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
}

if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
Expand Down
8 changes: 4 additions & 4 deletions cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ function cohort_delete_category($category) {
global $DB;
// TODO: make sure that cohorts are really, really not used anywhere and delete, for now just move to parent or system context

$oldcontext = get_context_instance(CONTEXT_COURSECAT, $category->id, MUST_EXIST);
$oldcontext = context_coursecat::instance($category->id, MUST_EXIST);

if ($category->parent and $parent = $DB->get_record('course_categories', array('id'=>$category->parent))) {
$parentcontext = get_context_instance(CONTEXT_COURSECAT, $parent->id, MUST_EXIST);
$parentcontext = context_coursecat::instance($parent->id, MUST_EXIST);
$sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext";
$params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$parentcontext->id);
} else {
$syscontext = get_context_instance(CONTEXT_SYSTEM);
$syscontext = context_system::instance();
$sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext";
$params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$syscontext->id);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ function cohort_remove_member($cohortid, $userid) {
function cohort_get_visible_list($course) {
global $DB, $USER;

$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
list($esql, $params) = get_enrolled_sql($context);
$parentsql = get_related_contexts_string($context);

Expand Down
2 changes: 1 addition & 1 deletion filter/algebra/algebradebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require_once($CFG->dirroot.'/filter/tex/lib.php');

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/site:config', context_system::instance());

$query = urldecode($_SERVER['QUERY_STRING']);

Expand Down
2 changes: 1 addition & 1 deletion filter/algebra/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function filter_algebra_image($imagefile, $tex= "", $height="", $width="", $alig
}
$anchorcontents .= "\" $style />";

if (!file_exists("$CFG->dataroot/filter/algebra/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (!file_exists("$CFG->dataroot/filter/algebra/$imagefile") && has_capability('moodle/site:config', context_system::instance())) {
$link = '/filter/algebra/algebradebug.php';
$action = null;
} else {
Expand Down
2 changes: 1 addition & 1 deletion filter/tex/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function filter_text_image($imagefile, $tex, $height, $width, $align, $alt) {
}
$anchorcontents .= "\" $style/>";

if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', context_system::instance())) {
$link = '/filter/tex/texdebug.php';
$action = null;
} else {
Expand Down
2 changes: 1 addition & 1 deletion filter/tex/texdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$texexp = optional_param('tex', '', PARAM_RAW);

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM), $USER->id); /// Required cap to run this. MDL-18552
require_capability('moodle/site:config', context_system::instance(), $USER->id); /// Required cap to run this. MDL-18552

$output = '';

Expand Down

0 comments on commit 6ca657a

Please sign in to comment.