Skip to content
Snippets Groups Projects
Commit 37fcd4da authored by Andy Hubert's avatar Andy Hubert Committed by Ryan Smith
Browse files

fix: Ensures statement duration isn't null (Thanks @AndyHubert). (#209)

parent a8ec9bcb
No related branches found
No related tags found
No related merge requests found
...@@ -18,10 +18,11 @@ namespace src\transformer\utils; ...@@ -18,10 +18,11 @@ namespace src\transformer\utils;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
function get_attempt_duration($attempt) { function get_attempt_duration($attempt) {
if (isset($attempt->timefinish)) { if (isset($attempt->timefinish) && isset($attempt->timestart)) {
$seconds = $attempt->timefinish - $attempt->timestart; $seconds = $attempt->timefinish - $attempt->timestart;
return "PT".(string) $seconds."S"; if ($seconds > 0) {
} else { return "PT".(string) $seconds."S";
return null; }
} }
return null;
} }
...@@ -31,7 +31,7 @@ function get_attempt_result(array $config, $attempt, $gradeitem) { ...@@ -31,7 +31,7 @@ function get_attempt_result(array $config, $attempt, $gradeitem) {
$success = $gradesum >= $passscore; $success = $gradesum >= $passscore;
$duration = get_attempt_duration($attempt); $duration = get_attempt_duration($attempt);
return [ $result = [
'score' => [ 'score' => [
'raw' => $rawscore, 'raw' => $rawscore,
'min' => $minscore, 'min' => $minscore,
...@@ -40,6 +40,11 @@ function get_attempt_result(array $config, $attempt, $gradeitem) { ...@@ -40,6 +40,11 @@ function get_attempt_result(array $config, $attempt, $gradeitem) {
], ],
'completion' => $completed, 'completion' => $completed,
'success' => $success, 'success' => $success,
'duration' => $duration,
]; ];
if ($duration != null) {
$result['duration'] = $duration;
}
return $result;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment