summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Query/ProfileAnnotators/StatusCodeProfileAnnotator.php
blob: 8afc5ce4e189cf1235332214b412e61d7fb04d56 (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
<?php

namespace SMW\Query\ProfileAnnotators;

use SMW\DIProperty;
use SMW\Query\ProfileAnnotator;
use SMWDINumber as DINumber;

/**
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class StatusCodeProfileAnnotator extends ProfileAnnotatorDecorator {

	/**
	 * @var array
	 */
	private $statusCodes = [];

	/**
	 * @since 3.0
	 *
	 * @param ProfileAnnotator $profileAnnotator
	 * @param array $statusCodes
	 */
	public function __construct( ProfileAnnotator $profileAnnotator, array $statusCodes = [] ) {
		parent::__construct( $profileAnnotator );
		$this->statusCodes = $statusCodes;
	}

	/**
	 * ProfileAnnotatorDecorator::addPropertyValues
	 */
	protected function addPropertyValues() {
		if ( $this->statusCodes !== [] ) {
			foreach ( $this->statusCodes as $statusCode ) {
				$this->addStatusCodeAnnotation( $statusCode );
			}
		}
	}

	private function addStatusCodeAnnotation( $statusCode ) {
		$this->getSemanticData()->addPropertyObjectValue(
			new DIProperty( '_ASKCO' ),
			new DINumber( $statusCode )
		);
	}

}