Completed
Push — refact-v2 ( 0317e0 )
by mw
04:47
created

SubPagePropertyAnnotator::addAnnotation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 10
cp 0
crap 6
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\DIWikiPage;
7
use SMW\SemanticData;
8
use SMWDataItem as DataItem;
9
use SMWDINumber as DINumber;
10
use SESP\PropertyAnnotator;
11
use SESP\AppFactory;
12
13
/**
14
 * @private
15
 * @ingroup SESP
16
 *
17
 * @license GNU GPL v2+
18
 * @since 2.0
19
 *
20
 * @author mwjames
21
 */
22
class SubPagePropertyAnnotator implements PropertyAnnotator {
23
24
	/**
25
	 * @var AppFactory
26
	 */
27
	private $appFactory;
28
29
	/**
30
	 * @since 2.0
31
	 *
32
	 * @param AppFactory $appFactory
33
	 */
34
	public function __construct( AppFactory $appFactory ) {
35
		$this->appFactory = $appFactory;
36
	}
37
38
	/**
39
	 * @since 2.0
40
	 *
41
	 * {@inheritDoc}
42
	 */
43
	public function isAnnotatorFor( DIProperty $property ) {
44
		return $property->getKey() === '___SUBP' ;
45
	}
46
47
	/**
48
	 * @since 2.0
49
	 *
50
	 * {@inheritDoc}
51
	 */
52
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
53
54
		$title = $semanticData->getSubject()->getTitle();
55
56
		//-1 = no limit. Returns TitleArray object
57
		$subpages = $title->getSubpages( -1 );
58
59
		foreach ( $subpages as $title ) {
60
			$semanticData->addPropertyObjectValue(
61
				$property,
62
				DIWikiPage::newFromTitle( $title )
63
			);
64
		}
65
	}
66
67
}
68