1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace HDNET\OnpageIntegration\Service; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
use HDNET\OnpageIntegration\Loader\ApiResultLoader; |
10
|
|
|
|
11
|
|
|
class OnPageService extends AbstractService |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var ApiResultLoader |
16
|
|
|
*/ |
17
|
|
|
protected $loader; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* OnPageService constructor. |
21
|
|
|
* |
22
|
|
|
* @param ApiResultLoader $loader |
23
|
|
|
*/ |
24
|
|
|
public function __construct(ApiResultLoader $loader) |
25
|
|
|
{ |
26
|
|
|
$this->loader = $loader; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* So that you get the error report of an |
31
|
|
|
* api call you have to crawl the graph api call |
32
|
|
|
* from a filter. |
33
|
|
|
* |
34
|
|
|
* In the next the you load the error report keys and |
35
|
|
|
* commit it into the errorReport function. |
36
|
|
|
* |
37
|
|
|
* errorReport generates the error report and afterwards |
38
|
|
|
* its stores in the field 'errors'. |
39
|
|
|
* ' * |
40
|
|
|
* |
41
|
|
|
* @param array $buildData |
42
|
|
|
* @param string $section |
43
|
|
|
* @param ApiResultLoader $loader |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
public function build($buildData, $section) |
46
|
|
|
{ |
47
|
|
|
$i = 0; |
48
|
|
|
foreach ($buildData as &$element) { |
49
|
|
|
$graphDataArray = $this->loader->load('zoom_' . $section . '_' . $i . '_graph'); |
50
|
|
|
$errorReportKey = $element['errors']; |
51
|
|
|
$element['errors'] = $this->errorReport($graphDataArray, $errorReportKey); |
52
|
|
|
$i++; |
53
|
|
|
} |
54
|
|
|
return $buildData; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Generates the error report key of an api call and |
59
|
|
|
* return the result. |
60
|
|
|
* |
61
|
|
|
* @param mixed $graphApiCallResult |
62
|
|
|
* @param mixed $errorReportKey |
63
|
|
|
* |
64
|
|
|
* @return int |
65
|
|
|
*/ |
66
|
|
|
protected function errorReport($graphApiCallResult, $errorReportKey) |
67
|
|
|
{ |
68
|
|
|
$totalErrors = 0; |
69
|
|
|
foreach ($graphApiCallResult as $element) { |
70
|
|
|
if (in_array('sum', $errorReportKey)) { |
71
|
|
|
foreach ($errorReportKey['hidden'] as $hidden) { |
72
|
|
|
if (in_array($hidden, $element)) { |
73
|
|
|
continue 2; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
$totalErrors += $element['count']; |
77
|
|
|
} |
78
|
|
|
if (in_array($errorReportKey['show'], $element)) { |
79
|
|
|
$totalErrors += $element['count']; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
return $totalErrors; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Fitted $tableApiCallResult by the elements of |
87
|
|
|
* $showTableKey |
88
|
|
|
* |
89
|
|
|
* @param string $apiCall |
90
|
|
|
* @param array $showTableKey |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function showColumns($apiCall, array $showTableKey) |
95
|
|
|
{ |
96
|
|
|
$apiCallResult = $this->loader->load($apiCall); |
97
|
|
|
|
98
|
|
|
$fittedTablesRecords = []; |
99
|
|
|
foreach ($apiCallResult as $singleCallElement) { |
100
|
|
|
foreach ($showTableKey as $key) { |
101
|
|
|
if (array_key_exists($key, $singleCallElement)) { |
102
|
|
|
$singleRecordArray[$key] = $singleCallElement[$key]; |
|
|
|
|
103
|
|
|
} |
104
|
|
|
if($key === 'documents') { |
105
|
|
|
$documents = [ |
106
|
|
|
'mime' => $singleCallElement['mime'], |
107
|
|
|
'meta_title' => $singleCallElement['meta_title'], |
108
|
|
|
'url' => $singleCallElement['url'], |
109
|
|
|
]; |
110
|
|
|
$singleRecordArray['document'] = $documents; |
|
|
|
|
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
$fittedTablesRecords[] = $this->replaceNULL($singleRecordArray); |
114
|
|
|
} |
115
|
|
|
return $fittedTablesRecords; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Build only for development |
120
|
|
|
*/ |
121
|
|
|
public function replaceNULL($array) |
122
|
|
|
{ |
123
|
|
|
foreach ($array as &$element) { |
124
|
|
|
if(empty($element)) { |
125
|
|
|
$element = "Keine"; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
return $array; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.