1
|
<?php
|
2
|
|
3
|
namespace App\Utils;
|
4
|
|
5
|
/**
|
6
|
* Class for static helper functions.
|
7
|
*/
|
8
|
class Utils {
|
9
|
/**
|
10
|
* Transforms array of arrays in form [['display-name' => whatever, 'key-name' => whatever, ...], ...]
|
11
|
* to simple array in form [dataset-display-name => dataset-key-name, ...].
|
12
|
*
|
13
|
* @param array of arrays for tranformation
|
14
|
*
|
15
|
* @return array in form [dataset-display-name => dataset-key-name, ...]
|
16
|
*/
|
17
|
public static function prepareDatasetsNames($datasets) {
|
18
|
$names = [];
|
19
|
|
20
|
foreach ($datasets as $key => $value) {
|
21
|
if (false == array_key_exists($value['key-name'], $names)) {
|
22
|
$names[$value['display-name']] = $value['key-name'];
|
23
|
}
|
24
|
}
|
25
|
|
26
|
return $names;
|
27
|
}
|
28
|
|
29
|
public static function prepareDatasetsColors($datasets) {
|
30
|
$colors = [];
|
31
|
foreach ($datasets as $key => $value) {
|
32
|
if (false == array_key_exists($value['key-name'], $colors)) {
|
33
|
$colors[$value['key-name']] = $value['display-color'];
|
34
|
}
|
35
|
}
|
36
|
|
37
|
return $colors;
|
38
|
}
|
39
|
}
|