Checking in skodak's fixes to help blocks in more contexts (esp MyMoodle)
This commit is contained in:
@@ -11,7 +11,7 @@ class block_calendar_month extends block_base {
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $USER, $CFG, $SESSION;
|
||||
global $USER, $CFG, $SESSION, $COURSE;
|
||||
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
|
||||
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
|
||||
|
||||
@@ -28,12 +28,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!
|
||||
if (!empty($this->instance->pageid)) {
|
||||
$courseshown = $this->instance->pageid;
|
||||
}
|
||||
else {
|
||||
$courseshown = SITEID;
|
||||
}
|
||||
$courseshown = $COURSE->id;
|
||||
|
||||
if($courseshown == SITEID) {
|
||||
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
|
||||
@@ -58,13 +53,12 @@ class block_calendar_month extends block_base {
|
||||
$this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
|
||||
// No filters for now
|
||||
|
||||
} elseif (!empty($courseshown)) {
|
||||
} else {
|
||||
// For any other course
|
||||
$this->content->text .= calendar_overlib_html();
|
||||
$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);
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
$this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $course).'</div>';
|
||||
$this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $COURSE).'</div>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class block_calendar_upcoming extends block_base {
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $USER, $CFG, $SESSION;
|
||||
global $USER, $CFG, $SESSION, $COURSE;
|
||||
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
|
||||
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
|
||||
|
||||
@@ -27,12 +27,7 @@ class block_calendar_upcoming extends block_base {
|
||||
$this->content->footer = '';
|
||||
|
||||
} else {
|
||||
if (!empty($this->instance->pageid)) {
|
||||
$courseshown = $this->instance->pageid;
|
||||
}
|
||||
else {
|
||||
$courseshown = SITEID;
|
||||
}
|
||||
$courseshown = $COURSE->id;
|
||||
$this->content->footer = '<br /><a href="'.$CFG->wwwroot.
|
||||
'/calendar/view.php?view=upcoming&course='.$courseshown.'">'.
|
||||
get_string('gotocalendar', 'calendar').'</a>...';
|
||||
|
||||
@@ -7,13 +7,14 @@ class block_course_summary extends block_base {
|
||||
}
|
||||
|
||||
function specialization() {
|
||||
if($this->instance->pagetype == PAGE_COURSE_VIEW && $this->instance->pageid != SITEID) {
|
||||
global $COURSE;
|
||||
if($this->instance->pagetype == PAGE_COURSE_VIEW && $COURSE->id != SITEID) {
|
||||
$this->title = get_string('coursesummary', 'block_course_summary');
|
||||
}
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $CFG, $THEME;
|
||||
global $CFG, $COURSE;
|
||||
|
||||
if($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@@ -23,19 +24,14 @@ class block_course_summary extends block_base {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (empty($this->instance->pageid)) {
|
||||
$this->instance->pageid = SITEID;
|
||||
}
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
|
||||
$this->content = New stdClass;
|
||||
$options->noclean = true; // Don't clean Javascripts etc
|
||||
$this->content->text = format_text($course->summary, FORMAT_HTML, $options);
|
||||
if(isediting($this->instance->pageid)) {
|
||||
if($this->instance->pageid == SITEID) {
|
||||
$this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
|
||||
if(isediting($COURSE->id)) {
|
||||
if($COURSE->id == SITEID) {
|
||||
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/site.php';
|
||||
} else {
|
||||
$editpage = $CFG->wwwroot.'/course/edit.php?id='.$this->instance->pageid;
|
||||
$editpage = $CFG->wwwroot.'/course/edit.php?id='.$COURSE->id;
|
||||
}
|
||||
$this->content->text .= "<div align=\"right\"><a href=\"$editpage\"><img src=\"$CFG->pixpath/t/edit.gif\" alt=\"\" /></a></div>";
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ class block_glossary_random extends block_base {
|
||||
}
|
||||
|
||||
function specialization() {
|
||||
global $CFG;
|
||||
$this->course = get_record('course', 'id', $this->instance->pageid);
|
||||
global $CFG, $COURSE;
|
||||
$this->course = $COURSE;
|
||||
|
||||
// load userdefined title and make sure it's never empty
|
||||
if (empty($this->config->title)) {
|
||||
|
||||
@@ -7,7 +7,7 @@ class block_news_items extends block_base {
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $CFG, $USER;
|
||||
global $CFG, $USER, $COURSE;
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@@ -22,44 +22,39 @@ class block_news_items extends block_base {
|
||||
}
|
||||
|
||||
|
||||
if ($this->instance->pageid == 0) {
|
||||
$this->instance->pageid = SITEID;
|
||||
}
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
|
||||
if ($course->newsitems) { // Create a nice listing of recent postings
|
||||
if ($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($COURSE->id, 'news')) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
|
||||
/// First work out whether we can post to this group and if so, include a link
|
||||
|
||||
if (isteacheredit($course->id)) { /// Teachers can always post
|
||||
if (isteacheredit($COURSE->id)) { /// Teachers can always post
|
||||
$visiblegroups = -1;
|
||||
|
||||
$text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
|
||||
get_string('addanewtopic', 'forum').'</a>...</div>';
|
||||
|
||||
} else { /// Check the group situation
|
||||
$currentgroup = get_current_group($course->id);
|
||||
$currentgroup = get_current_group($COURSE->id);
|
||||
|
||||
if (forum_user_can_post_discussion($forum, $currentgroup)) {
|
||||
$text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
|
||||
get_string('addanewtopic', 'forum').'</a>...</div>';
|
||||
}
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
|
||||
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $COURSE->id)) {
|
||||
$this->content->text = $text;
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$groupmode = groupmode($course, $cm);
|
||||
$groupmode = groupmode($COURSE, $cm);
|
||||
|
||||
/// Decides if current user is allowed to see ALL the current discussions or not
|
||||
|
||||
@@ -73,7 +68,7 @@ class block_news_items extends block_base {
|
||||
/// Get all the recent discussions we're allowed to see
|
||||
|
||||
if (! $discussions = forum_get_discussions($forum->id, 'p.modified DESC', 0, false,
|
||||
$visiblegroups, $course->newsitems) ) {
|
||||
$visiblegroups, $COURSE->newsitems) ) {
|
||||
$text .= '('.get_string('nonews', 'forum').')';
|
||||
$this->content->text = $text;
|
||||
return $this->content;
|
||||
@@ -119,7 +114,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($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class block_online_users extends block_base {
|
||||
function has_config() {return true;}
|
||||
|
||||
function get_content() {
|
||||
global $USER, $CFG;
|
||||
global $USER, $CFG, $COURSE;
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@@ -23,8 +23,6 @@ class block_online_users extends block_base {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
|
||||
$timetoshowusers = 300; //Seconds default
|
||||
if (isset($CFG->block_online_users_timetosee)) {
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
@@ -32,10 +30,10 @@ class block_online_users extends block_base {
|
||||
$timefrom = time()-$timetoshowusers;
|
||||
|
||||
//Calculate if we are in separate groups
|
||||
$isseparategroups = ($course->groupmode == SEPARATEGROUPS && $course->groupmodeforce && !isteacheredit($this->instance->pageid));
|
||||
$isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !isteacheredit($COURSE->id));
|
||||
|
||||
//Get the user current group
|
||||
$currentgroup = $isseparategroups ? get_current_group($this->instance->pageid) : NULL;
|
||||
$currentgroup = $isseparategroups ? get_current_group($COURSE->id) : NULL;
|
||||
|
||||
$groupmembers = "";
|
||||
$groupselect = "";
|
||||
@@ -46,11 +44,11 @@ class block_online_users extends block_base {
|
||||
$groupselect .= " AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
|
||||
}
|
||||
|
||||
if ($this->instance->pageid == SITEID) { // Site-level
|
||||
if ($COURSE->id == SITEID) { // Site-level
|
||||
$courseselect = '';
|
||||
$timeselect = "AND (s.timeaccess > $timefrom OR u.lastaccess > $timefrom)";
|
||||
} else {
|
||||
$courseselect = "AND s.course = '".$this->instance->pageid."'";
|
||||
$courseselect = "AND s.course = '".$COURSE->id."'";
|
||||
$timeselect = "AND s.timeaccess > $timefrom";
|
||||
}
|
||||
|
||||
@@ -69,7 +67,7 @@ class block_online_users extends block_base {
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->instance->pageid == SITEID && $CFG->allusersaresitestudents) {
|
||||
if ($COURSE->id == SITEID && $CFG->allusersaresitestudents) {
|
||||
if ($siteusers = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.picture, u.lastaccess
|
||||
FROM {$CFG->prefix}user u
|
||||
WHERE u.lastaccess > $timefrom AND u.username <> 'guest'
|
||||
@@ -88,7 +86,7 @@ class block_online_users extends block_base {
|
||||
$groupmembers
|
||||
WHERE u.id = s.userid $courseselect $groupselect $timeselect ";
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
if (!isteacher($COURSE->id)) {
|
||||
// Hide hidden teachers from students.
|
||||
$findteacherssql .= 'AND s.authority > 0 ';
|
||||
}
|
||||
@@ -116,8 +114,8 @@ class block_online_users extends block_base {
|
||||
foreach ($users as $user) {
|
||||
$this->content->text .= '<li class="listentry">';
|
||||
$timeago = format_time(time() - max($user->timeaccess, $user->lastaccess)); //bruno to calculate correctly on frontpage
|
||||
$this->content->text .= print_user_picture($user->id, $this->instance->pageid, $user->picture, 16, true).' ';
|
||||
$this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$this->instance->pageid.'" title="'.$timeago.'">'.$user->fullname.'</a>';
|
||||
$this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true).' ';
|
||||
$this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$COURSE->id.'" title="'.$timeago.'">'.$user->fullname.'</a>';
|
||||
if (!empty($USER->id) and ($USER->id != $user->id) and !empty($CFG->messaging) and !isguest()) { // Only when logged in
|
||||
$this->content->text .= "\n".' <a title="'.get_string('messageselectadd').'" target="message_'.$user->id.'" href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'
|
||||
.'<img class="icon message" src="'.$CFG->pixpath.'/t/message.gif" alt="'. get_string('messageselectadd') .'" /></a>';
|
||||
|
||||
@@ -7,6 +7,7 @@ class block_recent_activity extends block_base {
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $COURSE;
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@@ -21,11 +22,9 @@ class block_recent_activity extends block_base {
|
||||
$this->content->text = '';
|
||||
$this->content->footer = '';
|
||||
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
|
||||
// Slightly hacky way to do it but...
|
||||
ob_start();
|
||||
print_recent_activity($course);
|
||||
print_recent_activity($COURSE);
|
||||
$this->content->text = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $CFG, $editing;
|
||||
global $CFG, $editing, $COURSE;
|
||||
|
||||
require_once($CFG->libdir .'/rsslib.php');
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
$isteacher = false;
|
||||
$this->courseid = SITEID;
|
||||
if ($this->instance->pagetype == PAGE_COURSE_VIEW) {
|
||||
$this->courseid = $this->instance->pageid;
|
||||
$this->courseid = $COURSE->id;
|
||||
$isteacher = isteacher($this->courseid);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user