1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SRF\Filtered\Filter; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* File holding the SRF_FF_Number class |
7
|
|
|
* |
8
|
|
|
* @author Stephan Gambke |
9
|
|
|
* @file |
10
|
|
|
* @ingroup SemanticResultFormats |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use SMWPropertyValue; |
14
|
|
|
use SRF\Filtered\ResultItem; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The SRF_FF_Number class. |
18
|
|
|
* |
19
|
|
|
* Available parameters for this filter: |
20
|
|
|
* number filter origin: the point from which the number is measured (address or geo coordinate) |
21
|
|
|
* number filter property: the property containing the point to which number is measured - not implemented yet |
22
|
|
|
* number filter unit: the unit in which the number is measured |
23
|
|
|
* |
24
|
|
|
* @ingroup SemanticResultFormats |
25
|
|
|
*/ |
26
|
|
|
class NumberFilter extends Filter { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the name (string) or names (array of strings) of the resource |
30
|
|
|
* modules to load. |
31
|
|
|
* |
32
|
|
|
* @return string|array |
33
|
|
|
*/ |
34
|
1 |
|
public function getResourceModules() { |
35
|
1 |
|
return 'ext.srf.filtered.number-filter'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param ResultItem $row |
40
|
|
|
* |
41
|
|
|
* @return array|null |
42
|
|
|
*/ |
43
|
1 |
|
public function getJsDataForRow( ResultItem $row ) { |
44
|
1 |
|
$propertyName = $this->getPrintRequest()->getData()->getInceptiveProperty()->getKey(); |
45
|
|
|
|
46
|
1 |
|
foreach ( $row->getValue() as $field ) { |
47
|
|
|
|
48
|
1 |
|
$printRequest = $field->getPrintRequest(); |
49
|
|
|
|
50
|
1 |
|
if ( $printRequest->getData() instanceof SMWPropertyValue && |
|
|
|
|
51
|
1 |
|
$printRequest->getData()->getInceptiveProperty()->getKey() === $propertyName && |
52
|
1 |
|
( $field->reset() instanceof \SMWDINumber || $field->reset() instanceof \SMWDITime ) |
53
|
|
|
) { |
54
|
|
|
|
55
|
1 |
|
$values = []; // contains plain text |
56
|
1 |
|
$value = $field->getNextDataValue(); |
57
|
|
|
|
58
|
1 |
|
while ( $value instanceof \SMWNumberValue || $value instanceof \SMWTimeValue ) { |
59
|
|
|
|
60
|
1 |
|
if ( $value instanceof \SMWNumberValue ) { |
61
|
1 |
|
$cuv = $value->getConvertedUnitValues(); |
62
|
1 |
|
$values[] = $cuv[$value->getCanonicalMainUnit()]; |
63
|
|
|
} else { |
64
|
|
|
$values[] = $value->getYear(); |
65
|
|
|
} |
66
|
1 |
|
$value = $field->getNextDataItem(); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return [ 'values' => $values ]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return null; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
1 |
|
public function isValidFilterForPropertyType() { |
80
|
1 |
|
$typeID = $this->getPrintRequest()->getTypeID(); |
81
|
1 |
|
return $typeID === '_num' || $typeID === '_qty' || '_dat'; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
protected function buildJsConfig() { |
85
|
1 |
|
parent::buildJsConfig(); |
86
|
1 |
|
$this->addValueToJsConfig( 'number filter collapsible', 'collapsible' ); |
87
|
1 |
|
$this->addValueToJsConfig( 'number filter max value', 'max' ); |
88
|
1 |
|
$this->addValueToJsConfig( 'number filter min value', 'min' ); |
89
|
1 |
|
$this->addValueToJsConfig( 'number filter step', 'step' ); |
90
|
1 |
|
$this->addValueToJsConfig( 'number filter sliders', 'sliders' ); |
91
|
1 |
|
$this->addValueToJsConfig( 'number filter label', 'caption', $this->getPrintRequest()->getOutputFormat() ); |
92
|
1 |
|
$this->addValueListToJsConfig( 'number filter values', 'values' ); |
93
|
1 |
|
$this->addValueListToJsConfig( 'number filter switches', 'switches' ); |
94
|
1 |
|
} |
95
|
|
|
} |
96
|
|
|
|