MDL-56293 mod_book: Add ToC block in chapter edit/deletes

This commit is contained in:
Andrew Nicols
2016-10-06 15:43:03 +08:00
parent ddd8dc0d1b
commit d93c3b6890
3 changed files with 28 additions and 9 deletions
+4 -1
View File
@@ -78,6 +78,9 @@ if ($confirm) { // the operation was confirmed.
redirect('view.php?id='.$cm->id);
}
$chapters = book_preload_chapters($book);
book_add_fake_block($chapters, $chapter, $book, $cm);
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
@@ -93,4 +96,4 @@ $cancel = new moodle_url('/mod/book/view.php', array('id'=>$cm->id, 'chapterid'=
$title = format_string($chapter->title);
echo $OUTPUT->confirm("<strong>$title</strong><p>$strconfirm</p>", $continue, $cancel);
echo $OUTPUT->footer();
echo $OUTPUT->footer();
+4
View File
@@ -113,6 +113,10 @@ if ($mform->is_cancelled()) {
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
if ($chapters = book_preload_chapters($book)) {
book_add_fake_block($chapters, $chapter, $book, $cm);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
+20 -8
View File
@@ -161,16 +161,28 @@ function book_get_chapter_title($chid, $chapters, $book, $context) {
}
/**
* Add the book TOC sticky block to the default region
* Add the book TOC sticky block to the default region.
*
* @param array $chapters
* @param stdClass $chapter
* @param stdClass $book
* @param stdClass $cm
* @param bool $edit
* @param array $chapters The Chapters in the book
* @param stdClass $chapter The current chapter
* @param stdClass $book The book
* @param stdClass $cm The course module
* @param bool $edit Whether the user is editing
*/
function book_add_fake_block($chapters, $chapter, $book, $cm, $edit) {
global $OUTPUT, $PAGE;
function book_add_fake_block($chapters, $chapter, $book, $cm, $edit = null) {
global $PAGE, $USER;
if ($edit === null) {
if (has_capability('mod/book:edit', context_module::instance($cm->id))) {
if (isset($USER->editing)) {
$edit = $USER->editing;
} else {
$edit = 0;
}
} else {
$edit = 0;
}
}
$toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0);