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 55c8331 commit ba0c468
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
60 changes: 43 additions & 17 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content extends content_base {

private $sectioncompletionpercentage = [];
private $sectioncompletionmarkup = [];
private $sectioncompletioncalculated = [];
Expand Down Expand Up @@ -126,10 +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 @@ -171,12 +180,21 @@ 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;
$sectionimages[$section->id] = new stdClass();
$sectionimages[$section->id]->generatedimageuri = $output->get_generated_image_for_id($section->id);
}
// Number.
Expand Down Expand Up @@ -217,7 +235,7 @@ public function export_for_template(\renderer_base $output) {
// Section break.
if ($sectionformatoptions['sectionbreak'] == 2) { // Yes.
$sectionimages[$section->id]->sectionbreak = true;
if (!empty ($sectionformatoptions['sectionbreakheading'])) {
if (!empty($sectionformatoptions['sectionbreakheading'])) {
// Note: As a PARAM_TEXT, then does need to be passed through 'format_string' for multi-lang or not?
$sectionimages[$section->id]->sectionbreakheading = format_text(
$sectionformatoptions['sectionbreakheading'],
Expand Down Expand Up @@ -300,10 +318,16 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
foreach ($sectioninfos as $thissection) {
// The course/view.php check the section existence but the output can be called from other parts so we need to check it.
if (!$thissection) {
throw new \moodle_exception('unknowncoursesection', 'error', '',
get_string('unknowncoursesection', 'error',
course_get_url($course).' - '.format_string($course->fullname))
);
throw new \moodle_exception(
'unknowncoursesection',
'error',
'',
get_string(
'unknowncoursesection',
'error',
course_get_url($course) . ' - ' . format_string($course->fullname)
)
);
}

if ($thissection->section > $numsections) {
Expand All @@ -317,7 +341,7 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
continue;
}

$section = new stdClass;
$section = new stdClass();
$section->id = $thissection->id;
$section->num = $thissection->section;
$section->name = $output->section_title_without_link($thissection, $course);
Expand Down Expand Up @@ -365,8 +389,10 @@ protected function calculate_section_activity_completion($section, $course, $mod
if ($completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
$total++;
$completiondata = $completioninfo->get_data($thismod, true);
if ($completiondata->completionstate == COMPLETION_COMPLETE ||
$completiondata->completionstate == COMPLETION_COMPLETE_PASS) {
if (
$completiondata->completionstate == COMPLETION_COMPLETE ||
$completiondata->completionstate == COMPLETION_COMPLETE_PASS
) {
$complete++;
}
}
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 ba0c468

Please sign in to comment.