1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SourceBroker\Hugo\Indexer; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class FieldTransformer |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
class FieldTransformer |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Convert timestamp to another date format |
13
|
|
|
* |
14
|
|
|
* @param string $currentValue |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public function convertDate($currentValue) |
18
|
|
|
{ |
19
|
|
|
return $currentValue ? date('Y-m-d\TH:i:s\Z', $currentValue) : ''; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Add space classes |
24
|
|
|
* |
25
|
|
|
* @param string $currentValue |
26
|
|
|
* @param array $contentElementRawData |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function addSpaceClass($currentValue, $contentElementRawData) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
return implode(' ', array_filter(array_merge( |
32
|
|
|
explode(',', $contentElementRawData['space_before_class']), |
33
|
|
|
explode(',', $contentElementRawData['space_after_class']) |
34
|
|
|
))); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Replace commas with spaces in the string |
39
|
|
|
* |
40
|
|
|
* @param string $currentValue |
41
|
|
|
* @param array $contentElementRawData |
42
|
|
|
* @param string $fieldName |
43
|
|
|
* @param string $method |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function commaToSpace( |
47
|
|
|
$currentValue, |
48
|
|
|
/** @noinspection PhpUnusedParameterInspection */ |
49
|
|
|
$contentElementRawData, |
|
|
|
|
50
|
|
|
/** @noinspection PhpUnusedParameterInspection */ |
51
|
|
|
$fieldName, |
|
|
|
|
52
|
|
|
$method |
53
|
|
|
) { |
54
|
|
|
$fieldElements = preg_split('/,[\s]*/', $currentValue); |
55
|
|
|
|
56
|
|
|
if ($method == 'merge') { |
57
|
|
|
return implode(' ', array_merge([$currentValue], $fieldElements)); |
58
|
|
|
} else { |
59
|
|
|
return implode(' ', $fieldElements); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Remove duplicate classes from string |
65
|
|
|
* |
66
|
|
|
* @param string $currentValue |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function removeDuplicateClasses($currentValue) |
70
|
|
|
{ |
71
|
|
|
$classes = explode(' ', $currentValue); |
72
|
|
|
|
73
|
|
|
return trim(implode(' ', array_unique($classes)), ' '); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Convert string to integer |
78
|
|
|
* |
79
|
|
|
* @param string $currentValue |
80
|
|
|
* @return int |
81
|
|
|
*/ |
82
|
|
|
public function toInteger($currentValue) |
83
|
|
|
{ |
84
|
|
|
return (int)$currentValue; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.