Skip to content

Commit

Permalink
Don't break but report #199.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jan 19, 2024
1 parent 8be15fe commit 4dbedc1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
43 changes: 26 additions & 17 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,20 @@ public function export_for_template(\renderer_base $output) {
$fs = get_file_storage();
$coursecontext = \context_course::instance($course->id);
foreach ($coursesectionimages as $coursesectionimage) {
$replacement = $toolbox->check_displayed_image(
$coursesectionimage,
$course->id,
$coursecontext->id,
$coursesectionimage->sectionid,
$format,
$fs
);
if (!empty($replacement)) {
$coursesectionimages[$coursesectionimage->id] = $replacement;
try {
$replacement = $toolbox->check_displayed_image(
$coursesectionimage,
$course->id,
$coursecontext->id,
$coursesectionimage->sectionid,
$format,
$fs
);
if (!empty($replacement)) {
$coursesectionimages[$coursesectionimage->id] = $replacement;
}
} catch (\moodle_exception $me) {
$coursesectionimages[$coursesectionimage->id]->imageerror = $me->getMessage();
}
}
}
Expand Down Expand Up @@ -176,13 +180,18 @@ public function export_for_template(\renderer_base $output) {
}
foreach ($sectionsforgrid as $section) {
// Do we have an image?
if ((array_key_exists($section->id, $sectionimages)) && ($sectionimages[$section->id]->displayedimagestate >= 1)) {
$sectionimages[$section->id]->imageuri = $toolbox->get_displayed_image_uri(
$sectionimages[$section->id],
$coursecontext->id,
$section->id,
$displayediswebp
);
if (array_key_exists($section->id, $sectionimages)) {
if ($sectionimages[$section->id]->displayedimagestate >= 1) {
$sectionimages[$section->id]->imageuri = $toolbox->get_displayed_image_uri(
$sectionimages[$section->id],
$coursecontext->id,
$section->id,
$displayediswebp
);
} else if (empty($sectionimages[$section->id]->imageerror)) {
$sectionimages[$section->id]->imageerror =
get_string('cannotconvertuploadedimagetodisplayedimage', 'format_grid', json_encode($sectionimages[$section->id]));
}
} else {
// No.
$sectionimages[$section->id] = new stdClass();
Expand Down
6 changes: 6 additions & 0 deletions templates/grid.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
</div>
{{/generatedimageuri}}
{{#imageerror}}
<div class="grid-image-error card-img-bottom text-center">
<p><small>{{imageerror}}</small></p>
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
</div>
{{/imageerror}}
{{^popup}}
{{#notavailable}}</div>{{/notavailable}}
{{^notavailable}}</a>{{/notavailable}}
Expand Down
5 changes: 5 additions & 0 deletions templates/local/content/section/content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
<div class="grid-generatedimage card-img text-center" style="background-image: url('{{generatedimageuri}}');">
</div>
{{/generatedimageuri}}
{{#imageerror}}
<div class="grid-image-error card-img text-center">
<p><small>{{imageerror}}</small></p>
</div>
{{/imageerror}}
{{#image}}
<div class="grid-image-name card-footer">
{{image}}
Expand Down

0 comments on commit 4dbedc1

Please sign in to comment.