diff --git a/mod/book/backup/moodle2/backup_book_stepslib.php b/mod/book/backup/moodle2/backup_book_stepslib.php
index 27f1c89099b7f..50fbd51a4cb97 100644
--- a/mod/book/backup/moodle2/backup_book_stepslib.php
+++ b/mod/book/backup/moodle2/backup_book_stepslib.php
@@ -31,10 +31,14 @@ class backup_book_activity_structure_step extends backup_activity_structure_step
protected function define_structure() {
- // Define each element separated
- $book = new backup_nested_element('book', array('id'), array('name', 'intro', 'introformat', 'numbering', 'customtitles', 'timecreated', 'timemodified'));
+ // Define each element separated.
+ $book = new backup_nested_element('book', array('id'), array(
+ 'name', 'intro', 'introformat', 'numbering', 'navstyle',
+ 'customtitles', 'timecreated', 'timemodified'));
$chapters = new backup_nested_element('chapters');
- $chapter = new backup_nested_element('chapter', array('id'), array('pagenum', 'subchapter', 'title', 'content', 'contentformat', 'hidden', 'timemcreated', 'timemodified', 'importsrc',));
+ $chapter = new backup_nested_element('chapter', array('id'), array(
+ 'pagenum', 'subchapter', 'title', 'content', 'contentformat',
+ 'hidden', 'timemcreated', 'timemodified', 'importsrc'));
$book->add_child($chapters);
$chapters->add_child($chapter);
diff --git a/mod/book/db/install.xml b/mod/book/db/install.xml
index 546b1a2bfb699..c1b8598d71b93 100644
--- a/mod/book/db/install.xml
+++ b/mod/book/db/install.xml
@@ -12,6 +12,7 @@
+
@@ -40,4 +41,4 @@
-
\ No newline at end of file
+
diff --git a/mod/book/db/upgrade.php b/mod/book/db/upgrade.php
index 744fedf516f50..e4443685a9518 100644
--- a/mod/book/db/upgrade.php
+++ b/mod/book/db/upgrade.php
@@ -203,6 +203,19 @@ function xmldb_book_upgrade($oldversion) {
// Moodle v2.7.0 release upgrade line.
// Put any upgrade step following this.
+ if ($oldversion < 2014051201) {
+ // MDL-36874 Book update.
+ $table = new xmldb_table('book');
+ $field = new xmldb_field('navstyle', XMLDB_TYPE_INTEGER, '4' , XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1);
+
+ // Conditionally launch add field navstyle.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // MDL-36874 savepoint reached.
+ upgrade_mod_savepoint(true, 2014051201, 'book');
+ }
return true;
}
diff --git a/mod/book/lang/en/book.php b/mod/book/lang/en/book.php
index 94359f81e08c3..d027a5bc7f01b 100644
--- a/mod/book/lang/en/book.php
+++ b/mod/book/lang/en/book.php
@@ -51,6 +51,14 @@
$string['eventchapterupdated'] = 'Chapter updated';
$string['eventchapterviewed'] = 'Chapter viewed';
$string['subchapter'] = 'Subchapter';
+$string['navimages'] = 'Images';
+$string['navoptions'] = 'Available options for navigational links';
+$string['navoptions_desc'] = 'Options for displaying navigation on the book pages';
+$string['navstyle'] = 'Style of navigation';
+$string['navstyle_help'] = '* Images - Icons are used for navigation
+* Text - Chapter titles are used for navigation';
+$string['navtext'] = 'Text';
+$string['navtoc'] = 'TOC Only';
$string['nocontent'] = 'No content has been added to this book yet.';
$string['numbering'] = 'Chapter formatting';
$string['numbering_help'] = '* None - Chapter and subchapter titles have no formatting
diff --git a/mod/book/lib.php b/mod/book/lib.php
index 8f19e2a75667a..6e3fabc6b3992 100644
--- a/mod/book/lib.php
+++ b/mod/book/lib.php
@@ -41,6 +41,28 @@ function book_get_numbering_types() {
);
}
+/**
+ * Returns list of available navigation link types.
+ * @return array
+ */
+function book_get_nav_types() {
+ require_once(dirname(__FILE__).'/locallib.php');
+
+ return array (
+ BOOK_LINK_TOCONLY => get_string('navtoc', 'mod_book'),
+ BOOK_LINK_IMAGE => get_string('navimages', 'mod_book'),
+ BOOK_LINK_TEXT => get_string('navtext', 'mod_book'),
+ );
+}
+
+/**
+ * Returns list of available navigation link CSS classes.
+ * @return array
+ */
+function book_get_nav_classes() {
+ return array ('navtoc', 'navimages', 'navtext');
+}
+
/**
* Returns all other caps used in module
* @return array
diff --git a/mod/book/locallib.php b/mod/book/locallib.php
index 0bc9061055708..e9c6d5f9deaf3 100644
--- a/mod/book/locallib.php
+++ b/mod/book/locallib.php
@@ -39,6 +39,16 @@
define('BOOK_NUM_BULLETS', '2');
define('BOOK_NUM_INDENTED', '3');
+/**
+ * The following defines are used to define the navigation style used within a book.
+ * BOOK_LINK_TOCONLY Only the table of contents is shown, in a side region.
+ * BOOK_LINK_IMAGE Arrows link to previous/next/exit pages, in addition to the TOC.
+ * BOOK_LINK_TEXT Page names and arrows link to previous/next/exit pages, in addition to the TOC.
+ */
+define ('BOOK_LINK_TOCONLY', '0');
+define ('BOOK_LINK_IMAGE', '1');
+define ('BOOK_LINK_TEXT', '2');
+
/**
* Preload book chapters and fix toc structure if necessary.
*
diff --git a/mod/book/mod_form.php b/mod/book/mod_form.php
index 40d9f72d3d422..e2ac0961c2b20 100644
--- a/mod/book/mod_form.php
+++ b/mod/book/mod_form.php
@@ -70,6 +70,25 @@ function definition() {
$mform->addHelpButton('numbering', 'numbering', 'mod_book');
$mform->setDefault('numbering', $config->numbering);
+ $alloptions = book_get_nav_types();
+ $allowed = explode(',', $config->navoptions);
+ $options = array();
+ foreach ($allowed as $type) {
+ if (isset($alloptions[$type])) {
+ $options[$type] = $alloptions[$type];
+ }
+ }
+ if ($this->current->instance) {
+ if (!isset($options[$this->current->navstyle])) {
+ if (isset($alloptions[$this->current->navstyle])) {
+ $options[$this->current->navstyle] = $alloptions[$this->current->navstyle];
+ }
+ }
+ }
+ $mform->addElement('select', 'navstyle', get_string('navstyle', 'book'), $options);
+ $mform->addHelpButton('navstyle', 'navstyle', 'mod_book');
+ $mform->setDefault('navstyle', $config->navstyle);
+
$mform->addElement('checkbox', 'customtitles', get_string('customtitles', 'book'));
$mform->addHelpButton('customtitles', 'customtitles', 'mod_book');
$mform->setDefault('customtitles', 0);
diff --git a/mod/book/settings.php b/mod/book/settings.php
index 11420ae9db32b..d759e3976eded 100644
--- a/mod/book/settings.php
+++ b/mod/book/settings.php
@@ -38,12 +38,20 @@
get_string('numberingoptions', 'mod_book'), get_string('numberingoptions_desc', 'mod_book'),
array_keys($options), $options));
+ $navoptions = book_get_nav_types();
+ $settings->add(new admin_setting_configmultiselect('book/navoptions',
+ get_string('navoptions', 'mod_book'), get_string('navoptions_desc', 'mod_book'),
+ array_keys($navoptions), $navoptions));
// Modedit defaults.
- $settings->add(new admin_setting_heading('bookmodeditdefaults', get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin')));
+ $settings->add(new admin_setting_heading('bookmodeditdefaults',
+ get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin')));
$settings->add(new admin_setting_configselect('book/numbering',
get_string('numbering', 'mod_book'), '', BOOK_NUM_NUMBERS, $options));
+ $settings->add(new admin_setting_configselect('book/navstyle',
+ get_string('navstyle', 'mod_book'), '', BOOK_LINK_IMAGE, $navoptions));
+
}
diff --git a/mod/book/styles.css b/mod/book/styles.css
index 4e2daa4a6a384..4a607673da6ad 100644
--- a/mod/book/styles.css
+++ b/mod/book/styles.css
@@ -19,6 +19,9 @@
.path-mod-book .navtop {
margin-bottom: 0.5em;
}
+.path-mod-book .navbottom {
+ margin-top: 0.5em;
+}
/* == Fake toc block == */
@@ -88,3 +91,45 @@
.path-mod-book .book_toc_indented li li {
list-style: none;
}
+
+/* Text style links */
+.navtop.navtext .chaptername,
+.navbottom.navtext .chaptername {
+ font-weight: bolder;
+}
+.navtop.navtext a,
+.navbottom.navtext a {
+ display: inline-block;
+ max-width: 45%;
+}
+.navtop.navtext a.bookprev,
+.navbottom.navtext a.bookprev {
+ float: left;
+ text-align: left;
+}
+.dir-rtl .navtop.navtext a.bookprev,
+.dir-rtl .navbottom.navtext a.bookprev {
+ float: right;
+ text-align: right;
+}
+
+@media (max-width: 480px) {
+ .path-mod-book .navbottom,
+ .path-mod-book .navtop,
+ .dir-rtl.path-mod-book .navbottom,
+ .dir-rtl.path-mod-book .navtop {
+ text-align: center;
+ }
+ .navtop.navtext a,
+ .navbottom.navtext a {
+ display: block;
+ max-width: 100%;
+ margin: auto;
+ }
+ .navtop.navtext a.bookprev,
+ .navbottom.navtext a.bookprev,
+ .dir-rtl .navtop.navtext a.bookprev,
+ .dir-rtl .navbottom.navtext a.bookprev {
+ float: none;
+ }
+}
diff --git a/mod/book/version.php b/mod/book/version.php
index 155c6365c9c01..c5d5c8ba93a2e 100644
--- a/mod/book/version.php
+++ b/mod/book/version.php
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->component = 'mod_book'; // Full name of the plugin (used for diagnostics)
-$plugin->version = 2014051200; // The current module version (Date: YYYYMMDDXX)
+$plugin->version = 2014051201; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->cron = 0; // Period for cron to check this module (secs)
diff --git a/mod/book/view.php b/mod/book/view.php
index 3fd9b45f25c3b..f2a6398877cc9 100644
--- a/mod/book/view.php
+++ b/mod/book/view.php
@@ -127,7 +127,9 @@
// prepare chapter navigation icons
$previd = null;
+$prevtitle = null;
$nextid = null;
+$nexttitle = null;
$last = null;
foreach ($chapters as $ch) {
if (!$edit and $ch->hidden) {
@@ -135,37 +137,68 @@
}
if ($last == $chapter->id) {
$nextid = $ch->id;
+ $nexttitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
break;
}
if ($ch->id != $chapter->id) {
$previd = $ch->id;
+ $prevtitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
}
$last = $ch->id;
}
-$navprevicon = right_to_left() ? 'nav_next' : 'nav_prev';
-$navnexticon = right_to_left() ? 'nav_prev' : 'nav_next';
-$navprevdisicon = right_to_left() ? 'nav_next_dis' : 'nav_prev_dis';
-$chnavigation = '';
-if ($previd) {
- $chnavigation .= '';
-} else {
- $chnavigation .= '';
-}
-if ($nextid) {
- $chnavigation .= '';
-} else {
- $sec = $DB->get_field('course_sections', 'section', array('id' => $cm->section));
- $returnurl = course_get_url($course, $sec);
- $chnavigation .= '';
-
- // we are cheating a bit here, viewing the last page means user has viewed the whole book
- $completion = new completion_info($course);
- $completion->set_module_viewed($cm);
+if ($book->navstyle) {
+ $navprevicon = right_to_left() ? 'nav_next' : 'nav_prev';
+ $navnexticon = right_to_left() ? 'nav_prev' : 'nav_next';
+ $navprevdisicon = right_to_left() ? 'nav_next_dis' : 'nav_prev_dis';
+
+ $chnavigation = '';
+ if ($previd) {
+ $navprev = get_string('navprev', 'book');
+ if ($book->navstyle == 1) {
+ $chnavigation .= '' .
+ '';
+ } else {
+ $chnavigation .= '' .
+ '' . $OUTPUT->larrow() . ' ' .
+ $navprev . ': ' . $prevtitle . '';
+ }
+ } else {
+ if ($book->navstyle == 1) {
+ $chnavigation .= '';
+ }
+ }
+ if ($nextid) {
+ $navnext = get_string('navnext', 'book');
+ if ($book->navstyle == 1) {
+ $chnavigation .= '' .
+ '';
+ } else {
+ $chnavigation .= ' ' .
+ $navnext . ': ' . $nexttitle.
+ ' ' . $OUTPUT->rarrow() . '';
+ }
+ } else {
+ $navexit = get_string('navexit', 'book');
+ $sec = $DB->get_field('course_sections', 'section', array('id' => $cm->section));
+ $returnurl = course_get_url($course, $sec);
+ if ($book->navstyle == 1) {
+ $chnavigation .= '' .
+ '';
+ } else {
+ $chnavigation .= ' ' .
+ '' . $navexit . ' ' . $OUTPUT->uarrow() . '';
+ }
+
+ // We cheat a bit here in assuming that viewing the last page means the user viewed the whole book.
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+ }
}
// =====================================================
@@ -175,10 +208,14 @@
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
-// upper nav
-echo '
'.$chnavigation.'
';
+$navclasses = book_get_nav_classes();
+
+if ($book->navstyle) {
+ // Upper navigation.
+ echo '' . $chnavigation . '
';
+}
-// chapter itself
+// The chapter itself.
$hidden = $chapter->hidden ? ' dimmed_text' : null;
echo $OUTPUT->box_start('generalbox book_content' . $hidden);
@@ -198,7 +235,9 @@
echo $OUTPUT->box_end();
-// lower navigation
-echo ''.$chnavigation.'
';
+if ($book->navstyle) {
+ // Lower navigation.
+ echo '' . $chnavigation . '
';
+}
echo $OUTPUT->footer();