Should be $COURSE not $course
[moodle-linuxchix.git] / blocks / news_items / block_news_items.php
bloba4d7f3e2fd3a62f0cca1c218925783d8b77dc545
1 <?PHP //$Id$
3 class block_news_items extends block_base {
4 function init() {
5 $this->title = get_string('latestnews');
6 $this->version = 2005030800;
9 function get_content() {
10 global $CFG, $USER, $COURSE;
12 if ($this->content !== NULL) {
13 return $this->content;
16 $this->content = new stdClass;
17 $this->content->text = '';
18 $this->content->footer = '';
20 if (empty($this->instance)) {
21 return $this->content;
25 if ($COURSE->newsitems) { // Create a nice listing of recent postings
27 require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this
29 $text = '';
31 if (!$forum = forum_get_course_forum($COURSE->id, 'news')) {
32 return '';
35 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $COURSE->id)) {
36 return '';
39 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
41 /// First work out whether we can post to this group and if so, include a link
42 $groupmode = groupmode($COURSE, $cm);
43 $currentgroup = get_and_set_current_group($COURSE, $groupmode);
46 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
47 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
48 get_string('addanewtopic', 'forum').'</a>...</div>';
51 /// Get all the recent discussions we're allowed to see
53 if (! $discussions = forum_get_discussions($forum->id, 'p.modified DESC', 0, false,
54 $currentgroup, $COURSE->newsitems) ) {
55 $text .= '('.get_string('nonews', 'forum').')';
56 $this->content->text = $text;
57 return $this->content;
60 /// Actually create the listing now
62 $strftimerecent = get_string('strftimerecent');
63 $strmore = get_string('more', 'forum');
65 /// Accessibility: markup as a list.
66 $text .= "\n<ul class='unlist'>\n";
67 foreach ($discussions as $discussion) {
69 $discussion->subject = $discussion->name;
71 $discussion->subject = format_string($discussion->subject, true, $forum->course);
73 $text .= '<li class="post">'.
74 '<div class="head">'.
75 '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
76 '<div class="name">'.fullname($discussion).'</div></div>'.
77 '<div class="info">'.$discussion->subject.' '.
78 '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.
79 $strmore.'...</a></div>'.
80 "</li>\n";
82 $text .= "</ul>\n";
84 $this->content->text = $text;
86 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
87 get_string('oldertopics', 'forum').'</a> ...';
89 /// If RSS is activated at site and forum level and this forum has rss defined, show link
90 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
91 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) {
92 require_once($CFG->dirroot.'/lib/rsslib.php'); // We'll need this
93 if ($forum->rsstype == 1) {
94 $tooltiptext = get_string('rsssubscriberssdiscussions','forum',format_string($forum->name));
95 } else {
96 $tooltiptext = get_string('rsssubscriberssposts','forum',format_string($forum->name));
98 if (empty($USER->id)) {
99 $userid = 0;
100 } else {
101 $userid = $USER->id;
103 $this->content->footer .= '<br />'.rss_get_link($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
108 return $this->content;