Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file contains the news item block class, based upon block_base.
19
 *
20
 * @package    block_news_items
21
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Class block_news_items
27
 *
28
 * @package    block_news_items
29
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class block_news_items extends block_base {
33
    function init() {
34
        $this->title = get_string('pluginname', 'block_news_items');
35
    }
36
 
37
    function get_content() {
38
        global $CFG, $USER;
39
 
40
        if ($this->content !== NULL) {
41
            return $this->content;
42
        }
43
 
44
        $this->content = new stdClass;
45
        $this->content->text = '';
46
        $this->content->footer = '';
47
 
48
        if (empty($this->instance)) {
49
            return $this->content;
50
        }
51
 
52
 
53
        if ($this->page->course->newsitems) {   // Create a nice listing of recent postings
54
 
55
            require_once($CFG->dirroot.'/mod/forum/lib.php');   // We'll need this
56
 
57
            $text = '';
58
 
59
            if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
60
                return '';
61
            }
62
 
63
            $modinfo = get_fast_modinfo($this->page->course);
64
            if (empty($modinfo->instances['forum'][$forum->id])) {
65
                return '';
66
            }
67
            $cm = $modinfo->instances['forum'][$forum->id];
68
 
69
            if (!$cm->uservisible) {
70
                return '';
71
            }
72
 
73
            $context = context_module::instance($cm->id);
74
 
75
        /// User must have perms to view discussions in that forum
76
            if (!has_capability('mod/forum:viewdiscussion', $context)) {
77
                return '';
78
            }
79
 
80
        /// First work out whether we can post to this group and if so, include a link
81
            $groupmode    = groups_get_activity_groupmode($cm);
82
            $currentgroup = groups_get_activity_group($cm, true);
83
 
84
            if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
85
                $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
86
                          get_string('addanewtopic', 'forum').'</a>...</div>';
87
            }
88
 
89
        /// Get all the recent discussions we're allowed to see
90
 
91
            // This block displays the most recent posts in a forum in
92
            // descending order. The call to default sort order here will use
93
            // that unless the discussion that post is in has a timestart set
94
            // in the future.
95
            // This sort will ignore pinned posts as we want the most recent.
96
            $sort = forum_get_default_sort_order(true, 'p.modified', 'd', false);
97
            if (! $discussions = forum_get_discussions($cm, $sort, false,
98
                                                        -1, $this->page->course->newsitems,
99
                                                        false, -1, 0, FORUM_POSTS_ALL_USER_GROUPS) ) {
100
                $text .= '('.get_string('nonews', 'forum').')';
101
                $this->content->text = $text;
102
                return $this->content;
103
            }
104
 
105
        /// Actually create the listing now
106
 
107
            $strposttimeformat = get_string('strftimedatetime', 'core_langconfig');
108
            $strmore = get_string('more', 'forum');
109
 
110
        /// Accessibility: markup as a list.
111
            $text .= "\n<ul class='unlist'>\n";
112
            foreach ($discussions as $discussion) {
113
 
114
                $discussion->subject = $discussion->name;
115
 
116
                $discussion->subject = format_string($discussion->subject, true, $forum->course);
117
 
118
                $posttime = $discussion->modified;
119
                if (!empty($CFG->forum_enabletimedposts) && ($discussion->timestart > $posttime)) {
120
                    $posttime = $discussion->timestart;
121
                }
122
 
123
                // If the user who created the discussion post has been deleted, indicate so.
124
                if ($discussion->userdeleted) {
125
                    $userfullname = get_string('deleteduser', 'mod_forum');
126
                } else {
127
                    $userfullname = fullname($discussion, has_capability('moodle/site:viewfullnames', $context));
128
                }
129
 
130
                $text .= '<li class="post">'.
131
                         '<div class="head clearfix">'.
132
                         '<div class="date">'.userdate($posttime, $strposttimeformat).'</div>'.
133
                         '<div class="name">'.$userfullname.'</div>'.
134
                         '</div>'.
135
                         '<div class="info"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.$discussion->subject.'</a></div>'.
136
                         "</li>\n";
137
            }
138
            $text .= "</ul>\n";
139
 
140
            $this->content->text = $text;
141
 
142
            $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
143
                                      get_string('oldertopics', 'forum').'</a> ...';
144
 
145
        /// If RSS is activated at site and forum level and this forum has rss defined, show link
146
            if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
147
                $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) {
148
                require_once($CFG->dirroot.'/lib/rsslib.php');   // We'll need this
149
                if ($forum->rsstype == 1) {
150
                    $tooltiptext = get_string('rsssubscriberssdiscussions','forum');
151
                } else {
152
                    $tooltiptext = get_string('rsssubscriberssposts','forum');
153
                }
154
                if (!isloggedin()) {
155
                    $userid = $CFG->siteguest;
156
                } else {
157
                    $userid = $USER->id;
158
                }
159
 
160
                $this->content->footer .= '<br />'.rss_get_link($context->id, $userid, 'mod_forum', $forum->id, $tooltiptext);
161
            }
162
 
163
        }
164
 
165
        return $this->content;
166
    }
167
}
168
 
169