Skip to content

Commit

Permalink
MDL-56270 mod_book: Add next/prev chapter to attributes
Browse files Browse the repository at this point in the history
This adds the details of the next/previous chapter to the image
attributes and link for the in-page chapter-to-chapter navigation.
  • Loading branch information
andrewnicols committed Oct 5, 2016
1 parent ddd8dc0 commit 3cf1fea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mod/book/lang/en/book.php
Expand Up @@ -84,7 +84,9 @@
$string['confchapterdeleteall'] = 'Do you really want to delete this chapter and all its subchapters?';
$string['top'] = 'top';
$string['navprev'] = 'Previous';
$string['navprevtitle'] = 'Previous: {$a}';
$string['navnext'] = 'Next';
$string['navnexttitle'] = 'Next: {$a}';
$string['navexit'] = 'Exit book';
$string['book:addinstance'] = 'Add a new book';
$string['book:read'] = 'View book';
Expand Down
12 changes: 8 additions & 4 deletions mod/book/view.php
Expand Up @@ -126,8 +126,10 @@
// prepare chapter navigation icons
$previd = null;
$prevtitle = null;
$navprevtitle = null;
$nextid = null;
$nexttitle = null;
$navnexttitle = null;
$last = null;
foreach ($chapters as $ch) {
if (!$edit and $ch->hidden) {
Expand All @@ -136,11 +138,13 @@
if ($last == $chapter->id) {
$nextid = $ch->id;
$nexttitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
$navnexttitle = get_string('navnexttitle', 'mod_book', $nexttitle);
break;
}
if ($ch->id != $chapter->id) {
$previd = $ch->id;
$prevtitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
$navprevtitle = get_string('navprevtitle', 'mod_book', $prevtitle);
}
$last = $ch->id;
}
Expand All @@ -155,9 +159,9 @@
if ($previd) {
$navprev = get_string('navprev', 'book');
if ($book->navstyle == 1) {
$chnavigation .= '<a title="' . $navprev . '" class="bookprev" href="view.php?id=' .
$chnavigation .= '<a title="' . $navprevtitle . '" class="bookprev" href="view.php?id=' .
$cm->id . '&amp;chapterid=' . $previd . '">' .
'<img src="' . $OUTPUT->pix_url($navprevicon, 'mod_book') . '" class="icon" alt="' . $navprev . '"/></a>';
'<img src="' . $OUTPUT->pix_url($navprevicon, 'mod_book') . '" class="icon" alt="' . $navprevtitle . '"/></a>';
} else {
$chnavigation .= '<a title="' . $navprev . '" class="bookprev" href="view.php?id=' .
$cm->id . '&amp;chapterid=' . $previd . '">' .
Expand All @@ -172,9 +176,9 @@
if ($nextid) {
$navnext = get_string('navnext', 'book');
if ($book->navstyle == 1) {
$chnavigation .= '<a title="' . $navnext . '" class="booknext" href="view.php?id=' .
$chnavigation .= '<a title="' . $navnexttitle . '" class="booknext" href="view.php?id=' .
$cm->id . '&amp;chapterid='.$nextid.'">' .
'<img src="' . $OUTPUT->pix_url($navnexticon, 'mod_book').'" class="icon" alt="' . $navnext . '" /></a>';
'<img src="' . $OUTPUT->pix_url($navnexticon, 'mod_book').'" class="icon" alt="' . $navnexttitle . '" /></a>';
} else {
$chnavigation .= ' <a title="' . $navnext . '" class="booknext" href="view.php?id=' .
$cm->id . '&amp;chapterid='.$nextid.'">' .
Expand Down

0 comments on commit 3cf1fea

Please sign in to comment.