Skip to content

Commit 7c91e87

Browse files
committed
Add badges to grid - #215.
1 parent 644b97a commit 7c91e87

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Version 402.2.4 - In development
66
1. Fix updating of course when adding or removing sections. Note: Known issue of the section not looking as it should.
77
2. Fix 'Unable to update defaultimageresizemethod setting' - #211.
88
3. Use section anchors in links when editing.
9+
4. Add badges to grid - #215.
910

1011
Version 402.2.3 - 08/04/2024
1112
----------------------------

classes/output/courseformat/content.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ public function export_for_template(\renderer_base $output) {
183183
foreach ($data->sections as $datasectionkey => $datasection) {
184184
$datasectionmap[$datasection->id] = $datasectionkey;
185185
}
186+
} else {
187+
// Visibility info for grid.
188+
$sectionvisiblity = [];
189+
foreach ($sections as $section) {
190+
$sectionvisiblity[$section->id] = new stdClass;
191+
$sectionvisiblity[$section->id]->ishidden = $section->ishidden;
192+
$sectionvisiblity[$section->id]->visibility = $section->visibility;
193+
}
186194
}
187195
foreach ($sectionsforgrid as $section) {
188196
// Do we have an image?
@@ -213,7 +221,9 @@ public function export_for_template(\renderer_base $output) {
213221

214222
// Current section?
215223
if ((!empty($currentsectionid)) && ($currentsectionid == $section->id)) {
216-
$sectionimages[$section->id]->currentsection = true;
224+
$sectionimages[$section->id]->iscurrent = true;
225+
$sectionimages[$section->id]->hasbadge = true;
226+
$sectionimages[$section->id]->highlightedlabel = $format->get_section_highlighted_name();
217227
}
218228

219229
if ($editing) {
@@ -233,10 +243,11 @@ public function export_for_template(\renderer_base $output) {
233243
// Section name.
234244
$sectionimages[$section->id]->sectionname = $section->name;
235245

236-
/* User visible. For more info, see: $format->is_section_visible($thissection) method in relation
237-
to 'hiddensections' course format setting. */
238-
if (!$section->uservisible) {
239-
$sectionimages[$section->id]->notavailable = true;
246+
// Visibility information.
247+
$sectionimages[$section->id]->ishidden = $sectionvisiblity[$section->id]->ishidden;
248+
if ($sectionimages[$section->id]->ishidden) {
249+
$sectionimages[$section->id]->visibility = $sectionvisiblity[$section->id]->visibility;
250+
$sectionimages[$section->id]->hasbadge = true;
240251
}
241252

242253
// Section break.

templates/grid.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* sectionbreak - There is a section break for this section.
2727
* sectionbreakheading - Section break heading.
2828
* number - Section number.
29-
* currentsection - Current section?
29+
* iscurrent - Current section?
3030
* sectionurl - Section URL.
3131
* sectionname - Section name.
3232
* imageuri - Image URI.
@@ -52,7 +52,7 @@
5252
"sectionbreak": true,
5353
"sectionbreakheading": "This is the section heading",
5454
"number": 42,
55-
"currentsection": true,
55+
"iscurrent": true,
5656
"sectionurl": "https://mymoodle/course/view.php?id=4&section=2",
5757
"sectionname": "The second section",
5858
"imageuri": "https://mymoodle/pluginfile.php/358/format_grid/displayedsectionimage/42/1/ducking.jpg.webp",
@@ -73,21 +73,21 @@
7373
{{/sectionbreakheading}}
7474
<div class="thegrid d-flex flex-wrap grid-justify-{{gridjustification}}">
7575
{{/sectionbreak}}
76-
<div id="section-{{number}}" class="grid-section card{{#currentsection}} currentgridsection{{/currentsection}}">
76+
<div id="section-{{number}}" class="grid-section card{{#iscurrent}} currentgridsection{{/iscurrent}}">
7777
{{^popup}}
78-
{{#notavailable}}<div class="grid-section-inner">{{/notavailable}}
79-
{{^notavailable}}<a class="grid-section-inner" href="{{sectionurl}}">{{/notavailable}}
78+
{{#hasbadge}}<div class="grid-section-inner">{{/hasbadge}}
79+
{{^hasbadge}}<a class="grid-section-inner" href="{{sectionurl}}">{{/hasbadge}}
8080
{{/popup}}
8181
{{#popup}}
82-
<div class="grid-modal grid-section-inner" data-toggle="modal" data-target="#gridPopup" data-section="{{number}}" tabindex="0">
82+
<div class="grid-modal grid-section-inner d-flex flex-column h-100 justify-content-between" data-toggle="modal" data-target="#gridPopup" data-section="{{number}}" tabindex="0">
8383
{{/popup}}
84-
<div class="card-header text-truncate" title="{{sectionname}}">{{{sectionname}}}{{#notavailable}}
84+
<div class="card-header text-truncate h-100" title="{{sectionname}}">{{{sectionname}}}{{#hasbadge}}
8585
<div data-region="sectionbadges" class="sectionbadges d-flex">
8686
{{$ core_courseformat/local/content/section/badges }}
8787
{{> core_courseformat/local/content/section/badges }}
8888
{{/ core_courseformat/local/content/section/badges }}
8989
</div>
90-
{{/notavailable}}</div>
90+
{{/hasbadge}}</div>
9191
{{#imageuri}}
9292
<div class="grid-image card-img-bottom text-center">
9393
<img src="{{imageuri}}" alt="{{imagealttext}}" loading="lazy">

0 commit comments

Comments
 (0)