From d45d841e735337fe52d17921a0ba82af48dba4d1 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 2 Dec 2023 12:12:08 +0000 Subject: [PATCH] Show warning if there is a stealth section with content, related to #196. --- Changes.md | 1 + classes/output/courseformat/content.php | 25 +++++++++++++++++++++++-- lang/en/format_grid.php | 1 + templates/local/content.mustache | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index 5ee8e4ac..a8b88b43 100644 --- a/Changes.md +++ b/Changes.md @@ -7,6 +7,7 @@ Version 403.1.1 - TBR thanks to @Syxton(Matt Davidson). 2. Fix 'Sections showing beyond the number set in the settings', related to #196. 3. Improved backup and restore logic. +4. Show warning if there is a stealth section with content, related to #196. Version 403.1.0 - 15/10/2023 ---------------------------- diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index f02531ab..a6150dcf 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -49,6 +49,17 @@ class content extends content_base { */ protected $hasaddsection = false; + /** + * @var int Are there stealth sections with content? + */ + protected $hassteathwithcontent = 0; + + /** + * Get the template name. + * + * @param renderer_base $output typically, the renderer that's calling this method. + * @return string Mustache template name. + */ public function get_template_name(\renderer_base $renderer): string { return 'format_grid/local/content'; } @@ -56,8 +67,8 @@ public function get_template_name(\renderer_base $renderer): string { /** * Export this data so it can be used as the context for a mustache template (core/inplace_editable). * - * @param renderer_base $output typically, the renderer that's calling this function - * @return stdClass data context for a Mustache template + * @param renderer_base $output typically, the renderer that's calling this method. + * @return stdClass data context for a Mustache template. */ public function export_for_template(\renderer_base $output) { global $DB, $PAGE; @@ -258,6 +269,13 @@ public function export_for_template(\renderer_base $output) { } } + if ($this->hassteathwithcontent) { + $context = \context_course::instance($course->id); + if (has_capability('moodle/course:update', $context)) { + $data->stealthwarning = get_string('stealthwarning', 'format_grid', $this->hassteathwithcontent); + } + } + if ($this->hasaddsection) { $addsection = new $this->addsectionclass($format); $data->numsections = $addsection->export_for_template($output); @@ -309,6 +327,9 @@ protected function get_grid_sections(\renderer_base $output, $settings): array { } if ($thissection->section > $numsections) { + if (!empty($modinfo->sections[$thissection->section])) { + $this->hassteathwithcontent++; + } continue; } diff --git a/lang/en/format_grid.php b/lang/en/format_grid.php index 42265f3f..595f28e1 100644 --- a/lang/en/format_grid.php +++ b/lang/en/format_grid.php @@ -140,6 +140,7 @@ $string['settings'] = 'Settings'; $string['settingssettings'] = 'Settings settings'; $string['settingssettingsdesc'] = 'Grid format settings'; +$string['stealthwarning'] = 'Warning: Course has {$a} orphaned section(s) with content.'; $string['love'] = 'love'; $string['versioninfo'] = 'Release {$a->release}, version {$a->version} on Moodle {$a->moodle}. Made with {$a->love} in Great Britain.'; $string['versionalpha'] = 'Alpha version - Almost certainly contains bugs. This is a development version for developers \'only\'! Don\'t even think of installing on a production server!'; diff --git a/templates/local/content.mustache b/templates/local/content.mustache index e2218f2a..580d7f2b 100644 --- a/templates/local/content.mustache +++ b/templates/local/content.mustache @@ -167,6 +167,9 @@ {{#hasheaderimages}} {{> format_grid/coursestyles }} {{/hasheaderimages}} + {{#stealthwarning}} +
{{stealthwarning}}
+ {{/stealthwarning}}