mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
Major gain in efficiency for the latest news block and better styles
Still working on more improvements here
This commit is contained in:
parent
7270d81fad
commit
90ec387a54
5 changed files with 93 additions and 32 deletions
|
@ -21,19 +21,89 @@ class block_news_items extends block_base {
|
|||
return $this->content;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
|
||||
$course = get_record('course', 'id', $this->instance->pageid);
|
||||
|
||||
if ($course->newsitems) {
|
||||
$news = forum_get_course_forum($this->instance->pageid, 'news');
|
||||
// Slightly hacky way to do it but...
|
||||
ob_start();
|
||||
forum_print_latest_discussions($news->id, $course->newsitems, 'minimal', '', get_current_group($this->instance->pageid));
|
||||
$this->content->text = ob_get_contents();
|
||||
ob_end_clean();
|
||||
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')) {
|
||||
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
|
||||
$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);
|
||||
|
||||
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)) {
|
||||
$this->content->text = $text;
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$groupmode = groupmode($course, $cm);
|
||||
|
||||
/// Decides if current user is allowed to see ALL the current discussions or not
|
||||
|
||||
if (!$currentgroup and ($groupmode != SEPARATEGROUPS) ) {
|
||||
$visiblegroups = -1;
|
||||
} else {
|
||||
$visiblegroups = $currentgroup;
|
||||
}
|
||||
}
|
||||
|
||||
/// 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) ) {
|
||||
$text .= '('.get_string('nonews', 'forum').')';
|
||||
$this->content->text = $text;
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/// Actually create the listing now
|
||||
|
||||
$strftimerecent = get_string('strftimerecent');
|
||||
$strmore = get_string('more', 'forum');
|
||||
|
||||
foreach ($discussions as $discussion) {
|
||||
|
||||
$discussion->subject = $discussion->name;
|
||||
|
||||
if (!empty($CFG->filterall)) {
|
||||
$discussion->subject = filter_text($discussion->subject, $forum->course);
|
||||
}
|
||||
|
||||
$text .= '<p class="post">'.
|
||||
'<span class="head">'.userdate($discussion->modified, $strftimerecent).'<br />'.
|
||||
fullname($discussion).'</span><br />'.
|
||||
'<span class="info">'.$discussion->subject.' '.
|
||||
'<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.
|
||||
$strmore.'...</a></span>'.
|
||||
'</p>';
|
||||
}
|
||||
|
||||
$this->content->text = $text;
|
||||
|
||||
$this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
|
||||
get_string('oldertopics', 'forum').'</a> ...';
|
||||
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1214,7 +1214,7 @@ function forum_count_unrated_posts($discussionid, $userid) {
|
|||
}
|
||||
|
||||
function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
|
||||
$user=0, $fullpost=true, $visiblegroups=-1) {
|
||||
$user=0, $fullpost=true, $visiblegroups=-1, $limit=0) {
|
||||
/// Get all discussions in a forum
|
||||
global $CFG;
|
||||
|
||||
|
@ -1224,6 +1224,11 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
|
|||
$userselect = "";
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$limit = " LIMIT $limit ";
|
||||
} else {
|
||||
$limit = "";
|
||||
}
|
||||
|
||||
if ($visiblegroups == -1) {
|
||||
$groupselect = "";
|
||||
|
@ -1252,7 +1257,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
|
|||
AND p.parent = 0
|
||||
AND p.userid = u.id $groupselect $userselect
|
||||
AND (d.usermodified = um.id OR d.usermodified = 0)
|
||||
ORDER BY $forumsort");
|
||||
ORDER BY $forumsort $limit");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -373,7 +373,7 @@ th {
|
|||
color:#990000;
|
||||
}
|
||||
|
||||
.forumheadminimal {
|
||||
.sideblock .post .head {
|
||||
color:#555555;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,32 +207,16 @@ table.formtable tbody th {
|
|||
}
|
||||
|
||||
.forumaddnew,
|
||||
.forumaddnewminimal,
|
||||
.forumnodiscuss,
|
||||
.forumnodiscussminimal,
|
||||
.forumolddiscussminimal,
|
||||
.noticeboxcontent {
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.forumnodiscuss,
|
||||
.forumnodiscussminimal {
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.forumpostheadername,
|
||||
.forumpostheaderreplies,
|
||||
.forumpostheaderdate {
|
||||
font-size:small;
|
||||
}
|
||||
|
||||
.forumaddnewminimal,
|
||||
.forumnodiscussminimal,
|
||||
.forumheadminimal,
|
||||
.foruminfominimal,
|
||||
.forumolddiscussminimal {
|
||||
font-size:x-small;
|
||||
}
|
||||
|
||||
.forumpost .topic .subject {
|
||||
font-weight: bold;
|
||||
|
@ -408,6 +392,12 @@ table.calendar-controls .next {
|
|||
text-align:center;
|
||||
}
|
||||
|
||||
.sideblock .head,
|
||||
.sideblock .info {
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
|
||||
/* block_rss_client.php */
|
||||
.rssclientlink {
|
||||
font-size:x-small;
|
||||
|
|
|
@ -409,10 +409,6 @@ body#mod-forum-search .introcontent {
|
|||
font-weight:bold;
|
||||
}
|
||||
|
||||
.forumolddiscussminimal {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.forumolddiscuss {
|
||||
text-align: right;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue