Skip to content

Commit

Permalink
Merge branch 'MDL36874_Text_navigation_for_Books' of git://github.com…
Browse files Browse the repository at this point in the history
…/Dave-B/moodle

Conflicts:
	mod/book/version.php
	mod/book/db/upgrade.php
  • Loading branch information
danpoltawski committed Nov 18, 2014
2 parents 0bd55a3 + f4de846 commit c8b01e0
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 39 deletions.
26 changes: 20 additions & 6 deletions lib/outputlib.php
Expand Up @@ -278,6 +278,15 @@ class theme_config {
*/
public $larrow = null;

/**
* @var string Accessibility: Up arrow-like character is used in
* the book heirarchical navigation.
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use ^ - this is confusing for blind users.
*/
public $uarrow = null;

/**
* @var bool Some themes may want to disable ajax course editing.
*/
Expand Down Expand Up @@ -452,11 +461,13 @@ private function __construct($config) {
$baseconfig = $config;
}

$configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer',
'parents_exclude_javascripts', 'layouts', 'enable_dock', 'enablecourseajax', 'supportscssoptimisation',
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector', 'doctype',
'yuicssmodules', 'blockrtlmanipulations', 'lessfile', 'extralesscallback', 'lessvariablescallback',
'blockrendermethod');
$configurable = array(
'parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets',
'javascripts', 'javascripts_footer', 'parents_exclude_javascripts',
'layouts', 'enable_dock', 'enablecourseajax', 'supportscssoptimisation',
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'uarrow',
'hidefromselector', 'doctype', 'yuicssmodules', 'blockrtlmanipulations',
'lessfile', 'extralesscallback', 'lessvariablescallback', 'blockrendermethod');

foreach ($config as $key=>$value) {
if (in_array($key, $configurable)) {
Expand Down Expand Up @@ -533,7 +544,7 @@ public function init_page(moodle_page $page) {
}

/**
* Checks if arrows $THEME->rarrow, $THEME->larrow have been set (theme/-/config.php).
* Checks if arrows $THEME->rarrow, $THEME->larrow, $THEME->uarrow have been set (theme/-/config.php).
* If not it applies sensible defaults.
*
* Accessibility: right and left arrow Unicode characters for breadcrumb, calendar,
Expand All @@ -546,6 +557,7 @@ private function check_theme_arrows() {
// Also OK in Win 9x/2K/IE 5.x
$this->rarrow = '►';
$this->larrow = '◄';
$this->uarrow = '▲';
if (empty($_SERVER['HTTP_USER_AGENT'])) {
$uagent = '';
} else {
Expand All @@ -564,13 +576,15 @@ private function check_theme_arrows() {
// So we use the same ones Konqueror uses.
$this->rarrow = '→';
$this->larrow = '←';
$this->uarrow = '↑';
}
elseif (isset($_SERVER['HTTP_ACCEPT_CHARSET'])
&& false === stripos($_SERVER['HTTP_ACCEPT_CHARSET'], 'utf-8')) {
// (Win/IE 5 doesn't set ACCEPT_CHARSET, but handles Unicode.)
// To be safe, non-Unicode browsers!
$this->rarrow = '>';
$this->larrow = '<';
$this->uarrow = '^';
}

// RTL support - in RTL languages, swap r and l arrows
Expand Down
13 changes: 13 additions & 0 deletions lib/outputrenderers.php
Expand Up @@ -3196,6 +3196,19 @@ public function larrow() {
return $this->page->theme->larrow;
}

/**
* Accessibility: Up arrow-like character is used in
* the book heirarchical navigation.
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use ^ - this is confusing for blind users.
*
* @return string
*/
public function uarrow() {
return $this->page->theme->uarrow;
}

/**
* Returns the custom menu if one has been set
*
Expand Down
10 changes: 7 additions & 3 deletions mod/book/backup/moodle2/backup_book_stepslib.php
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion mod/book/db/install.xml
Expand Up @@ -12,6 +12,7 @@
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="numbering" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="navstyle" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="customtitles" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down Expand Up @@ -40,4 +41,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
15 changes: 15 additions & 0 deletions mod/book/db/upgrade.php
Expand Up @@ -207,5 +207,20 @@ function xmldb_book_upgrade($oldversion) {
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2014111800) {

// Define field navstyle to be added to book.
$table = new xmldb_table('book');
$field = new xmldb_field('navstyle', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1', 'numbering');

// Conditionally launch add field navstyle.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Book savepoint reached.
upgrade_mod_savepoint(true, 2014111800, 'book');
}

return true;
}
8 changes: 8 additions & 0 deletions mod/book/lang/en/book.php
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions mod/book/lib.php
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions mod/book/locallib.php
Expand Up @@ -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.
*
Expand Down
19 changes: 19 additions & 0 deletions mod/book/mod_form.php
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion mod/book/settings.php
Expand Up @@ -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));

}
45 changes: 45 additions & 0 deletions mod/book/styles.css
Expand Up @@ -19,6 +19,9 @@
.path-mod-book .navtop {
margin-bottom: 0.5em;
}
.path-mod-book .navbottom {
margin-top: 0.5em;
}

/* == Fake toc block == */

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion mod/book/version.php
Expand Up @@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die;

$plugin->component = 'mod_book'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2014111000; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2014111800; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014110400; // Requires this Moodle version
$plugin->cron = 0; // Period for cron to check this module (secs)

0 comments on commit c8b01e0

Please sign in to comment.