Skip to content

Commit

Permalink
Add badges to grid - #215.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Aug 20, 2024
1 parent 193841d commit d0eee90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------
Expand Down
21 changes: 16 additions & 5 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions templates/grid.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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&section=2",
"sectionname": "The second section",
"imageuri": "https://mymoodle/pluginfile.php/358/format_grid/displayedsectionimage/42/1/ducking.jpg.webp",
Expand All @@ -73,21 +73,21 @@
{{/sectionbreakheading}}
<div class="thegrid d-flex flex-wrap grid-justify-{{gridjustification}}">
{{/sectionbreak}}
<div id="section-{{number}}" class="grid-section card{{#currentsection}} currentgridsection{{/currentsection}}">
<div id="section-{{number}}" class="grid-section card{{#iscurrent}} currentgridsection{{/iscurrent}}">
{{^popup}}
{{#notavailable}}<div class="grid-section-inner">{{/notavailable}}
{{^notavailable}}<a class="grid-section-inner" href="{{sectionurl}}">{{/notavailable}}
{{#hasbadge}}<div class="grid-section-inner">{{/hasbadge}}
{{^hasbadge}}<a class="grid-section-inner" href="{{sectionurl}}">{{/hasbadge}}
{{/popup}}
{{#popup}}
<div class="grid-modal grid-section-inner" data-toggle="modal" data-target="#gridPopup" data-section="{{number}}" tabindex="0">
<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">
{{/popup}}
<div class="card-header text-truncate" title="{{sectionname}}">{{{sectionname}}}{{#notavailable}}
<div class="card-header text-truncate h-100" title="{{sectionname}}">{{{sectionname}}}{{#hasbadge}}
<div data-region="sectionbadges" class="sectionbadges d-flex">
{{$ core_courseformat/local/content/section/badges }}
{{> core_courseformat/local/content/section/badges }}
{{/ core_courseformat/local/content/section/badges }}
</div>
{{/notavailable}}</div>
{{/hasbadge}}</div>
{{#imageuri}}
<div class="grid-image card-img-bottom text-center">
<img src="{{imageuri}}" alt="{{imagealttext}}" loading="lazy">
Expand Down

0 comments on commit d0eee90

Please sign in to comment.