Skip to content

Commit

Permalink
Merge pull request #11693 from nanaya/clean-up-graph-json
Browse files Browse the repository at this point in the history
Clean up user stats json generator
  • Loading branch information
notbakaneko authored Nov 28, 2024
2 parents b24f634 + cbdb502 commit 623459f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,16 +1768,18 @@ function priv_check_user($user, $ability, $object = null)
}

// Used to generate x,y pairs for fancy-chart.coffee
function array_to_graph_json(array &$array, $property_to_use)
function array_to_graph_json(array $array, string $fieldName): array
{
$index = 0;
$ret = [];

return array_map(function ($e) use (&$index, $property_to_use) {
return [
'x' => $index++,
'y' => $e[$property_to_use],
foreach ($array as $index => $item) {
$ret[] = [
'x' => $index,
'y' => $item[$fieldName],
];
}, $array);
}

return $ret;
}

// Fisher-Yates
Expand Down

0 comments on commit 623459f

Please sign in to comment.