Completed
Push — master ( 1fe2bc...e619ac )
by mw
02:21
created

ApprovedStatusPropertyAnnotator.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDIString as DIString;
8
use SESP\PropertyAnnotator;
9
use SESP\AppFactory;
10
use LogReader;
11
12
/**
13
 * @private
14
 * @ingroup SESP
15
 *
16
 * @license GNU GPL v2+
17
 */
18
class ApprovedStatusPropertyAnnotator implements PropertyAnnotator {
19
20
	/**
21
	 * Predefined property ID
22
	 */
23
	const PROP_ID = '___APPROVEDSTATUS';
24
25
	/**
26
	 * @var AppFactory
27
	 */
28
	private $appFactory;
29
30
	/**
31
	 * @var Integer|null
32
	 */
33
	private $approvedStatus;
34
35
	/**
36
	 * @param AppFactory $appFactory
37
	 */
38
	public function __construct( AppFactory $appFactory ) {
39
		$this->appFactory = $appFactory;
40
	}
41
42
	/**
43
	 * @since 2.0
44
	 *
45
	 * @param string $approvedStatus
46
	 */
47
	public function setApprovedStatus( $approvedStatus ) {
48
		$this->approvedStatus = $approvedStatus;
49
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	public function isAnnotatorFor( DIProperty $property ) {
55
		return $property->getKey() === self::PROP_ID;
56
	}
57
58
	public function getDataItem() {
59
		return new DIString( $this->approvedStatus );
0 ignored issues
show
Deprecated Code introduced by
The class SMWDIString has been deprecated with message: Will be removed after SMW 1.9; use SMWDIBlob instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	public function addAnnotation(
66
		DIProperty $property, SemanticData $semanticData
67
	) {
68
		if ( $this->approvedStatus === null && class_exists( 'ApprovedRevs' ) ) {
69
			$logReader = $this->appFactory->newDatabaseLogReader(
70
				$semanticData->getSubject()->getTitle(), 'approval'
71
			);
72
			$this->approvedStatus = $logReader->getStatusOfLogEntry();
73
		}
74
75
		if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== "" ) {
76
			$semanticData->addPropertyObjectValue(
77
				$property, $this->getDataItem()
78
			);
79
		} else {
80
			$semanticData->removeProperty( $property );
81
		}
82
	}
83
}
84