Commit cb640229 authored by tjhunt's avatar tjhunt
Browse files

blocklib: MDL-19010 remove no-longer-necessary global variable use from blocks

parent b80856bd
......@@ -7,7 +7,7 @@ class block_activity_modules extends block_list {
}
function get_content() {
global $CFG, $COURSE, $DB;
global $CFG, $DB;
if($this->content !== NULL) {
return $this->content;
......
......@@ -29,7 +29,7 @@ class block_admin_bookmarks extends block_base {
function get_content() {
global $CFG, $USER, $PAGE;
global $CFG, $USER;
if ($this->content !== NULL) {
return $this->content;
......@@ -62,12 +62,13 @@ class block_admin_bookmarks extends block_base {
$bookmarks = array();
}
if (isset($PAGE->section) and $PAGE->section == 'search'){
// TODO
if (isset($this->page->section) and $this->page->section == 'search'){
// the search page can't be properly bookmarked at present
$this->content->footer = '';
} else if (($section = (isset($PAGE->section) ? $PAGE->section : '')) && (in_array($section, $bookmarks))) {
} else if (($section = (isset($this->page->section) ? $this->page->section : '')) && (in_array($section, $bookmarks))) {
$this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/delete.php?section=' . $section . '&amp;sesskey='.sesskey().'">' . get_string('unbookmarkthispage','admin') . '</a>';
} else if ($section = (isset($PAGE->section) ? $PAGE->section : '')) {
} else if ($section = (isset($this->page->section) ? $this->page->section : '')) {
$this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/create.php?section=' . $section . '&amp;sesskey='.sesskey().'">' . get_string('bookmarkthispage','admin') . '</a>';
} else {
$this->content->footer = '';
......
......@@ -10,13 +10,13 @@ class block_admin_tree extends block_base {
var $destination;
function init() {
global $PAGE;
$this->title = get_string('administrationsite');
$this->version = 2007101509;
$this->currentdepth = 0;
$this->divcounter = 1;
$this->tempcontent = '';
$this->section = (isset($PAGE->section) ? $PAGE->section : '');
// TODO
$this->section = (isset($this->page->section) ? $this->page->section : '');
$this->pathtosection = array();
$this->expandnodes = array();
}
......
......@@ -11,7 +11,7 @@ class block_blog_menu extends block_base {
}
function get_content() {
global $CFG, $USER, $COURSE;
global $CFG, $USER;
if (empty($CFG->bloglevel)) {
$this->content->text = '';
......@@ -47,10 +47,10 @@ class block_blog_menu extends block_base {
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if ($COURSE->id != SITEID) {
if ($this->page->course->id != SITEID) {
$incoursecontext = true;
$curcontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$curcontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
} else {
$incoursecontext = false;
$curcontext = $sitecontext;
......@@ -63,10 +63,10 @@ class block_blog_menu extends block_base {
if ( (isloggedin() && !isguest()) && $incoursecontext
&& $CFG->bloglevel >= BLOG_COURSE_LEVEL && $canviewblogs) {
$coursearg = '&amp;courseid='.$COURSE->id;
$coursearg = '&amp;courseid='.$this->page->course->id;
// a course is specified
$courseviewlink = '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=course&amp;filterselect='. $COURSE->id .'">';
$courseviewlink = '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=course&amp;filterselect='. $this->page->course->id .'">';
$courseviewlink .= get_string('viewcourseentries', 'blog') ."</a></li>\n";
}
......
......@@ -39,7 +39,7 @@ class block_blog_tags extends block_base {
}
function get_content() {
global $CFG, $SITE, $COURSE, $USER, $DB;
global $CFG, $SITE, $USER, $DB;
if (empty($CFG->usetags) || empty($CFG->bloglevel)) {
$this->content->text = '';
......@@ -130,18 +130,18 @@ class block_blog_tags extends block_base {
case BLOG_GROUP_LEVEL:
$filtertype = 'group';
$filterselect = groups_get_course_group($COURSE);
$filterselect = groups_get_course_group($this->page->course);
break;
case BLOG_COURSE_LEVEL:
$filtertype = 'course';
$filterselect = $COURSE->id;
$filterselect = $this->page->course->id;
break;
default:
if (isset($COURSE->id) && $COURSE->id != SITEID) {
if ($this->page->course->id != SITEID) {
$filtertype = 'course';
$filterselect = $COURSE->id;
$filterselect = $this->page->course->id;
} else {
$filtertype = 'site';
$filterselect = SITEID;
......
......@@ -11,7 +11,7 @@ class block_calendar_month extends block_base {
}
function get_content() {
global $USER, $CFG, $SESSION, $COURSE;
global $USER, $CFG, $SESSION;
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
......@@ -21,7 +21,7 @@ class block_calendar_month extends block_base {
return $this->content;
}
// Reset the session variables
calendar_session_vars($COURSE);
calendar_session_vars($this->page->course);
$this->content = new stdClass;
$this->content->text = '';
......@@ -30,7 +30,7 @@ class block_calendar_month extends block_base {
// [pj] To me it looks like this if would never be needed, but Penny added it
// when committing the /my/ stuff. Reminder to discuss and learn what it's about.
// It definitely needs SOME comment here!
$courseshown = $COURSE->id;
$courseshown = $this->page->course->id;
if ($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
......@@ -42,9 +42,9 @@ class block_calendar_month extends block_base {
} else {
//MDL-14693: fix calendar on resource page
$courseshown = optional_param( 'id', $COURSE->id, PARAM_INT );
$courseshown = optional_param( 'id', $this->page->course->id, PARAM_INT );
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => $COURSE);
$filtercourse = array($courseshown => $this->page->course);
$groupeventsfrom = array($courseshown => 1);
}
......@@ -52,9 +52,9 @@ class block_calendar_month extends block_base {
calendar_set_referring_course($courseshown);
// MDL-9059, set to show this course when admins go into a course, then unset it.
if ($COURSE->id != SITEID && !isset($SESSION->cal_courses_shown[$COURSE->id]) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
if ($this->page->course->id != SITEID && !isset($SESSION->cal_courses_shown[$this->page->course->id]) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
$courseset = true;
$SESSION->cal_courses_shown[$COURSE->id] = $COURSE;
$SESSION->cal_courses_shown[$this->page->course->id] = $this->page->course;
}
// Be VERY careful with the format for default courses arguments!
......@@ -73,13 +73,13 @@ class block_calendar_month extends block_base {
$this->content->text .= calendar_top_controls('course', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
$this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
$this->content->text .= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
$this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $COURSE).'</div>';
$this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $this->page->course).'</div>';
}
// MDL-9059, unset this so that it doesn't stay in session
if (!empty($courseset)) {
unset($SESSION->cal_courses_shown[$COURSE->id]);
unset($SESSION->cal_courses_shown[$this->page->course->id]);
}
return $this->content;
......
......@@ -7,7 +7,7 @@ class block_calendar_upcoming extends block_base {
}
function get_content() {
global $USER, $CFG, $SESSION, $COURSE;
global $USER, $CFG, $SESSION;
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
......@@ -17,7 +17,7 @@ class block_calendar_upcoming extends block_base {
return $this->content;
}
// Reset the session variables
calendar_session_vars($COURSE);
calendar_session_vars($this->page->course);
$this->content = new stdClass;
$this->content->text = '';
......@@ -27,7 +27,7 @@ class block_calendar_upcoming extends block_base {
$this->content->footer = '';
} else {
$courseshown = $COURSE->id;
$courseshown = $this->page->course->id;
$this->content->footer = '<br /><a href="'.$CFG->wwwroot.
'/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
get_string('gotocalendar', 'calendar').'</a>...';
......@@ -47,7 +47,7 @@ class block_calendar_upcoming extends block_base {
calendar_set_referring_course(0);
} else {
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => $COURSE);
$filtercourse = array($courseshown => $this->page->course);
$groupeventsfrom = array($courseshown => 1);
}
}
......
......@@ -7,13 +7,13 @@ class block_course_summary extends block_base {
}
function specialization() {
if($this->page->pagetype == PAGE_COURSE_VIEW && $PAGE->course->id != SITEID) {
if($this->page->pagetype == PAGE_COURSE_VIEW && $this->page->course->id != SITEID) {
$this->title = get_string('coursesummary', 'block_course_summary');
}
}
function get_content() {
global $CFG, $COURSE, $PAGE;
global $CFG;
if($this->content !== NULL) {
return $this->content;
......@@ -26,12 +26,12 @@ class block_course_summary extends block_base {
$this->content = new object();
$options = new object();
$options->noclean = true; // Don't clean Javascripts etc
$this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
if ($PAGE->user_is_editing()) {
if($COURSE->id == SITEID) {
$this->content->text = format_text($this->page->course->summary, FORMAT_HTML, $options);
if ($this->page->user_is_editing()) {
if($this->page->course->id == SITEID) {
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
} else {
$editpage = $CFG->wwwroot.'/course/edit.php?id='.$COURSE->id;
$editpage = $CFG->wwwroot.'/course/edit.php?id='.$this->page->course->id;
}
$this->content->text .= "<div class=\"editbutton\"><a href=\"$editpage\"><img src=\"$CFG->pixpath/t/edit.gif\" alt=\"".get_string('edit')."\" /></a></div>";
}
......
......@@ -13,8 +13,8 @@ class block_glossary_random extends block_base {
}
function specialization() {
global $CFG, $COURSE, $DB;
$this->course = $COURSE;
global $CFG, $DB;
$this->course = $this->page->course;
// load userdefined title and make sure it's never empty
if (empty($this->config->title)) {
......@@ -152,7 +152,7 @@ class block_glossary_random extends block_base {
}
function get_content() {
global $USER, $CFG, $COURSE, $DB;
global $USER, $CFG, $DB;
if (empty($this->config->glossary)) {
$this->content->text = get_string('notyetconfigured','block_glossary_random');
......@@ -162,11 +162,7 @@ class block_glossary_random extends block_base {
$glossaryid = $this->config->glossary;
if ($this->course->id == $COURSE->id) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id'=>$this->course->id));
}
$course = $this->page->course;
require_once($CFG->dirroot.'/course/lib.php');
$modinfo = get_fast_modinfo($course);
......
......@@ -406,7 +406,7 @@ class block_base {
* @todo complete documenting this function. Define $options.
*/
function _add_edit_controls($options) {
global $CFG, $USER, $PAGE;
global $CFG, $USER;
// TODO
if (empty($this->instance->pinned)) {
......
......@@ -7,7 +7,7 @@ class block_news_items extends block_base {
}
function get_content() {
global $CFG, $USER, $COURSE;
global $CFG, $USER;
if ($this->content !== NULL) {
return $this->content;
......@@ -22,17 +22,17 @@ class block_news_items extends block_base {
}
if ($COURSE->newsitems) { // Create a nice listing of recent postings
if ($this->page->course->newsitems) { // Create a nice listing of recent postings
require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this
$text = '';
if (!$forum = forum_get_course_forum($COURSE->id, 'news')) {
if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
return '';
}
$modinfo = get_fast_modinfo($COURSE);
$modinfo = get_fast_modinfo($this->page->course);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
......@@ -58,7 +58,7 @@ class block_news_items extends block_base {
/// Get all the recent discussions we're allowed to see
if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
$currentgroup, $COURSE->newsitems) ) {
$currentgroup, $this->page->course->newsitems) ) {
$text .= '('.get_string('nonews', 'forum').')';
$this->content->text = $text;
return $this->content;
......@@ -107,7 +107,7 @@ class block_news_items extends block_base {
} else {
$userid = $USER->id;
}
$this->content->footer .= '<br />'.rss_get_link($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
$this->content->footer .= '<br />'.rss_get_link($this->page->course->id, $userid, 'forum', $forum->id, $tooltiptext);
}
}
......
......@@ -14,7 +14,7 @@ class block_online_users extends block_base {
function has_config() {return true;}
function get_content() {
global $USER, $CFG, $COURSE, $DB;
global $USER, $CFG, $DB;
if ($this->content !== NULL) {
return $this->content;
......@@ -35,7 +35,7 @@ class block_online_users extends block_base {
$timefrom = 100 * floor((time()-$timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache
// Get context so we can check capabilities.
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$context = $this->page->context;
// TODO
if (empty($this->instance->pinned)) {
......@@ -45,12 +45,12 @@ class block_online_users extends block_base {
}
//Calculate if we are in separate groups
$isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS
&& $COURSE->groupmodeforce
$isseparategroups = ($this->page->course->groupmode == SEPARATEGROUPS
&& $this->page->course->groupmodeforce
&& !has_capability('moodle/site:accessallgroups', $context));
//Get the user current group
$currentgroup = $isseparategroups ? groups_get_course_group($COURSE) : NULL;
$currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL;
$groupmembers = "";
$groupselect = "";
......@@ -65,7 +65,7 @@ class block_online_users extends block_base {
$params['currentgroup'] = $currentgroup;
}
if ($COURSE->id == SITEID) { // Site-level
if ($this->page->course->id == SITEID) { // Site-level
$sql = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, MAX(u.lastaccess) AS lastaccess
FROM {user} u $groupmembers
WHERE u.lastaccess > $timefrom
......@@ -103,7 +103,7 @@ class block_online_users extends block_base {
$groupselect $rawhere
GROUP BY u.id";
$params['courseid'] = $COURSE->id;
$params['courseid'] = $this->page->course->id;
}
//Calculate minutes
......@@ -151,12 +151,12 @@ class block_online_users extends block_base {
$this->content->text .= '<li class="listentry">';
$timeago = format_time(time() - $user->lastaccess); //bruno to calculate correctly on frontpage
if ($user->username == 'guest') {
$this->content->text .= '<div class="user">'.print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
$this->content->text .= '<div class="user">'.print_user_picture($user->id, $this->page->course->id, $user->picture, 16, true, false, '', false);
$this->content->text .= get_string('guestuser').'</div>';
} else {
$this->content->text .= '<div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$COURSE->id.'" title="'.$timeago.'">';
$this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
$this->content->text .= '<div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->page->course->id.'" title="'.$timeago.'">';
$this->content->text .= print_user_picture($user->id, $this->page->course->id, $user->picture, 16, true, false, '', false);
$this->content->text .= $user->fullname.'</a></div>';
}
if ($canshowicon and ($USER->id != $user->id) and $user->username != 'guest') { // Only when logged in and messaging active etc
......
......@@ -8,7 +8,7 @@ class block_participants extends block_list {
function get_content() {
global $CFG, $COURSE;
global $CFG;
if (empty($this->instance)) {
$this->content = '';
......@@ -23,7 +23,7 @@ class block_participants extends block_list {
/// MDL-13252 Always get the course context or else the context may be incorrect in the user/index.php
$currentcontext = $this->page->context;
if ($COURSE->id == SITEID) {
if ($this->page->course->id == SITEID) {
if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
$this->content = '';
return $this->content;
......
......@@ -7,8 +7,6 @@ class block_recent_activity extends block_base {
}
function get_content() {
global $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
......@@ -24,7 +22,7 @@ class block_recent_activity extends block_base {
// Slightly hacky way to do it but...
ob_start();
print_recent_activity($COURSE);
print_recent_activity($this->page->course);
$this->content->text = ob_get_contents();
ob_end_clean();
......
......@@ -43,10 +43,10 @@
}
function get_content() {
global $CFG, $editing, $COURSE, $USER;
global $CFG, $editing, $USER;
if (!empty($COURSE)) {
$this->courseid = $COURSE->id;
if (!empty($this->page->course)) {
$this->courseid = $this->page->course->id;
}
/// When displaying feeds in block, we double $CFG->block_rss_client_timeout
......
......@@ -28,7 +28,7 @@ class block_section_links extends block_base {
}
function get_content() {
global $CFG, $USER, $COURSE, $DB;
global $CFG, $USER, $DB;
$highlight = 0;
......
......@@ -11,7 +11,7 @@ class block_site_main_menu extends block_list {
}
function get_content() {
global $USER, $CFG, $COURSE, $DB, $PAGE;
global $USER, $CFG, $DB;
if ($this->content !== NULL) {
return $this->content;
......@@ -29,7 +29,7 @@ class block_site_main_menu extends block_list {
$course = $this->page->course;
require_once($CFG->dirroot.'/course/lib.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);
/// extra fast view mode
......
......@@ -11,7 +11,7 @@ class block_social_activities extends block_list {
}
function get_content() {
global $USER, $CFG, $COURSE, $DB, $PAGE;
global $USER, $CFG, $DB;
if ($this->content !== NULL) {
return $this->content;
......@@ -31,7 +31,7 @@ class block_social_activities extends block_list {
require_once($CFG->dirroot.'/course/lib.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);
/// extra fast view mode
......
......@@ -38,7 +38,7 @@ class block_tags extends block_base {
function get_content() {
global $CFG, $SITE, $COURSE, $USER, $SCRIPT;
global $CFG, $SITE, $USER, $SCRIPT;
if (empty($CFG->usetags)) {
$this->content->text = '';
......@@ -79,10 +79,10 @@ class block_tags extends block_base {
$isguest = has_capability('moodle/legacy:guest', $systemcontext, $USER->id, false);
$loggedin = isloggedin() && !$isguest;
$coursepage = $canedit = false;
$coursepage = (isset($COURSE->id) && $COURSE->id != SITEID);
$coursepage = (isset($this->page->course->id) && $this->page->course->id != SITEID);
$mymoodlepage = ($SCRIPT == '/my/index.php') ? true : false;
$sitepage = (isset($COURSE->id) && $COURSE->id == SITEID && !$mymoodlepage);
$coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$sitepage = (isset($this->page->course->id) && $this->page->course->id == SITEID && !$mymoodlepage);
$coursecontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
if ($coursepage) {
$canedit = has_capability('moodle/tag:create', $systemcontext);
}
......@@ -111,9 +111,9 @@ class block_tags extends block_base {
}
}
if ($coursepage) {
$coursetags = coursetag_print_cloud(coursetag_get_tags($COURSE->id, 0, '', $numoftags, $sort), true);
$coursetags = coursetag_print_cloud(coursetag_get_tags($this->page->course->id, 0, '', $numoftags, $sort), true);
if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang);
$courseflag = '&amp;courseid='.$COURSE->id;
$courseflag = '&amp;courseid='.$this->page->course->id;
}
if ($mymoodlepage) {
$mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true);
......@@ -236,7 +236,7 @@ class block_tags extends block_base {
<form action="{$CFG->wwwroot}/tag/coursetags_add.php" method="post" id="coursetag"
onsubmit="return ctags_checkinput(this.coursetag_new_tag.value)">
<div style="display: none;">
<input type="hidden" name="entryid" value="$COURSE->id" />
<input type="hidden" name="entryid" value="$this->page->course->id" />
<input type="hidden" name="userid" value="$USER->id" />
<input type="hidden" name="sesskey" value="$sesskey" />
</div>
......@@ -266,7 +266,7 @@ EOT;
// add the edit link
$this->content->footer .= '
<div>
<a href="'.$CFG->wwwroot.'/tag/coursetags_edit.php?courseid='.$COURSE->id.'"
<a href="'.$CFG->wwwroot.'/tag/coursetags_edit.php?courseid='.$this->page->course->id.'"
title="'.get_string('edittags', $tagslang).'">'.get_string('edittags', $tagslang).'</a>
</div>';
}
......
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