1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class for handling concept property values. |
5
|
|
|
*/ |
6
|
|
|
class ConceptPropertyValue extends VocabularyDataObject |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** submembers */ |
9
|
|
|
private $submembers; |
10
|
|
|
/** property type */ |
11
|
|
|
private $type; |
12
|
|
|
/** content language */ |
13
|
|
|
private $clang; |
14
|
|
|
|
15
|
|
View Code Duplication |
public function __construct($model, $vocab, $resource, $prop, $clang = '') |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
parent::__construct($model, $vocab, $resource); |
18
|
|
|
$this->submembers = array(); |
19
|
|
|
$this->type = $prop; |
20
|
|
|
$this->clang = $clang; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __toString() |
24
|
|
|
{ |
25
|
|
|
$label = is_string($this->getLabel()) ? $this->getLabel() : $this->getLabel()->getValue(); |
26
|
|
|
if ($this->vocab->getConfig()->sortByNotation()) { |
27
|
|
|
$label = $this->getNotation() . $label; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $label; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getLang() |
34
|
|
|
{ |
35
|
|
|
return $this->getEnvLang(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getLabel($lang = '') |
39
|
|
|
{ |
40
|
|
|
if ($this->clang) { |
41
|
|
|
$lang = $this->clang; |
42
|
|
|
} |
43
|
|
|
if ($this->vocab->getConfig()->getLanguageOrder($lang)) { |
44
|
|
View Code Duplication |
foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { |
|
|
|
|
45
|
|
|
if ($this->resource->label($fallback) !== null) { |
46
|
|
|
return $this->resource->label($fallback); |
47
|
|
|
} |
48
|
|
|
// We need to check all the labels in case one of them matches a subtag of the current language |
49
|
|
|
if ($this->resource->allLiterals('skos:prefLabel')) { |
50
|
|
|
foreach($this->resource->allLiterals('skos:prefLabel') as $label) { |
51
|
|
|
// the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language |
52
|
|
|
if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { |
53
|
|
|
return EasyRdf\Literal::create($label, $fallback); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($this->resource->label($lang) !== null) { // current language |
61
|
|
|
return $this->resource->label($lang); |
62
|
|
|
} elseif ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) { // vocab default language |
63
|
|
|
return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage()); |
64
|
|
|
} elseif ($this->resource->label() !== null) { // any language |
65
|
|
|
return $this->resource->label(); |
66
|
|
|
} elseif ($this->resource->getLiteral('rdf:value', $lang) !== null) { // current language |
67
|
|
|
return $this->resource->getLiteral('rdf:value', $lang); |
68
|
|
|
} elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language |
69
|
|
|
return $this->resource->getLiteral('rdf:value'); |
70
|
|
|
} |
71
|
|
|
// uri if no label is found |
72
|
|
|
$label = $this->resource->shorten() ? $this->resource->shorten() : $this->getUri(); |
73
|
|
|
return $label; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getType() |
77
|
|
|
{ |
78
|
|
|
return $this->type; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getUri() |
82
|
|
|
{ |
83
|
|
|
return $this->resource->getUri(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getVocab() |
87
|
|
|
{ |
88
|
|
|
return $this->vocab; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getVocabName() |
92
|
|
|
{ |
93
|
|
|
return $this->vocab->getTitle(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function addSubMember($member, $lang = '') |
97
|
|
|
{ |
98
|
|
|
$label = $member->getLabel($lang) ? $member->getLabel($lang) : $member->getLabel(); |
99
|
|
|
$this->submembers[$label->getValue()] = $member; |
100
|
|
|
$this->sortSubMembers(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getSubMembers() |
104
|
|
|
{ |
105
|
|
|
if (empty($this->submembers)) { |
106
|
|
|
return null; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->submembers; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private function sortSubMembers() |
113
|
|
|
{ |
114
|
|
|
if (!empty($this->submembers)) { |
115
|
|
|
ksort($this->submembers); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function isExternal() { |
121
|
|
|
$propertyUris = $this->resource->propertyUris(); |
122
|
|
|
return empty($propertyUris); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getNotation() |
126
|
|
|
{ |
127
|
|
|
if ($this->vocab->getConfig()->showNotation() && $this->resource->get('skos:notation')) { |
128
|
|
|
return $this->resource->get('skos:notation')->getValue(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function isReified() { |
134
|
|
|
return (!$this->resource->label() && $this->resource->getLiteral('rdf:value')); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getReifiedPropertyValues() { |
138
|
|
|
$ret = array(); |
139
|
|
|
$props = $this->resource->propertyUris(); |
140
|
|
|
foreach($props as $prop) { |
141
|
|
|
$prop = (EasyRdf\RdfNamespace::shorten($prop) !== null) ? EasyRdf\RdfNamespace::shorten($prop) : $prop; |
142
|
|
|
foreach ($this->resource->allLiterals($prop) as $val) { |
143
|
|
|
if ($prop !== 'rdf:value' && $this->resource->get($prop)) { // shown elsewhere |
144
|
|
|
$ret[gettext($prop)] = new ConceptPropertyValueLiteral($this->resource->get($prop), $prop); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
foreach ($this->resource->allResources($prop) as $val) { |
148
|
|
|
$ret[gettext($prop)] = new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
return $ret; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.