blob: 0f59128e55e71debcff233d81910722039239179 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<?php
namespace SMW\Query\ProfileAnnotators;
use SMW\DIProperty;
use SMW\Query\ProfileAnnotator;
use SMWDIBlob as DIBlob;
use SMWQuery as Query;
/**
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class ParametersProfileAnnotator extends ProfileAnnotatorDecorator {
/**
* @var Query
*/
private $query;
/**
* @since 2.5
*
* @param ProfileAnnotator $profileAnnotator
* @param Query $query
*/
public function __construct( ProfileAnnotator $profileAnnotator, Query $query ) {
parent::__construct( $profileAnnotator );
$this->query = $query;
}
/**
* ProfileAnnotatorDecorator::addPropertyValues
*/
protected function addPropertyValues() {
list( $sort, $order ) = $this->doSerializeSortKeys( $this->query );
$options = [
'limit' => $this->query->getLimit(),
'offset' => $this->query->getOffset(),
'sort' => $sort,
'order' => $order,
'mode' => $this->query->getQueryMode()
];
$this->getSemanticData()->addPropertyObjectValue(
new DIProperty( '_ASKPA' ),
new DIBlob( json_encode( $options ) )
);
}
private function doSerializeSortKeys( $query ) {
$sort = [];
$order = [];
if ( $query->getSortKeys() === null ) {
return [ $sort, $order ];
}
foreach ( $query->getSortKeys() as $key => $value ) {
$sort[] = $key;
$order[] = strtolower( $value );
}
return [ $sort, $order ];
}
}
|