diff --git a/classes/grouped_profile_table.php b/classes/grouped_profile_table.php index 02c4582..e788272 100644 --- a/classes/grouped_profile_table.php +++ b/classes/grouped_profile_table.php @@ -34,10 +34,10 @@ abstract class grouped_profile_table extends profile_table { /** Columns to be displayed.*/ const COLUMNS = [ 'maxduration', + 'minduration', 'requestcount', 'maxcreated', 'mincreated', - 'minduration', ]; /** @var \moodle_url URL path to use for linking to profile groups. */ @@ -82,6 +82,25 @@ protected function put_sql(): void { ); } + /** + * Defines the columns for this table. + * + * @throws \coding_exception + */ + public function make_columns(): void { + $headers = []; + $columns = $this->get_columns(); + foreach ($columns as $column) { + $headers[] = get_string('field_' . $column, 'tool_excimer'); + } + + $this->define_columns($columns); + $this->column_class('maxduration', 'text-right'); + $this->column_class('minduration', 'text-right'); + $this->column_class('requestcount', 'text-center'); + $this->define_headers($headers); + } + /** * Get the columns to be displayed. * diff --git a/classes/helper.php b/classes/helper.php index c93c434..1da07ef 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -88,7 +88,7 @@ public static function reason_display(int $reason): string { } /** - * Returns a formatted time duration in a human readable format. + * Returns a formatted time duration in h:m:s format. * * @param float $duration * @param bool $markup If true, then use markup on the result. @@ -96,6 +96,29 @@ public static function reason_display(int $reason): string { * @throws \Exception */ public static function duration_display(float $duration, bool $markup = true): string { + if (!$markup) { + return $duration; + } + + $s = (int) $duration; + $h = $s / 3600; + $m = ($s % 3600) / 60; + $s = $s % 60; + if ($h >= 1) { + return sprintf('%d:%02d:%02d', $h, $m, $s); + } + return sprintf('%d:%02d', $m, $s); + } + + /** + * Returns a formatted time duration in a human readable format. + * + * @param float $duration + * @param bool $markup If true, then use markup on the result. + * @return string + * @throws \Exception + */ + public static function duration_display_text(float $duration, bool $markup = true): string { // Variable $markup allows a different format when viewed (true) vs downloaded (false). if ($markup) { if (intval($duration) > 10) { diff --git a/profile.php b/profile.php index 54032a3..8f1105b 100644 --- a/profile.php +++ b/profile.php @@ -122,11 +122,11 @@ $data['finished'] = userdate($data['finished']); $duration = $data['duration']; -$data['duration'] = helper::duration_display($duration, true); +$data['duration'] = helper::duration_display_text($duration, true); if (isset($data['lockwait'])) { $lockwait = $data['lockwait']; - $data['lockwait'] = helper::duration_display($lockwait, true); - $data['lockheld'] = helper::duration_display($data['lockheld'], true); + $data['lockwait'] = helper::duration_display_text($lockwait, true); + $data['lockheld'] = helper::duration_display_text($data['lockheld'], true); $data['lockwaiturl'] = helper::lockwait_display_link($data['lockwaiturl'], $lockwait); $data['lockwaiturlhelp'] = helper::lockwait_display_help($OUTPUT, $data['lockwaiturl']);