Browse Source

CONTRIB-6516 block_completion_progress: Guard divisions in wrap calculations

master 2016090500
Michael de Raadt 9 years ago
parent
commit
cf25087e7d
  1. 8
      lib.php
  2. 2
      version.php

8
lib.php

@ -372,11 +372,17 @@ function block_completion_progress_bar($activities, $completions, $config, $user
// Determine the segment width. // Determine the segment width.
$wrapafter = get_config('block_completion_progress', 'wrapafter') ?: DEFAULT_COMPLETIONPROGRESS_WRAPAFTER; $wrapafter = get_config('block_completion_progress', 'wrapafter') ?: DEFAULT_COMPLETIONPROGRESS_WRAPAFTER;
if ($wrapafter <= 1) {
$wrapafter = 1;
}
if ($numactivities <= $wrapafter) { if ($numactivities <= $wrapafter) {
$longbars = 'squeeze'; $longbars = 'squeeze';
} }
if ($longbars == 'wrap') { if ($longbars == 'wrap') {
$rows = ceil($numactivities / $wrapafter); $rows = ceil($numactivities / $wrapafter);
if ($rows <= 1) {
$rows = 1;
}
$cellwidth = floor(100 / ceil($numactivities / $rows)); $cellwidth = floor(100 / ceil($numactivities / $rows));
$cellunit = '%'; $cellunit = '%';
$celldisplay = 'inline-block'; $celldisplay = 'inline-block';
@ -393,7 +399,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$content .= HTML_WRITER::tag('svg', $rightpoly, array('class' => 'right-arrow-svg', 'height' => '30', 'width' => '30')); $content .= HTML_WRITER::tag('svg', $rightpoly, array('class' => 'right-arrow-svg', 'height' => '30', 'width' => '30'));
} }
if ($longbars == 'squeeze') { if ($longbars == 'squeeze') {
$cellwidth = floor(100 / $numactivities); $cellwidth = $numactivities > 0 ? floor(100 / $numactivities) : 1;
$cellunit = '%'; $cellunit = '%';
$celldisplay = 'table-cell'; $celldisplay = 'table-cell';
} }

2
version.php

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$plugin->version = 2016081800; $plugin->version = 2016090500;
$plugin->requires = 2014051200; // Moodle 2.7. $plugin->requires = 2014051200; // Moodle 2.7.
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Version for Moodle 2.7 onwards'; $plugin->release = 'Version for Moodle 2.7 onwards';

Loading…
Cancel
Save