Commit fe2fdd11 authored by Frederic Massart's avatar Frederic Massart
Browse files

MDL-34456 Librairies: Replaced deprecated get_context_instance()

parent bdaff201
......@@ -61,7 +61,7 @@ class block_admin_bookmarks extends block_base {
* @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);
......
......@@ -4,7 +4,7 @@ require('../../config.php');
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
......
......@@ -5,7 +5,7 @@ require('../../config.php');
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
......
......@@ -98,7 +98,7 @@ class block_blog_menu extends block_base {
$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'));
......
......@@ -118,7 +118,7 @@ class block_blog_tags extends block_base {
// 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')";
}
......
......@@ -28,7 +28,7 @@ class block_calendar_upcoming extends block_base {
$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.'">'.
......
......@@ -36,7 +36,7 @@ require_login();
$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);
......
......@@ -191,7 +191,7 @@ class community_hub_search_form extends moodleform {
//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'),
......
......@@ -113,7 +113,7 @@ class block_community_manager {
$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;
......
......@@ -51,7 +51,7 @@ class block_completionstatus extends block_base {
$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);
......@@ -84,7 +84,7 @@ class block_completionstatus extends block_base {
// 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;
......
......@@ -52,8 +52,8 @@ if ($userid) {
// 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;
......
......@@ -33,17 +33,17 @@ class block_course_list extends block_list {
}
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> ...";
}
}
......@@ -57,12 +57,12 @@ class block_course_list extends block_list {
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');
......@@ -72,16 +72,16 @@ class block_course_list extends block_list {
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();
......@@ -89,7 +89,7 @@ class block_course_list extends block_list {
$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();
......@@ -120,7 +120,7 @@ class block_course_list extends block_list {
$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>";
......
......@@ -28,7 +28,7 @@ class block_course_summary extends block_base {
$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()) {
......
......@@ -265,7 +265,7 @@ class block_edit_form extends moodleform {
$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 {
......
......@@ -45,7 +45,7 @@ class block_glossary_random extends block_base {
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;
......@@ -131,7 +131,7 @@ class block_glossary_random extends block_base {
$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 '';
}
......@@ -162,7 +162,7 @@ class block_glossary_random extends block_base {
//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 {
......
......@@ -10,7 +10,7 @@ class block_mnet_hosts extends block_list {
}
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);
......@@ -59,7 +59,7 @@ class block_mnet_hosts extends block_list {
}
}
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',
......
......@@ -418,7 +418,7 @@ class block_base {
$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();
}
......
......@@ -41,7 +41,7 @@ class block_news_items extends block_base {
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)) {
......
......@@ -26,7 +26,7 @@ class block_participants extends block_list {
$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;
}
......
......@@ -33,7 +33,7 @@ if (isguestuser()) {
}
//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');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment