1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ReportingCloud PHP Wrapper |
5
|
|
|
* |
6
|
|
|
* Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access ReportingCloud in PHP. |
7
|
|
|
* |
8
|
|
|
* @link http://www.reporting.cloud to learn more about ReportingCloud |
9
|
|
|
* @link https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository |
10
|
|
|
* @license https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md |
11
|
|
|
* @copyright © 2016 Text Control GmbH |
12
|
|
|
*/ |
13
|
|
|
namespace TxTextControl\ReportingCloud; |
14
|
|
|
|
15
|
|
|
use TxTextControl\ReportingCloud\Filter\TimestampToDateTime as TimestampToDateTimeFilter; |
16
|
|
|
use TxTextControl\ReportingCloud\PropertyMap\AbstractPropertyMap as PropertyMap; |
17
|
|
|
use TxTextControl\ReportingCloud\PropertyMap\MergeSettings as MergeSettingsPropertyMap; |
18
|
|
|
use TxTextControl\ReportingCloud\Validator\StaticValidator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ReportingCloudTrait |
22
|
|
|
* |
23
|
|
|
* @package TxTextControl\ReportingCloud |
24
|
|
|
* @author Jonathan Maron (@JonathanMaron) |
25
|
|
|
*/ |
26
|
|
|
trait ReportingCloudTrait |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Using the passed propertyMap, recursively build array |
31
|
|
|
* |
32
|
|
|
* @param array $array Array |
33
|
|
|
* @param PropertyMap $propertyMap PropertyMap |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
5 |
|
protected function buildPropertyMapArray($array, PropertyMap $propertyMap) |
38
|
|
|
{ |
39
|
5 |
|
$ret = []; |
40
|
|
|
|
41
|
5 |
|
foreach ($array as $key => $value) { |
42
|
5 |
|
$map = $propertyMap->getMap(); |
43
|
5 |
|
if (isset($map[$key])) { |
44
|
5 |
|
$key = $map[$key]; |
45
|
5 |
|
} |
46
|
5 |
|
if (is_array($value)) { |
47
|
2 |
|
$value = $this->buildPropertyMapArray($value, $propertyMap); |
48
|
2 |
|
} |
49
|
5 |
|
$ret[$key] = $value; |
50
|
5 |
|
} |
51
|
|
|
|
52
|
5 |
|
return $ret; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Using passed mergeSettings array, build array for backend |
57
|
|
|
* |
58
|
|
|
* @param array $array MergeSettings array |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
8 |
|
protected function buildMergeSettingsArray($array) |
63
|
|
|
{ |
64
|
8 |
|
$ret = []; |
65
|
|
|
|
66
|
8 |
|
$filter = new TimestampToDateTimeFilter(); |
67
|
8 |
|
$propertyMap = new MergeSettingsPropertyMap(); |
68
|
|
|
|
69
|
8 |
|
foreach ($propertyMap->getMap() as $property => $key) { |
70
|
8 |
|
if (isset($array[$key])) { |
71
|
8 |
|
$value = $array[$key]; |
72
|
8 |
|
if ('remove_' == substr($key, 0, 7)) { |
73
|
6 |
|
StaticValidator::execute($value, 'TypeBoolean'); |
74
|
4 |
|
} |
75
|
8 |
|
if ('_date' == substr($key, -5)) { |
76
|
8 |
|
StaticValidator::execute($value, 'Timestamp'); |
77
|
6 |
|
$value = $filter->filter($value); |
78
|
6 |
|
} |
79
|
8 |
|
$ret[$property] = $value; |
80
|
8 |
|
} |
81
|
8 |
|
} |
82
|
|
|
|
83
|
4 |
|
return $ret; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Using passed findAndReplaceData associative array (key-value), build array for backend (list of string arrays) |
88
|
|
|
* |
89
|
|
|
* @param array $array FindAndReplaceData array |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
4 |
|
protected function buildFindAndReplaceDataArray($array) |
94
|
|
|
{ |
95
|
4 |
|
$ret = []; |
96
|
|
|
|
97
|
4 |
|
foreach ($array as $search => $replace) { |
98
|
4 |
|
array_push($ret, [$search, $replace]); |
99
|
4 |
|
} |
100
|
|
|
|
101
|
4 |
|
return $ret; |
102
|
|
|
} |
103
|
|
|
} |