Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-34456 Librairies: Replaced deprecated get_context_instance()
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jul 24, 2012
1 parent bdaff20 commit fe2fdd1
Show file tree
Hide file tree
Showing 31 changed files with 45 additions and 46 deletions.
2 changes: 1 addition & 1 deletion blocks/admin_bookmarks/block_admin_bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function instance_allow_multiple() {
* @return array
*/
function applicable_formats() {
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('moodle/site:config', context_system::instance())) {
return array('all' => true);
} else {
return array('site' => true);
Expand Down
2 changes: 1 addition & 1 deletion blocks/admin_bookmarks/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require_once($CFG->libdir.'/adminlib.php');
require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$PAGE->set_context($context);
$adminroot = admin_get_root(false, false); // settings not required - only pages

Expand Down
2 changes: 1 addition & 1 deletion blocks/admin_bookmarks/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_once($CFG->libdir.'/adminlib.php');

require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$PAGE->set_context($context);
$adminroot = admin_get_root(false, false); // settings not required - only pages

Expand Down
2 changes: 1 addition & 1 deletion blocks/blog_menu/block_blog_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function get_content() {
$this->content->text = html_writer::alist($menulist, array('class'=>'list'));

// Prepare the footer for this block
if (has_capability('moodle/blog:search', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('moodle/blog:search', context_system::instance())) {
// Full-text search field
$form = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide'));
$form .= html_writer::empty_tag('input', array('id'=>'blogsearchquery', 'type'=>'text', 'name'=>'search'));
Expand Down
2 changes: 1 addition & 1 deletion blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function get_content() {

// admins should be able to read all tags
$type = '';
if (!has_capability('moodle/user:readuserblogs', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/user:readuserblogs', context_system::instance())) {
$type = " AND (p.publishstate = 'site' or p.publishstate='public')";
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/calendar_upcoming/block_calendar_upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function get_content() {
$this->content->footer = '<div class="gotocal"><a href="'.$CFG->wwwroot.
'/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
get_string('gotocalendar', 'calendar').'</a>...</div>';
$context = get_context_instance(CONTEXT_COURSE, $courseshown);
$context = context_course::instance($courseshown);
if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) {
$this->content->footer .= '<div class="newevent"><a href="'.$CFG->wwwroot.
'/calendar/event.php?action=new&amp;course='.$courseshown.'">'.
Expand Down
2 changes: 1 addition & 1 deletion blocks/community/communitycourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
$courseid = required_param('courseid', PARAM_INT); //if no courseid is given
$parentcourse = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);

$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);
$PAGE->set_course($parentcourse);
$PAGE->set_url('/blocks/community/communitycourse.php');
$PAGE->set_heading($SITE->fullname);
Expand Down
2 changes: 1 addition & 1 deletion blocks/community/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function definition() {

//display enrol/download select box if the USER has the download capability on the course
if (has_capability('moodle/community:download',
get_context_instance(CONTEXT_COURSE, $this->_customdata['courseid']))) {
context_course::instance($this->_customdata['courseid']))) {
$options = array(0 => get_string('enrollable', 'block_community'),
1 => get_string('downloadable', 'block_community'));
$mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'),
Expand Down
2 changes: 1 addition & 1 deletion blocks/community/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function block_community_download_course_backup($course) {

$fs = get_file_storage();
$record = new stdClass();
$record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
$record->contextid = context_user::instance($USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
Expand Down
4 changes: 2 additions & 2 deletions blocks/completionstatus/block_completionstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function get_content() {
$this->content = new stdClass;

// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
$can_edit = has_capability('moodle/course:update', context_course::instance($this->page->course->id));

// Get course completion data
$info = new completion_info($this->page->course);
Expand Down Expand Up @@ -84,7 +84,7 @@ public function get_content() {
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
// If not enrolled, but are can view the report:
if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
if (has_capability('report/completion:view', context_course::instance($COURSE->id))) {
$this->content->text = '<a href="'.$CFG->wwwroot.'/report/completion/index.php?course='.$COURSE->id.
'">'.get_string('viewcoursereport', 'completion').'</a>';
return $this->content;
Expand Down
4 changes: 2 additions & 2 deletions blocks/completionstatus/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
// Check permissions
require_login($course);

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);

$can_view = false;

Expand Down
20 changes: 10 additions & 10 deletions blocks/course_list/block_course_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ function get_content() {
}

if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and
!(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall)) { // Just print My Courses
!(has_capability('moodle/course:update', context_system::instance()) and $adminseesall)) { // Just print My Courses
if ($courses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
foreach ($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontext = context_course::instance($course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">".$icon.format_string($course->fullname). "</a>";
}
$this->title = get_string('mycourses');
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
$this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ...";
}
}
Expand All @@ -57,12 +57,12 @@ function get_content() {
if ($categories) { //Check we have categories
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
foreach ($categories as $category) {
$categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
$categoryname = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . $categoryname . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
$this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
}
$this->title = get_string('categories');
Expand All @@ -72,24 +72,24 @@ function get_content() {

if ($courses) {
foreach ($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontext = context_course::instance($course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";

$this->content->items[]="<a $linkcss title=\""
. format_string($course->shortname, true, array('context' => $coursecontext))."\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
.$icon. format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . "</a>";
.$icon. format_string($course->fullname, true, array('context' => context_course::instance($course->id))) . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
$this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
}
$this->get_remote_courses();
} else {

$this->content->icons[] = '';
$this->content->items[] = get_string('nocoursesyet');
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
if (has_capability('moodle/course:create', context_coursecat::instance($category->id))) {
$this->content->footer = '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a> ...';
}
$this->get_remote_courses();
Expand Down Expand Up @@ -120,7 +120,7 @@ function get_remote_courses() {
$this->content->items[] = get_string('remotecourses','mnet');
$this->content->icons[] = '';
foreach ($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontext = context_course::instance($course->id);
$this->content->items[]="<a title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">"
.$icon. format_string($course->fullname) . "</a>";
Expand Down
2 changes: 1 addition & 1 deletion blocks/course_summary/block_course_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function get_content() {
$options = new stdClass();
$options->noclean = true; // Don't clean Javascripts etc
$options->overflowdiv = true;
$context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
$context = context_course::instance($this->page->course->id);
$this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
$this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
if ($this->page->user_is_editing()) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function set_data($defaults) {
$defaults->bui_subpagepattern = '%@NULL@%';
}

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
if ($defaults->parentcontextid == $systemcontext->id) {
$defaults->bui_contexts = BUI_CONTEXTS_ENTIRE_SITE; // System-wide and sticky
} else {
Expand Down
6 changes: 3 additions & 3 deletions blocks/glossary_random/block_glossary_random.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function specialization() {
if (! $cm = get_coursemodule_from_instance("glossary", $this->config->glossary, $this->course->id)) {
return false;
}
$glossaryctx = get_context_instance(CONTEXT_MODULE, $cm->id);
$glossaryctx = context_module::instance($cm->id);

$limitfrom = 0;
$limitnum = 1;
Expand Down Expand Up @@ -131,7 +131,7 @@ function get_content() {
$glossaryid = $this->config->glossary;
$cm = $modinfo->instances['glossary'][$glossaryid];

if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if (!has_capability('mod/glossary:view', context_module::instance($cm->id))) {
return '';
}

Expand Down Expand Up @@ -162,7 +162,7 @@ function get_content() {

//Obtain the visible property from the instance
if ($cm->uservisible) {
if (has_capability('mod/glossary:write', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if (has_capability('mod/glossary:write', context_module::instance($cm->id))) {
$this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?cmid='.$cm->id
.'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';
} else {
Expand Down
4 changes: 2 additions & 2 deletions blocks/mnet_hosts/block_mnet_hosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function has_config() {
}

function applicable_formats() {
if (has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
if (has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
return array('all' => true, 'mod' => false, 'tag' => false);
} else {
return array('site' => true);
Expand Down Expand Up @@ -59,7 +59,7 @@ function get_content() {
}
}

if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
if (!has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
Expand Down
2 changes: 1 addition & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function _load_instance($instance, $page) {
$this->config = unserialize(base64_decode($instance->configdata));
}
$this->instance = $instance;
$this->context = get_context_instance(CONTEXT_BLOCK, $instance->id);
$this->context = context_block::instance($instance->id);
$this->page = $page;
$this->specialization();
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/news_items/block_news_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function get_content() {
return '';
}

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);

/// User must have perms to view discussions in that forum
if (!has_capability('mod/forum:viewdiscussion', $context)) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/participants/block_participants.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function get_content() {
$this->content = '';
return $this->content;
} else if ($this->page->course->id == SITEID) {
if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/site:viewparticipants', context_system::instance())) {
$this->content = '';
return $this->content;
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/private_files/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
//TODO: add capability check here!

$context = get_context_instance(CONTEXT_USER, $USER->id);
$context = context_user::instance($USER->id);
$title = get_string('privatefiles', 'block_private_files');
$struser = get_string('user');

Expand Down
2 changes: 1 addition & 1 deletion blocks/private_files/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class private_files_tree implements renderable {
public $dir;
public function __construct() {
global $USER;
$this->context = get_context_instance(CONTEXT_USER, $USER->id);
$this->context = context_user::instance($USER->id);
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/quiz_results/block_quiz_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function get_content() {
$context = $this->page->context;
} else {
$cm = get_coursemodule_from_instance('quiz', $quizid, $courseid);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
}
$groupmode = groups_get_activity_groupmode($cm);

Expand Down
2 changes: 1 addition & 1 deletion blocks/rss_client/editfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static function autodiscover_feed_url($url){
$PAGE->set_course($course);
$context = $PAGE->context;
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$PAGE->set_context($context);
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/rss_client/managefeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$PAGE->set_course($course);
$context = $PAGE->context;
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$PAGE->set_context($context);
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/rss_client/viewfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
$PAGE->set_course($course);
$context = $PAGE->context;
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$PAGE->set_context($context);
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/section_links/block_section_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function get_content() {
}

$course = $this->page->course;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);

if ($course->format == 'weeks' or $course->format == 'weekscss') {
$highlight = ceil((time()-$course->startdate)/604800);
Expand Down
2 changes: 1 addition & 1 deletion blocks/selfcompletion/block_selfcompletion.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function get_content() {
$this->content = new stdClass;

// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
$can_edit = has_capability('moodle/course:update', context_course::instance($this->page->course->id));

// Get course completion data
$info = new completion_info($this->page->course);
Expand Down
2 changes: 1 addition & 1 deletion blocks/settings/block_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function get_content() {

// only do search if you have moodle/site:config
if (!empty($this->content->text)) {
if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {
if (has_capability('moodle/site:config',context_system::instance()) ) {
$this->content->footer = $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW));
} else {
$this->content->footer = '';
Expand Down
2 changes: 1 addition & 1 deletion blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function get_content() {

$course = $this->page->course;
require_once($CFG->dirroot.'/course/lib.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);

Expand Down
Loading

0 comments on commit fe2fdd1

Please sign in to comment.