Skip to content

Commit

Permalink
Exercises: Fix category order #3644
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 26, 2020
1 parent f4d244a commit f78e1a3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main/exercise/TestCategory.php
Expand Up @@ -796,7 +796,9 @@ public static function get_stats_table_by_attempt($exercise, $category_list = []
$radar = '';
$countCategories = count($category_list);
if ($countCategories > 1) {
$resultsArray = [];
$tempResult = [];
$labels = array_column($categoryNameList, 'title');
$labelsWithId = array_column($categoryNameList, 'title', 'id');
foreach ($category_list as $category_id => $category_item) {
$table->setCellContents($row, 0, $categoryNameList[$category_id]['title']);
$table->setCellContents(
Expand All @@ -819,13 +821,21 @@ public static function get_stats_table_by_attempt($exercise, $category_list = []
true
)
);
$resultsArray[] = round($category_item['score'] / $category_item['total'] * 10);
$tempResult[$category_id] = round($category_item['score'] / $category_item['total'] * 10);
$row++;
}

// Radar requires more than 3 categories.
if ($countCategories > 2 && RESULT_DISABLE_RADAR === (int) $exercise->results_disabled) {
$radar = $exercise->getRadar(array_column($categoryNameList, 'title'), [$resultsArray]);
$resultsArray = [];
foreach ($labelsWithId as $categoryId => $label) {
if (isset($tempResult[$categoryId])) {
$resultsArray[] = $tempResult[$categoryId];
} else {
$resultsArray[] = 0;
}
}
$radar = $exercise->getRadar($labels, [$resultsArray]);
}

if (!empty($none_category)) {
Expand Down

0 comments on commit f78e1a3

Please sign in to comment.