From cf25087e7d7b42d6774eb20e4778e73fc9599ed6 Mon Sep 17 00:00:00 2001 From: Michael de Raadt Date: Mon, 5 Sep 2016 08:52:44 +1000 Subject: [PATCH] CONTRIB-6516 block_completion_progress: Guard divisions in wrap calculations --- lib.php | 8 +++++++- version.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 8421749..a27dbd7 100644 --- a/lib.php +++ b/lib.php @@ -372,11 +372,17 @@ function block_completion_progress_bar($activities, $completions, $config, $user // Determine the segment width. $wrapafter = get_config('block_completion_progress', 'wrapafter') ?: DEFAULT_COMPLETIONPROGRESS_WRAPAFTER; + if ($wrapafter <= 1) { + $wrapafter = 1; + } if ($numactivities <= $wrapafter) { $longbars = 'squeeze'; } if ($longbars == 'wrap') { $rows = ceil($numactivities / $wrapafter); + if ($rows <= 1) { + $rows = 1; + } $cellwidth = floor(100 / ceil($numactivities / $rows)); $cellunit = '%'; $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')); } if ($longbars == 'squeeze') { - $cellwidth = floor(100 / $numactivities); + $cellwidth = $numactivities > 0 ? floor(100 / $numactivities) : 1; $cellunit = '%'; $celldisplay = 'table-cell'; } diff --git a/version.php b/version.php index 5de189c..fb7df92 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2016081800; +$plugin->version = 2016090500; $plugin->requires = 2014051200; // Moodle 2.7. $plugin->maturity = MATURITY_STABLE; $plugin->release = 'Version for Moodle 2.7 onwards';