MDL-33121 Book Module: performed minor changes and cleanup for the module

This commit is contained in:
Tõnis Tartes 2012-06-13 15:28:07 +08:00 committed by Rossiani Wijaya
parent b15ef0b058
commit 5b7e511ea8
17 changed files with 160 additions and 99 deletions

View File

@ -130,14 +130,14 @@ class moodle1_mod_book_handler extends moodle1_mod_handler {
}
/**
* This is executed when the parser reaches the <OPTIONS> opening element
* This is executed when the parser reaches the <CHAPTERS> opening element
*/
public function on_book_chapters_start() {
$this->xmlwriter->begin_tag('chapters');
}
/**
* This is executed when the parser reaches the closing </OPTIONS> element
* This is executed when the parser reaches the closing </CHAPTERS> element
*/
public function on_book_chapters_end() {
$this->xmlwriter->end_tag('chapters');

View File

@ -13,7 +13,6 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book module upgrade code
*

View File

@ -45,9 +45,8 @@ $chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$b
// Header and strings.
$PAGE->set_title(format_string($book->name));
$PAGE->add_body_class('mod_book');
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
// Form processing.
if ($confirm) { // the operation was confirmed.

View File

@ -108,9 +108,8 @@ if ($mform->is_cancelled()) {
}
// Otherwise fill and print the form.
$PAGE->set_title(format_string($book->name));
$PAGE->add_body_class('mod_book');
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editingchapter', 'mod_book'));

View File

@ -29,11 +29,19 @@ require_once($CFG->libdir.'/formslib.php');
class book_chapter_edit_form extends moodleform {
function definition() {
global $CFG;
$chapter = $this->_customdata['chapter'];
$options = $this->_customdata['options'];
//Disabled subchapter option when editing first node
$disabledmsg = null;
$disabledarr = null;
if (!$chapter->id && $chapter->pagenum == 1 || $chapter->pagenum == 1) {
$disabledmsg = get_string('subchapternotice', 'book');
$disabledarr = array('group' => 1, 'disabled' => 'disabled');
}
$mform = $this->_form;
$mform->addElement('header', 'general', get_string('edit'));
@ -42,7 +50,7 @@ class book_chapter_edit_form extends moodleform {
$mform->setType('title', PARAM_RAW);
$mform->addRule('title', null, 'required', null, 'client');
$mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book'));
$mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book'), $disabledmsg, $disabledarr);
$mform->addElement('editor', 'content_editor', get_string('content', 'mod_book'), null, $options);
$mform->setType('content_editor', PARAM_RAW);

View File

@ -88,14 +88,14 @@ foreach ($books as $book) {
$currentsection = $book->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($book->timemodified)."</span>";
$printsection = html_writer::tag('span', userdate($book->timemodified), array('class' => 'smallinfo'));
}
$class = $book->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$class = $book->visible ? null : array('class' => 'dimmed'); // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($book->name)."</a>",
html_writer::link(new moodle_url('view.php', array('id' => $cm->id)), format_string($book->name), $class),
format_module_intro('book', $book, $cm->id));
}

View File

@ -58,7 +58,6 @@ $string['numbering2'] = 'Bullets';
$string['numbering3'] = 'Indented';
$string['numberingoptions'] = 'Available options for chapter formatting';
$string['numberingoptions_desc'] = 'Options for displaying chapters and subchapters in the table of contents';
$string['chapterscount'] = 'Chapters';
$string['addafter'] = 'Add new chapter';
$string['confchapterdelete'] = 'Do you really want to delete this chapter?';
$string['confchapterdeleteall'] = 'Do you really want to delete this chapter and all its subchapters?';
@ -73,6 +72,6 @@ $string['book:viewhiddenchapters'] = 'View hidden book chapters';
$string['errorchapter'] = 'Error reading chapter of book.';
$string['page-mod-book-x'] = 'Any book module page';
$string['subchapternotice'] = 'This option is disabled, because the first chapter cannot be a subchapter';
$string['subplugintype_booktool'] = 'Book tool';
$string['subplugintype_booktool_plural'] = 'Book tools';

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die;
* @return array
*/
function book_get_numbering_types() {
global $CFG; // required for the include
require_once(dirname(__FILE__).'/locallib.php');
return array (
@ -215,7 +215,6 @@ function book_scale_used_anywhere($scaleid) {
* @return array
*/
function book_get_view_actions() {
global $CFG; // necessary for includes
$return = array('view', 'view all');
@ -240,7 +239,6 @@ function book_get_view_actions() {
* @return array
*/
function book_get_post_actions() {
global $CFG; // necessary for includes
$return = array('update');
@ -291,13 +289,11 @@ function book_supports($feature) {
* @return void
*/
function book_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode) {
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
if ($PAGE->cm->modname !== 'book') {
return;
}
global $USER, $PAGE;
$plugins = get_plugin_list('booktool');
foreach ($plugins as $plugin => $dir) {
if (file_exists("$dir/lib.php")) {
require_once("$dir/lib.php");

View File

@ -24,6 +24,8 @@
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once(dirname(__FILE__).'/lib.php');
require_once($CFG->libdir.'/filelib.php');
@ -217,7 +219,7 @@ function book_add_fake_block($chapters, $chapter, $book, $cm, $edit) {
function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
global $USER, $OUTPUT;
$toc = ''; // Representation of toc (HTML)
$toc ='';
$nch = 0; // Chapter number
$ns = 0; // Subchapter number
$first = 1;
@ -226,27 +228,35 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= '<div class="book_toc_none">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
break;
case BOOK_NUM_NUMBERS:
$toc .= '<div class="book_toc_numbered">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
break;
case BOOK_NUM_BULLETS:
$toc .= '<div class="book_toc_bullets">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
break;
case BOOK_NUM_INDENTED:
$toc .= '<div class="book_toc_indented">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
break;
}
if ($edit) { // Teacher's TOC
$toc .= '<ul>';
$toc .= html_writer::start_tag('ul');
$i = 0;
foreach ($chapters as $ch) {
$i++;
$title = trim(format_string($ch->title, true, array('context'=>$context)));
if (!$ch->subchapter) {
$toc .= ($first) ? '<li>' : '</ul></li><li>';
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
if (!$ch->hidden) {
$nch++;
$ns = 0;
@ -257,10 +267,18 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
if ($book->numbering == BOOK_NUM_NUMBERS) {
$title = "x $title";
}
$title = '<span class="dimmed_text">'.$title.'</span>';
$title = html_writer::tag('span', $title, array('class' => 'dimmed_text'));
}
} else {
$toc .= ($first) ? '<li><ul><li>' : '<li>';
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
if (!$ch->hidden) {
$ns++;
if ($book->numbering == BOOK_NUM_NUMBERS) {
@ -270,75 +288,109 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
if ($book->numbering == BOOK_NUM_NUMBERS) {
$title = "x.x $title";
}
$title = '<span class="dimmed_text">'.$title.'</span>';
$title = html_writer::tag('span', $title, array('class' => 'dimmed_text'));
}
}
if ($ch->id == $chapter->id) {
$toc .= '<strong>'.$title.'</strong>';
$toc .= html_writer::tag('strong', $title);
} else {
$toc .= '<a title="'.s($title).'" href="view.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'">'.$title.'</a>';
$toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title)));
}
$toc .= '&nbsp;&nbsp;';
if ($i != 1) {
$toc .= ' <a title="'.get_string('up').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;up=1&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/up').'" class="iconsmall" alt="'.get_string('up').'" /></a>';
$toc .= html_writer::link(new moodle_url('move.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'up' => '1', 'sesskey' => $USER->sesskey)),
$OUTPUT->pix_icon('t/up', get_string('up')), array('title' => get_string('up')));
}
if ($i != count($chapters)) {
$toc .= ' <a title="'.get_string('down').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;up=0&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/down').'" class="iconsmall" alt="'.get_string('down').'" /></a>';
$toc .= html_writer::link(new moodle_url('move.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'up' => '0', 'sesskey' => $USER->sesskey)),
$OUTPUT->pix_icon('t/down', get_string('down')), array('title' => get_string('down')));
}
$toc .= ' <a title="'.get_string('edit').'" href="edit.php?cmid='.$cm->id.'&amp;id='.$ch->id.'"><img src="'.
$OUTPUT->pix_url('t/edit').'" class="iconsmall" alt="'.get_string('edit').'" /></a>';
$toc .= ' <a title="'.get_string('delete').'" href="delete.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/delete').'" class="iconsmall" alt="'.get_string('delete').'" /></a>';
$toc .= html_writer::link(new moodle_url('edit.php', array('cmid' => $cm->id, 'id' => $ch->id)),
$OUTPUT->pix_icon('t/edit', get_string('edit')), array('title' => get_string('edit')));
$toc .= html_writer::link(new moodle_url('delete.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
$OUTPUT->pix_icon('t/delete', get_string('delete')), array('title' => get_string('delete')));
if ($ch->hidden) {
$toc .= ' <a title="'.get_string('show').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/show').'" class="iconsmall" alt="'.get_string('show').'" /></a>';
$toc .= html_writer::link(new moodle_url('show.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
$OUTPUT->pix_icon('t/show', get_string('show')), array('title' => get_string('show')));
} else {
$toc .= ' <a title="'.get_string('hide').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/hide').'" class="iconsmall" alt="'.get_string('hide').'" /></a>';
$toc .= html_writer::link(new moodle_url('show.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
$OUTPUT->pix_icon('t/hide', get_string('hide')), array('title' => get_string('hide')));
}
$toc .= ' <a title="'.get_string('addafter', 'mod_book').'" href="edit.php?cmid='.$cm->id.
'&amp;pagenum='.$ch->pagenum.'&amp;subchapter='.$ch->subchapter.'"><img src="'.
$OUTPUT->pix_url('add', 'mod_book').'" class="iconsmall" alt="'.get_string('addafter', 'mod_book').'" /></a>';
$toc .= html_writer::link(new moodle_url('edit.php', array('cmid' => $cm->id, 'pagenum' => $ch->pagenum, 'subchapter' => $ch->subchapter)),
$OUTPUT->pix_icon('add', get_string('addafter', 'mod_book'), 'mod_book'), array('title' => get_string('addafter', 'mod_book')));
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
if (!$ch->subchapter) {
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::end_tag('li');
}
$first = 0;
}
$toc .= '</ul></li></ul>';
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
} else { // Normal students view
$toc .= '<ul>';
$toc .= html_writer::start_tag('ul');
foreach ($chapters as $ch) {
$title = trim(format_string($ch->title, true, array('context'=>$context)));
if (!$ch->hidden) {
if (!$ch->subchapter) {
$nch++;
$ns = 0;
$toc .= ($first) ? '<li>' : '</ul></li><li>';
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
if ($book->numbering == BOOK_NUM_NUMBERS) {
$title = "$nch $title";
}
} else {
$ns++;
$toc .= ($first) ? '<li><ul><li>' : '<li>';
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
if ($book->numbering == BOOK_NUM_NUMBERS) {
$title = "$nch.$ns $title";
}
}
if ($ch->id == $chapter->id) {
$toc .= '<strong>'.$title.'</strong>';
$toc .= html_writer::tag('strong', $title);
} else {
$toc .= '<a title="'.s($title).'" href="view.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'">'.$title.'</a>';
$toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title)));
}
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
if (!$ch->subchapter) {
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::end_tag('li');
}
$first = 0;
}
}
$toc .= '</ul></li></ul>';
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
}
$toc .= '</div>';
$toc .= html_writer::end_tag('div');
$toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.

View File

@ -1,5 +1,5 @@
.mod_book .book_chapter_title {
.path-mod-book .book_chapter_title {
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
text-align: left;
font-size: large;
@ -9,7 +9,7 @@
margin-bottom: 20px;
}
.mod_book img.bigicon {
.path-mod-book img.bigicon {
vertical-align: middle;
margin-right: 4px;
margin-left: 4px;
@ -18,7 +18,7 @@
border: 0px;
}
.mod_book .navtop {
.path-mod-book .navtop {
text-align: right;
margin-bottom: 0.5em;
}

View File

@ -44,10 +44,6 @@ $context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
require_capability('booktool/exportimscp:export', $context);
$strbooks = get_string('modulenameplural', 'book');
$strbook = get_string('modulename', 'book');
$strtop = get_string('top', 'book');
add_to_log($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id='.$cm->id, $book->id, $cm->id);
$file = booktool_exportimscp_build_package($book, $context);

View File

@ -31,11 +31,8 @@ defined('MOODLE_INTERNAL') || die;
* @param navigation_node $node The node to add module settings to
*/
function booktool_exportimscp_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
if ($PAGE->cm->modname !== 'book') {
return;
}
global $PAGE;
if (has_capability('booktool/exportimscp:export', $PAGE->cm->context)) {
$url = new moodle_url('/mod/book/tool/exportimscp/index.php', array('id'=>$PAGE->cm->id));

View File

@ -48,9 +48,8 @@ if ($chapterid) {
$chapter = false;
}
$PAGE->set_title(format_string($book->name));
$PAGE->add_body_class('mod_book');
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
// Prepare the page header.
$strbook = get_string('modulename', 'mod_book');

View File

@ -31,11 +31,8 @@ defined('MOODLE_INTERNAL') || die;
* @param navigation_node $node The node to add module settings to
*/
function booktool_importhtml_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
if ($PAGE->cm->modname !== 'book') {
return;
}
global $PAGE;
if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) {
$url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id'=>$PAGE->cm->id));

View File

@ -31,11 +31,8 @@ defined('MOODLE_INTERNAL') || die;
* @param navigation_node $node The node to add module settings to
*/
function booktool_print_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
if ($PAGE->cm->modname !== 'book') {
return;
}
global $PAGE;
$params = $PAGE->url->params();

View File

@ -45,43 +45,67 @@ function booktool_print_get_toc($chapters, $book, $cm) {
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= '<div class="book_toc_none">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
break;
case BOOK_NUM_NUMBERS:
$toc .= '<div class="book_toc_numbered">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
break;
case BOOK_NUM_BULLETS:
$toc .= '<div class="book_toc_bullets">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
break;
case BOOK_NUM_INDENTED:
$toc .= '<div class="book_toc_indented">';
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
break;
}
$toc .= '<a name="toc"></a>'; // Representation of toc (HTML).
$toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
if ($book->customtitles) {
$toc .= '<h1>'.get_string('toc', 'mod_book').'</h1>';
$toc .= html_writer::tag('h1', get_string('toc', 'mod_book'));
} else {
$toc .= '<p class="book_chapter_title">'.get_string('toc', 'mod_book').'</p>';
$toc .= html_writer::tag('p', get_string('toc', 'mod_book'), array('class' => 'book_chapter_title'));
}
$toc .= '<ul>';
$toc .= html_writer::start_tag('ul');
foreach ($chapters as $ch) {
if (!$ch->hidden) {
$title = book_get_chapter_title($ch->id, $chapters, $book, $context);
if (!$ch->subchapter) {
$toc .= $first ? '<li>' : '</ul></li><li>';
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
} else {
$toc .= $first ? '<li><ul><li>' : '<li>';
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
}
$titles[$ch->id] = $title;
$toc .= '<a title="'.s($title).'" href="#ch'.$ch->id.'">'.$title.'</a>';
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
$toc .= html_writer::link(new moodle_url('#ch'.$ch->id), $title, array('title' => s($title)));
if (!$ch->subchapter) {
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::end_tag('li');
}
$first = false;
}
}
$toc .= '</ul></li></ul>';
$toc .= '</div>';
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('div');
$toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
return array($toc, $titles);

View File

@ -114,9 +114,8 @@ $strbook = get_string('modulename', 'mod_book');
$strtoc = get_string('toc', 'mod_book');
// prepare header
$PAGE->set_title(format_string($book->name));
$PAGE->add_body_class('mod_book');
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
book_add_fake_block($chapters, $chapter, $book, $cm, $edit);