Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / blocks / news_items / block_news_items.php
blob58b086c4845202953a554affa34e83d9f38b776f
1 <?PHP //$Id$
3 class block_news_items extends block_base {
4 function init() {
5 $this->title = get_string('latestnews');
6 $this->version = 2007101509;
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 $modinfo = get_fast_modinfo($COURSE);
36 if (empty($modinfo->instances['forum'][$forum->id])) {
37 return '';
39 $cm = $modinfo->instances['forum'][$forum->id];
41 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
43 /// First work out whether we can post to this group and if so, include a link
44 $groupmode = groups_get_activity_groupmode($cm);
45 $currentgroup = groups_get_activity_group($cm, true);
48 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
49 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
50 get_string('addanewtopic', 'forum').'</a>...</div>';
53 /// Get all the recent discussions we're allowed to see
55 if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
56 $currentgroup, $COURSE->newsitems) ) {
57 $text .= '('.get_string('nonews', 'forum').')';
58 $this->content->text = $text;
59 return $this->content;
62 /// Actually create the listing now
64 $strftimerecent = get_string('strftimerecent');
65 $strmore = get_string('more', 'forum');
67 /// Accessibility: markup as a list.
68 $text .= "\n<ul class='unlist'>\n";
69 foreach ($discussions as $discussion) {
71 $discussion->subject = $discussion->name;
73 $discussion->subject = format_string($discussion->subject, true, $forum->course);
75 $text .= '<li class="post">'.
76 '<div class="head">'.
77 '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
78 '<div class="name">'.fullname($discussion).'</div></div>'.
79 '<div class="info">'.$discussion->subject.' '.
80 '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.
81 $strmore.'...</a></div>'.
82 "</li>\n";
84 $text .= "</ul>\n";
86 $this->content->text = $text;
88 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
89 get_string('oldertopics', 'forum').'</a> ...';
91 /// If RSS is activated at site and forum level and this forum has rss defined, show link
92 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
93 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) {
94 require_once($CFG->dirroot.'/lib/rsslib.php'); // We'll need this
95 if ($forum->rsstype == 1) {
96 $tooltiptext = get_string('rsssubscriberssdiscussions','forum',format_string($forum->name));
97 } else {
98 $tooltiptext = get_string('rsssubscriberssposts','forum',format_string($forum->name));
100 if (empty($USER->id)) {
101 $userid = 0;
102 } else {
103 $userid = $USER->id;
105 $this->content->footer .= '<br />'.rss_get_link($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
110 return $this->content;