From 9795add5278df407c05cd026edb8b9be84388a3b Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Thu, 12 Sep 2024 15:55:45 +0200 Subject: [PATCH] MDL-82541 core_courseformat: improve orphan section visualitzation --- .../output/local/content/section/availability.php | 5 +++++ .../output/local/content/section/controlmenu.php | 1 + .../output/local/content/section/visibility.php | 4 ++++ .../templates/local/content/section/content.mustache | 6 ++++++ lang/en/courseformat.php | 1 + .../tests/behat/subsection_disabled_plugin.feature | 12 ++++++++++-- 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/course/format/classes/output/local/content/section/availability.php b/course/format/classes/output/local/content/section/availability.php index 91ebe64c5c3..f4eb7f5b677 100644 --- a/course/format/classes/output/local/content/section/availability.php +++ b/course/format/classes/output/local/content/section/availability.php @@ -142,6 +142,11 @@ class availability implements named_templatable, renderable { ['id' => $this->section->id, 'showonly' => 'availabilityconditions'] ); $info = ['editurl' => $editurl->out(false)]; + + if ($section->is_orphan()) { + $info['editing'] = false; + } + if (!$section->visible) { return []; } else if (!$section->uservisible) { diff --git a/course/format/classes/output/local/content/section/controlmenu.php b/course/format/classes/output/local/content/section/controlmenu.php index 13e72a6315f..ba0c5b07f1c 100644 --- a/course/format/classes/output/local/content/section/controlmenu.php +++ b/course/format/classes/output/local/content/section/controlmenu.php @@ -277,6 +277,7 @@ class controlmenu extends basecontrolmenu { } } if ( + !$isstealth && has_any_capability([ 'moodle/course:movesections', 'moodle/course:update', diff --git a/course/format/classes/output/local/content/section/visibility.php b/course/format/classes/output/local/content/section/visibility.php index 506b51d86c2..dbc38e45d6c 100644 --- a/course/format/classes/output/local/content/section/visibility.php +++ b/course/format/classes/output/local/content/section/visibility.php @@ -76,6 +76,10 @@ class visibility implements named_templatable, renderable { $data->editing = $this->format->show_editor(); + if ($this->section->is_orphan()) { + $data->editing = false; + } + $data->notavailable = false; $data->hiddenfromstudents = true; if ($data->editing && $this->is_section_visibility_editable()) { diff --git a/course/format/templates/local/content/section/content.mustache b/course/format/templates/local/content/section/content.mustache index c8c77b14bad..b12016f48c3 100644 --- a/course/format/templates/local/content/section/content.mustache +++ b/course/format/templates/local/content/section/content.mustache @@ -83,6 +83,7 @@ "insertafter": true, "numsections": 42, "sitehome": false, + "isstealth": false, "highlightedlabel" : "Highlighted" } }} @@ -163,6 +164,11 @@
+ {{#isstealth}} +
+ {{#str}} orphansectionwarning, core_courseformat {{/str}} +
+ {{/isstealth}} {{#summary}} {{$ core_courseformat/local/content/section/summary }} {{> core_courseformat/local/content/section/summary }} diff --git a/lang/en/courseformat.php b/lang/en/courseformat.php index d13b6346b72..dbdf1fea29d 100644 --- a/lang/en/courseformat.php +++ b/lang/en/courseformat.php @@ -67,6 +67,7 @@ $string['courseindex'] = 'Course index'; $string['courseindexoptions'] = 'Course index options'; $string['maxsectionaddmessage'] = 'You have reached the maximum number of sections allowed for a course.'; $string['nobulkaction'] = 'No bulk actions available'; +$string['orphansectionwarning'] = 'This section and its content are not part of the course structure and are not visible to students. To use any of this content, move it to a different section.'; $string['preference:coursesectionspreferences'] = 'Section user preferences for course {$a}'; $string['privacy:metadata:preference:coursesectionspreferences'] = 'Section user preferences like collapsed and expanded.'; $string['section_hide_feedback'] = 'Course section {$a->name} hidden.'; diff --git a/mod/subsection/tests/behat/subsection_disabled_plugin.feature b/mod/subsection/tests/behat/subsection_disabled_plugin.feature index f46916712b2..fc54005695b 100644 --- a/mod/subsection/tests/behat/subsection_disabled_plugin.feature +++ b/mod/subsection/tests/behat/subsection_disabled_plugin.feature @@ -38,6 +38,8 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa And "Move" "link" should not exist in the "Subsection1" "core_courseformat > Section actions menu" And "View" "link" should exist in the "Subsection1" "core_courseformat > Section actions menu" And "Delete" "link" should exist in the "Subsection1" "core_courseformat > Section actions menu" + And "Permalink" "link" should not exist in the "Subsection1" "core_courseformat > Section actions menu" + And I should see "This section and its content are not part of the course structure" in the "Subsection1" "section" Scenario: Students should not see orphaned subsections When I log in as "student1" @@ -54,6 +56,7 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa And I should see "Subsection1" in the "page-content" "region" And I should see "Subactivity" in the "Subsection1" "section" And "Section 2" "section" should appear before "Subsection1" "section" + And I should see "This section and its content are not part of the course structure" When I enable "subsection" "mod" plugin And I am on "Course 1" course homepage with editing mode on Then I should see "Activity Sample" in the "Section 1" "section" @@ -66,6 +69,7 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa And "Move" "link" should exist in the "Subsection1" "core_courseformat > Section actions menu" And "View" "link" should exist in the "Subsection1" "core_courseformat > Section actions menu" And "Delete" "link" should exist in the "Subsection1" "core_courseformat > Section actions menu" + And I should not see "This section and its content are not part of the course structure" @javascript Scenario: Deleting the subsections with mod_subsection disabled should not break the course @@ -104,14 +108,18 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa And I press "Save changes" And I should see "Not available unless: You belong to a group in GX1" And I disable "subsection" "mod" plugin - When I am on the "C1 > Subsection1" "course > section" page - And I turn editing mode on + When I am on "Course 1" course homepage with editing mode on + And I should see "This section and its content are not part of the course structure" in the "Subsection1" "section" + And I should see "Not available unless: You belong to a group in GX1" + And I should not see "Edit restrictions" + And I am on the "C1 > Subsection1" "course > section" page And I click on "Edit" "icon" in the "[data-region='header-actions-container']" "css_element" And I choose "Delete" in the open action menu And I click on "Delete" "button" in the "Delete section?" "dialogue" And I enable "subsection" "mod" plugin Then I am on "Course 1" course homepage And I should see "Not available unless: You belong to a group in GX1" + And I should see "Edit restrictions" @javascript Scenario: Visibility is restored when a subsection is deleted while mod_subsection is disabled