MDL-8501 mod_forum: Adding links to navigate between discussions

This commit is contained in:
Frederic Massart 2014-07-02 16:06:49 +08:00
parent 826cb6f6a1
commit d78628783b
4 changed files with 66 additions and 0 deletions

View File

@ -225,6 +225,8 @@
$PAGE->set_title("$course->shortname: ".format_string($discussion->name));
$PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform);
$renderer = $PAGE->get_renderer('mod_forum');
echo $OUTPUT->header();
$headingvalue = format_string($forum->name);
@ -256,6 +258,10 @@
}
}
// Output the links to neighbour discussions.
$neighbours = forum_get_discussion_neighbours($cm, $discussion);
echo $renderer->neighbouring_discussion_navigation($neighbours['prev'], $neighbours['next']);
/// Print the controls across the top
echo '<div class="discussioncontrols clearfix">';

View File

@ -317,6 +317,7 @@ $string['namenews'] = 'News forum';
$string['namenews_help'] = 'The news forum is a special forum for announcements that is automatically created when a course is created. A course can have only one news forum. Only teachers and administrators can post in the news forum. The "Latest news" block will display recent discussions from the news forum.';
$string['namesocial'] = 'Social forum';
$string['nameteacher'] = 'Teacher forum';
$string['nextdiscussiona'] = 'Next discussion: {$a}';
$string['newforumposts'] = 'New forum posts';
$string['noattachments'] = 'There are no attachments to this post';
$string['nodiscussions'] = 'There are no discussion topics yet in this forum';
@ -359,6 +360,7 @@ $string['page-mod-forum-view'] = 'Forum module main page';
$string['page-mod-forum-discuss'] = 'Forum module discussion thread page';
$string['parent'] = 'Show parent';
$string['parentofthispost'] = 'Parent of this post';
$string['prevdiscussiona'] = 'Previous discussion: {$a}';
$string['pluginadministration'] = 'Forum administration';
$string['pluginname'] = 'Forum';
$string['postadded'] = '<p>Your post was successfully added.</p> <p>You have {$a} to edit it if you want to make any changes.</p>';

View File

@ -32,6 +32,39 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class mod_forum_renderer extends plugin_renderer_base {
/**
* Returns the navigation to the previous and next discussion.
*
* @param mixed $prev Previous discussion record, or false.
* @param mixed $next Next discussion record, or false.
* @return string The output.
*/
public function neighbouring_discussion_navigation($prev, $next) {
$html = '';
if ($prev || $next) {
$html .= html_writer::start_tag('div', array('class' => 'discussion-nav clearfix'));
$html .= html_writer::start_tag('ul');
if ($prev) {
$url = new moodle_url('/mod/forum/discuss.php', array('d' => $prev->id));
$html .= html_writer::start_tag('li', array('class' => 'prev-discussion'));
$html .= html_writer::link($url, $prev->name,
array('aria-label' => get_string('prevdiscussiona', 'mod_forum', $prev->name)));
$html .= html_writer::end_tag('li');
}
if ($next) {
$url = new moodle_url('/mod/forum/discuss.php', array('d' => $next->id));
$html .= html_writer::start_tag('li', array('class' => 'next-discussion'));
$html .= html_writer::link($url, $next->name,
array('aria-label' => get_string('nextdiscussiona', 'mod_forum', $next->name)));
$html .= html_writer::end_tag('li');
}
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_tag('div');
}
return $html;
}
/**
* This method is used to generate HTML for a subscriber selection form that
* uses two user_selector controls

View File

@ -112,3 +112,28 @@ span.unread {
.forumpost.unread .row.header {
border-bottom: 1px solid #DDD;
}
/* Discussion navigation */
.path-mod-forum .discussion-nav {
margin: .5em 0;
}
.path-mod-forum .discussion-nav ul {
margin: 0;
list-style: none;
}
.dir-rtl.path-mod-forum .discussion-nav .next-discussion:after,
.path-mod-forum .discussion-nav .prev-discussion:before {
content: ' ◄ ';
}
.dir-rtl.path-mod-forum .discussion-nav .prev-discussion:before,
.path-mod-forum .discussion-nav .next-discussion:after {
content: ' ► ';
}
.dir-rtl.path-mod-forum .discussion-nav .prev-discussion,
.path-mod-forum .discussion-nav .next-discussion {
float: right;
}
.dir-rtl.path-mod-forum .discussion-nav .next-discussion,
.path-mod-forum .discussion-nav .prev-discussion {
float: left;
}