mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-33061 - lib - Replacement of get_context_instance with the new function call (group 3)
This commit is contained in:
parent
147dc9dafd
commit
41b3836067
9 changed files with 74 additions and 74 deletions
64
blog/lib.php
64
blog/lib.php
|
@ -42,7 +42,7 @@ require_once($CFG->dirroot.'/tag/lib.php');
|
|||
function blog_user_can_edit_entry($blogentry) {
|
||||
global $USER;
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
|
||||
if (has_capability('moodle/blog:manageentries', $sitecontext)) {
|
||||
return true; // can edit any blog entry
|
||||
|
@ -72,7 +72,7 @@ function blog_user_can_view_user_entry($targetuserid, $blogentry=null) {
|
|||
return true; // can view own entries in any case
|
||||
}
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
if (has_capability('moodle/blog:manageentries', $sitecontext)) {
|
||||
return true; // can manage all entries
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ function blog_user_can_view_user_entry($targetuserid, $blogentry=null) {
|
|||
|
||||
case BLOG_USER_LEVEL:
|
||||
default:
|
||||
$personalcontext = get_context_instance(CONTEXT_USER, $targetuserid);
|
||||
$personalcontext = context_user::instance($targetuserid);
|
||||
return has_capability('moodle/user:readuserblogs', $personalcontext);
|
||||
break;
|
||||
|
||||
|
@ -131,7 +131,7 @@ function blog_remove_associations_for_user($userid) {
|
|||
*/
|
||||
function blog_remove_associations_for_course($courseid) {
|
||||
global $DB;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
$DB->delete_records('blog_association', array('contextid' => $context->id));
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ function blog_sync_external_entries($externalblog) {
|
|||
*/
|
||||
function blog_delete_external_entries($externalblog) {
|
||||
global $DB;
|
||||
require_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/blog:manageexternal', context_system::instance());
|
||||
$DB->delete_records_select('post',
|
||||
"module='blog_external' AND " . $DB->sql_compare_text('content') . " = ?",
|
||||
array($externalblog->id));
|
||||
|
@ -406,7 +406,7 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
|
|||
}
|
||||
|
||||
// If blog level is global then display a link to view all site entries
|
||||
if (!empty($CFG->bloglevel) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (!empty($CFG->bloglevel) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) {
|
||||
$options[CONTEXT_SYSTEM] = array('viewsite' => array(
|
||||
'string' => get_string('viewsiteentries', 'blog'),
|
||||
'link' => new moodle_url('/blog/index.php')
|
||||
|
@ -450,7 +450,7 @@ function blog_get_options_for_user(stdClass $user=null) {
|
|||
return $useroptions[$user->id];
|
||||
}
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
$canview = has_capability('moodle/blog:view', $sitecontext);
|
||||
|
||||
if (!$iscurrentuser && $canview && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
|
||||
|
@ -510,7 +510,7 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
|
|||
}
|
||||
|
||||
// Check that the user can associate with the course
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
if (!has_capability('moodle/blog:associatecourse', $sitecontext)) {
|
||||
return $options;
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
|
|||
return $courseoptions[$key];
|
||||
}
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$coursecontext = context_course::instance($course->id, IGNORE_MISSING);
|
||||
$canparticipate = (is_enrolled($coursecontext) or is_viewing($coursecontext));
|
||||
|
||||
if (has_capability('moodle/blog:view', $coursecontext)) {
|
||||
|
@ -587,7 +587,7 @@ function blog_get_options_for_module($module, $user=null) {
|
|||
}
|
||||
|
||||
// Check the user can associate with the module
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
if (!has_capability('moodle/blog:associatemodule', $sitecontext)) {
|
||||
return $options;
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ function blog_get_options_for_module($module, $user=null) {
|
|||
return $moduleoptions[$module->id];
|
||||
}
|
||||
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $module->id);
|
||||
$modcontext = context_module::instance($module->id, IGNORE_MISSING);
|
||||
$canparticipate = (is_enrolled($modcontext) or is_viewing($modcontext));
|
||||
|
||||
if (has_capability('moodle/blog:view', $modcontext)) {
|
||||
|
@ -719,7 +719,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
$headers['strview'] = null;
|
||||
|
||||
$site = $DB->get_record('course', array('id' => SITEID));
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
// Common Lang strings
|
||||
$strparticipants = get_string("participants");
|
||||
$strblogentries = get_string("blogentries", 'blog');
|
||||
|
@ -761,7 +761,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
// Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
|
||||
// Note: if action is set to 'add' or 'edit', we do this at the end
|
||||
if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid) && !in_array($action, array('edit', 'add'))) {
|
||||
$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)));
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
$PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
|
||||
$PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
|
||||
|
@ -784,7 +784,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
} else {
|
||||
$mycourseid = $site->id;
|
||||
}
|
||||
$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)));
|
||||
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
|
||||
|
@ -803,7 +803,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 3: A user's blog entries
|
||||
if (!empty($userid) && empty($entryid) && ((empty($courseid) && empty($modid)) || !$CFG->useblogassociations)) {
|
||||
$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)));
|
||||
$blogurl->param('userid', $userid);
|
||||
$PAGE->set_title("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
|
||||
$PAGE->set_heading("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
|
||||
|
@ -814,7 +814,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 4: No blog associations, no userid
|
||||
if (!$CFG->useblogassociations && empty($userid) && !in_array($action, array('edit', 'add'))) {
|
||||
$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)));
|
||||
$PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
|
||||
$PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
|
||||
$headers['heading'] = get_string('siteblog', 'blog', $shortname);
|
||||
|
@ -822,7 +822,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 5: Blog entries associated with an activity by a specific user (courseid ignored)
|
||||
if (!empty($userid) && !empty($modid) && empty($entryid)) {
|
||||
$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)));
|
||||
$blogurl->param('userid', $userid);
|
||||
$blogurl->param('modid', $modid);
|
||||
|
||||
|
@ -845,8 +845,8 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 6: Blog entries associated with a course by a specific user
|
||||
if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
||||
$blogurl->param('userid', $userid);
|
||||
$blogurl->param('courseid', $courseid);
|
||||
|
||||
|
@ -857,7 +857,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
$a = new stdClass();
|
||||
$a->user = fullname($user);
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$a->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesbyuseraboutcourse', 'blog', $a);
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
|
@ -869,8 +869,8 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 7: Blog entries by members of a group, associated with that group's course
|
||||
if (!empty($groupid) && empty($modid) && empty($entryid)) {
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
||||
$blogurl->param('courseid', $course->id);
|
||||
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
|
@ -883,7 +883,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
$a = new stdClass();
|
||||
$a->group = $group->name;
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$a->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
|
@ -892,8 +892,8 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 8: Blog entries by members of a group, associated with an activity in that course
|
||||
if (!empty($groupid) && !empty($modid) && empty($entryid)) {
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
||||
$headers['cm'] = $cm;
|
||||
$blogurl->param('modid', $modid);
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
|
@ -916,8 +916,8 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 9: All blog entries associated with an activity
|
||||
if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
||||
$PAGE->set_cm($cm, $course);
|
||||
$blogurl->param('modid', $modid);
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
|
@ -932,15 +932,15 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
|
||||
// Case 10: All blog entries associated with a course
|
||||
if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
||||
$blogurl->param('courseid', $courseid);
|
||||
$PAGE->navbar->add($strblogentries, $blogurl);
|
||||
$PAGE->set_title("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
|
||||
$PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
|
||||
$a = new stdClass();
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))));
|
||||
$headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => context_course::instance($course->id))));
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
$headers['strview'] = get_string('viewblogentries', 'blog', $a);
|
||||
$blogurl->remove_params(array('userid'));
|
||||
|
@ -987,9 +987,9 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
|||
*/
|
||||
function blog_get_associated_count($courseid, $cmid=null) {
|
||||
global $DB;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
if ($cmid) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$context = context_module::instance($cmid);
|
||||
}
|
||||
return $DB->count_records('blog_association', array('contextid' => $context->id));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue