1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class ArrayUtility |
4
|
|
|
*/ |
5
|
|
|
namespace HDNET\OnpageIntegration\Utility; |
6
|
|
|
|
7
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
8
|
|
|
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ArrayUtility |
12
|
|
|
*/ |
13
|
|
|
class ArrayUtility |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Append the errors of an api call to |
18
|
|
|
* metaDataArray |
19
|
|
|
* |
20
|
|
|
* @param $metaDataArray |
21
|
|
|
* @param $section |
22
|
|
|
*/ |
23
|
|
|
public static function buildIndexActionArray(&$metaDataArray, $section) |
24
|
|
|
{ |
25
|
|
|
$loader = GeneralUtility::makeInstance(\HDNET\OnpageIntegration\Loader\ApiResultLoader::class); |
26
|
|
|
|
27
|
|
|
for ($i = 0; $i < count($metaDataArray[0]); $i++) { |
|
|
|
|
28
|
|
|
|
29
|
|
|
$graphDataArray = $loader->load('zoom_' . $section . '_' . $i . '_graph'); |
30
|
|
|
$errorReportyKey = $metaDataArray[0][$i]['errors']; |
31
|
|
|
|
32
|
|
|
$metaDataArray[0][$i]['errors'] = self::errorReport($graphDataArray, $errorReportyKey); |
33
|
|
|
//todo remove |
34
|
|
|
$metaDataArray[0][$i]['test'] = $graphDataArray; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine the error report of an aspect |
40
|
|
|
* |
41
|
|
|
* @param $graphApiCallResult |
42
|
|
|
* @param $errorReportKey |
43
|
|
|
* |
44
|
|
|
* @return int |
45
|
|
|
*/ |
46
|
|
|
protected static function errorReport($graphApiCallResult,$errorReportKey) { |
47
|
|
|
$totalErrors = 0; |
48
|
|
|
|
49
|
|
|
foreach($graphApiCallResult as $element) { |
50
|
|
|
|
51
|
|
|
if(in_array('sum', $errorReportKey)) { |
52
|
|
|
if(in_array($errorReportKey['hidden'], $element)) { |
53
|
|
|
continue; |
54
|
|
|
} |
55
|
|
|
$totalErrors += $element['count']; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if(in_array($errorReportKey['show'], $element)) { |
59
|
|
|
$totalErrors += $element['count']; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
return $totalErrors; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Fitted $tableApiCallResult by the elements of |
67
|
|
|
* $showTableKey |
68
|
|
|
* |
69
|
|
|
* @param array $tableApiCallResult |
70
|
|
|
* @param array $showTableKey |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public static function showTable(array $tableApiCallResult,array $showTableKey) { |
75
|
|
|
$fittedTablesRecords = []; |
76
|
|
|
foreach($tableApiCallResult as $singleCallElement) { |
77
|
|
|
|
78
|
|
|
foreach($showTableKey as $key) { |
79
|
|
|
if(array_key_exists($key, $singleCallElement)) { |
80
|
|
|
$singleRecordArray[$key] = $singleCallElement[$key]; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
$fittedTablesRecords[] = $singleRecordArray; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
return $fittedTablesRecords; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: