Completed
Pull Request — master (#30)
by mw
05:10 queued 03:52
created

PropertyRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 106
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B registerTo() 0 57 4
A addPropertyDefinition() 0 17 2
1
<?php
2
3
namespace SMW\Notifications;
4
5
use SMW\PropertyRegistry as SemanticMediaWikiPropertyRegistry;
6
use SMW\Notifications\DataValues\NotificationGroupValue;
7
8
define( 'SMW_NOTIFICATIONS_ON', 'Notifications on' );
9
define( 'SMW_NOTIFICATIONS_TO_GROUP', 'Notifications to group' );
10
define( 'SMW_NOTIFICATIONS_GROUP_MEMBER_OF', 'Notifications group member of' );
11
define( 'SMW_NOTIFICATIONS_TO', 'Notifications to' );
12
13
/**
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class PropertyRegistry {
20
21
	/**
22
	 * Marking a property to be watched
23
	 */
24
	const NOTIFICATIONS_ON = "__notifications_on";
25
26
	/**
27
	 * Group assigned to the property to can point recipients
28
	 */
29
	const NOTIFICATIONS_TO_GROUP = "__notifications_to_group";
30
31
	/**
32
	 * Users assigned to a group
33
	 */
34
	const NOTIFICATIONS_GROUP_MEMBER_OF = "__notifications_group_member";
35
36
	/**
37
	 * List of individuals that can be listed directly
38
	 */
39
	const NOTIFICATIONS_TO = "__notifications_to";
40
41
	/**
42
	 * @since 1.0
43
	 *
44
	 * @param SemanticMediaWikiPropertyRegistry $propertyRegistry
45
	 *
46
	 * @return boolean
47
	 */
48
	public function registerTo( SemanticMediaWikiPropertyRegistry $propertyRegistry ) {
49
50
		$propertyDefinitions = array(
51
52
			self::NOTIFICATIONS_ON => array(
53
				'label' => SMW_NOTIFICATIONS_ON,
54
				'type'  => '_txt',
55
				'alias' => array( wfMessage( 'smw-notifications-property-alias-notifications-on' )->text() ),
56
				'msgkey' => 'smw-notifications-property-alias-notifications-on',
57
				'visible' => true,
58
				'annotable' => true
59
			),
60
61
			self::NOTIFICATIONS_TO_GROUP => array(
62
				'label' => SMW_NOTIFICATIONS_TO_GROUP,
63
				'type'  => '_txt',
64
				'alias' => array( wfMessage( 'smw-notifications-property-alias-notifications-to-group' )->text() ),
65
				'msgkey' => 'smw-notifications-property-alias-notifications-to-group',
66
				'visible' => true,
67
				'annotable' => true
68
			),
69
70
			self::NOTIFICATIONS_GROUP_MEMBER_OF => array(
71
				'label' => SMW_NOTIFICATIONS_GROUP_MEMBER_OF,
72
				'type'  => NotificationGroupValue::TYPE_ID,
73
				'alias' => array( wfMessage( 'smw-notifications-property-alias-notifications-group-member-of' )->text() ),
74
				'msgkey' => 'smw-notifications-property-alias-notifications-group',
75
				'visible' => true,
76
				'annotable' => true
77
			),
78
79
			self::NOTIFICATIONS_TO => array(
80
				'label' => SMW_NOTIFICATIONS_TO,
81
				'type'  => '_wpg',
82
				'alias' => array( wfMessage( 'smw-notifications-property-alias-notifications-to' )->text() ),
83
				'msgkey' => 'smw-notifications-property-alias-notifications-to',
84
				'visible' => true,
85
				'annotable' => true
86
			)
87
		);
88
89
		foreach ( $propertyDefinitions as $id => $definition ) {
90
			$this->addPropertyDefinition( $propertyRegistry, $id, $definition );
91
		}
92
93
		foreach ( $propertyDefinitions as $id => $definition ) {
94
			// 2.4+
95
			if ( method_exists( $propertyRegistry, 'registerPropertyAliasByMsgKey' ) ) {
96
				$propertyRegistry->registerPropertyAliasByMsgKey(
97
					$id,
98
					$definition['msgkey']
99
				);
100
			}
101
		}
102
103
		return true;
104
	}
105
106
	private function addPropertyDefinition( $propertyRegistry, $id, $definition ) {
107
108
		$propertyRegistry->registerProperty(
109
			$id,
110
			$definition['type'],
111
			$definition['label'],
112
			$definition['visible'],
113
			$definition['annotable']
114
		);
115
116
		foreach ( $definition['alias'] as $alias ) {
117
			$propertyRegistry->registerPropertyAlias(
118
				$id,
119
				$alias
120
			);
121
		}
122
	}
123
124
}
125