From b5bce42cca997b6c5d7619f00860a2125cd9a51b Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Tue, 5 Feb 2019 09:46:08 +0800 Subject: [PATCH 1/2] MDL-50793 mod_book: Update behat tests --- mod/book/tests/behat/show_hide_chapters.feature | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mod/book/tests/behat/show_hide_chapters.feature b/mod/book/tests/behat/show_hide_chapters.feature index c84ab8feda1..f235bccc319 100644 --- a/mod/book/tests/behat/show_hide_chapters.feature +++ b/mod/book/tests/behat/show_hide_chapters.feature @@ -11,9 +11,11 @@ Feature: Book activity chapter visibility management And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 2 | student1@example.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | + | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I add a "Book" to section "1" and I fill the form with: @@ -54,8 +56,8 @@ Feature: Book activity chapter visibility management And I turn editing mode off And I am on "Course 1" course homepage And I follow "Test book" - Then I should not see "Second chapter" in the "Table of contents" "block" - And I should not see "Third chapter" in the "Table of contents" "block" + Then the "class" attribute of "a[title='Second chapter']" "css_element" should contain "dimmed_text" + And the "class" attribute of "a[title='Third chapter']" "css_element" should contain "dimmed_text" And I follow "Next" And I should see "Fourth chapter" in the ".book_content" "css_element" And I follow "Exit book" @@ -72,3 +74,9 @@ Feature: Book activity chapter visibility management And I follow "Next" And I should see "Fourth chapter" in the ".book_content" "css_element" And I follow "Exit book" + And I log out + And I log in as "student1" + And I am on "Course 1" course homepage + And I follow "Test book" + And I should not see "Second chapter" in the "Table of contents" "block" + And I should not see "Third chapter" in the "Table of contents" "block" From 854f6116f33621a1cf67e31413020d8f84d4de77 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Tue, 5 Feb 2019 09:46:48 +0800 Subject: [PATCH 2/2] MDL-50793 mod_book: Display hidden chapters to teachers --- mod/book/locallib.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mod/book/locallib.php b/mod/book/locallib.php index 52cb3d4aac1..e5e4e8d5620 100644 --- a/mod/book/locallib.php +++ b/mod/book/locallib.php @@ -167,7 +167,7 @@ function book_get_chapter_title($chid, $chapters, $book, $context) { * @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 + * @param bool|null $edit Whether the user is editing */ function book_add_fake_block($chapters, $chapter, $book, $cm, $edit = null) { global $PAGE, $USER; @@ -184,7 +184,7 @@ function book_add_fake_block($chapters, $chapter, $book, $cm, $edit = null) { } } - $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0); + $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit); $bc = new block_contents(); $bc->title = get_string('toc', 'mod_book'); @@ -214,6 +214,7 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { $first = 1; $context = context_module::instance($cm->id); + $viewhidden = has_capability('mod/book:viewhiddenchapters', $context); switch ($book->numbering) { case BOOK_NUM_NONE: @@ -230,7 +231,7 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { break; } - if ($edit) { // Teacher's TOC + if ($edit) { // Editing on (Teacher's TOC). $toc .= html_writer::start_tag('ul'); $i = 0; foreach ($chapters as $ch) { @@ -350,12 +351,12 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { $toc .= html_writer::end_tag('li'); $toc .= html_writer::end_tag('ul'); - } else { // Normal students view + } else { // Editing off. Normal students, teachers view. $toc .= html_writer::start_tag('ul'); foreach ($chapters as $ch) { $title = trim(format_string($ch->title, true, array('context'=>$context))); $titleunescaped = trim(format_string($ch->title, true, array('context' => $context, 'escape' => false))); - if (!$ch->hidden) { + if (!$ch->hidden || ($ch->hidden && $viewhidden)) { if (!$ch->subchapter) { $nch++; $ns = 0; @@ -386,12 +387,15 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { $title = "$nch.$ns. $title"; } } + + $cssclass = ($ch->hidden && $viewhidden) ? 'dimmed_text' : ''; + if ($ch->id == $chapter->id) { - $toc .= html_writer::tag('strong', $title); + $toc .= html_writer::tag('strong', $title, array('class' => $cssclass)); } else { $toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), - $title, array('title' => s($titleunescaped))); + $title, array('title' => s($titleunescaped), 'class' => $cssclass)); } if (!$ch->subchapter) {