Skip to content

Commit

Permalink
Update duration display
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed May 17, 2024
1 parent 824d69a commit 8c2688a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
21 changes: 20 additions & 1 deletion classes/grouped_profile_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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.
*
Expand Down
25 changes: 24 additions & 1 deletion classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,37 @@ 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.
* @return 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) {
Expand Down
6 changes: 3 additions & 3 deletions profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down

0 comments on commit 8c2688a

Please sign in to comment.