1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ModernTimeline\ResultFacade; |
6
|
|
|
|
7
|
|
|
use SMW\DIWikiPage; |
8
|
|
|
use SMW\Query\PrintRequest; |
9
|
|
|
use SMWQueryResult; |
10
|
|
|
|
11
|
|
|
class ResultSimplifier { |
12
|
|
|
|
13
|
4 |
|
public function newSubjectCollection( SMWQueryResult $result ): SubjectCollection { |
14
|
4 |
|
$subjects = []; |
15
|
|
|
|
16
|
4 |
|
foreach ( $result->getResults() as $diWikiPage ) { |
17
|
3 |
|
$subjects[] = $this->newSubject( $diWikiPage, $result->getPrintRequests(), $result ); |
18
|
|
|
} |
19
|
|
|
|
20
|
4 |
|
return new SubjectCollection( $subjects ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param DIWikiPage $resultPage |
25
|
|
|
* @param PrintRequest[] $printRequests |
26
|
|
|
* @param SMWQueryResult $result |
27
|
|
|
* @return Subject |
28
|
|
|
*/ |
29
|
3 |
|
private function newSubject( DIWikiPage $resultPage, array $printRequests, SMWQueryResult $result ): Subject { |
30
|
3 |
|
$propertyValueCollections = []; |
31
|
|
|
|
32
|
3 |
|
foreach ( $printRequests as $printRequest ) { |
33
|
3 |
|
$dataItems = $this->newResultArray( $resultPage, $printRequest, $result )->getContent(); |
34
|
|
|
|
35
|
3 |
|
$propertyValueCollections[] = new PropertyValueCollection( |
36
|
3 |
|
$printRequest, |
37
|
3 |
|
$dataItems === false ? [] : $dataItems |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
return new Subject( $resultPage, $propertyValueCollections ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Compat with SMW 3.0 |
46
|
|
|
* In 3.1+ do: ResultArray::factory( $resultPage, $printRequest, $result ) |
47
|
|
|
*/ |
48
|
3 |
|
private function newResultArray( DIWikiPage $resultPage, PrintRequest $printRequest, SMWQueryResult $result ): \SMWResultArray { |
49
|
3 |
|
return new \SMWResultArray( |
50
|
3 |
|
$resultPage, |
51
|
|
|
$printRequest, |
52
|
3 |
|
$result->getStore(), |
53
|
3 |
|
method_exists( $result, 'getFieldItemFinder' ) ? $result->getFieldItemFinder() : null |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|