From d0eee90274614498db7655599f3c0199a430ed7f Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Wed, 14 Aug 2024 19:10:10 +0100 Subject: [PATCH] Add badges to grid - #215. --- Changes.md | 1 + classes/output/courseformat/content.php | 21 ++++++++++++++++----- templates/grid.mustache | 16 ++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Changes.md b/Changes.md index 514666c5..bc7e7cde 100644 --- a/Changes.md +++ b/Changes.md @@ -6,6 +6,7 @@ Version 403.1.3 - In development 1. Fix updating of course when adding or removing sections. Note: Known issue of the section not looking as it should. 2. Fix 'Unable to update defaultimageresizemethod setting' - #211. 3. Use section anchors in links when editing. +4. Add badges to grid - #215. Version 403.1.2 - 08/04/2024 ---------------------------- diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index feb2123f..8c5686d3 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -183,6 +183,14 @@ public function export_for_template(\renderer_base $output) { foreach ($data->sections as $datasectionkey => $datasection) { $datasectionmap[$datasection->id] = $datasectionkey; } + } else { + // Visibility info for grid. + $sectionvisiblity = []; + foreach ($sections as $section) { + $sectionvisiblity[$section->id] = new stdClass; + $sectionvisiblity[$section->id]->ishidden = $section->ishidden; + $sectionvisiblity[$section->id]->visibility = $section->visibility; + } } foreach ($sectionsforgrid as $section) { // Do we have an image? @@ -213,7 +221,9 @@ public function export_for_template(\renderer_base $output) { // Current section? if ((!empty($currentsectionid)) && ($currentsectionid == $section->id)) { - $sectionimages[$section->id]->currentsection = true; + $sectionimages[$section->id]->iscurrent = true; + $sectionimages[$section->id]->hasbadge = true; + $sectionimages[$section->id]->highlightedlabel = $format->get_section_highlighted_name(); } if ($editing) { @@ -233,10 +243,11 @@ public function export_for_template(\renderer_base $output) { // Section name. $sectionimages[$section->id]->sectionname = $section->name; - /* User visible. For more info, see: $format->is_section_visible($thissection) method in relation - to 'hiddensections' course format setting. */ - if (!$section->uservisible) { - $sectionimages[$section->id]->notavailable = true; + // Visibility information. + $sectionimages[$section->id]->ishidden = $sectionvisiblity[$section->id]->ishidden; + if ($sectionimages[$section->id]->ishidden) { + $sectionimages[$section->id]->visibility = $sectionvisiblity[$section->id]->visibility; + $sectionimages[$section->id]->hasbadge = true; } // Section break. diff --git a/templates/grid.mustache b/templates/grid.mustache index 7b87fd19..04c9e307 100644 --- a/templates/grid.mustache +++ b/templates/grid.mustache @@ -26,7 +26,7 @@ * sectionbreak - There is a section break for this section. * sectionbreakheading - Section break heading. * number - Section number. - * currentsection - Current section? + * iscurrent - Current section? * sectionurl - Section URL. * sectionname - Section name. * imageuri - Image URI. @@ -52,7 +52,7 @@ "sectionbreak": true, "sectionbreakheading": "This is the section heading", "number": 42, - "currentsection": true, + "iscurrent": true, "sectionurl": "https://mymoodle/course/view.php?id=4§ion=2", "sectionname": "The second section", "imageuri": "https://mymoodle/pluginfile.php/358/format_grid/displayedsectionimage/42/1/ducking.jpg.webp", @@ -73,21 +73,21 @@ {{/sectionbreakheading}}
{{/sectionbreak}} -
+