Completed
Pull Request — master (#95)
by Mark A.
05:26
created

ApprovedRevPropertyAnnotator::isAnnotatorFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDataItem as DataItem;
8
use SMWDINumber as DINumber;
9
use SMWDIBoolean as DIBool;
10
use SESP\PropertyAnnotator;
11
use SESP\AppFactory;
12
use ApprovedRevs;
13
14
/**
15
 * @private
16
 * @ingroup SESP
17
 *
18
 * @license GNU GPL v2+
19
 */
20
class ApprovedRevPropertyAnnotator implements PropertyAnnotator {
21
22
	/**
23
	 * Predefined property ID
24
	 */
25
	const PROP_ID = '___APPROVED';
26
27
	/**
28
	 * @var AppFactory
29
	 */
30
	private $appFactory;
31
32
	/**
33
	 * @param AppFactory $appFactory
34
	 */
35
	public function __construct( AppFactory $appFactory ) {
36
		$this->appFactory = $appFactory;
37
	}
38
39
	/**
40
	 * {@inheritDoc}
41
	 */
42
	public function isAnnotatorFor( DIProperty $property ) {
43
		return $property->getKey() === self::PROP_ID;
44
	}
45
46
	/**
47
	 * {@inheritDoc}
48
	 */
49
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
50
		if ( !class_exists( 'ApprovedRevs' ) ) {
51
			return null;
52
		}
53
54
		$title = $semanticData->getSubject()->getTitle();
55
		$rev = ApprovedRevs::getApprovedRevID( $title );
56
57
		if ( is_numeric( $rev ) ) {
58
			$semanticData->addPropertyObjectValue( $property, new DINumber( $rev ) );
59
		} else {
60
			$semanticData->removeProperty( $property );
61
		}
62
	}
63
}
64