1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* VocabularyConfig provides access to the vocabulary configuration defined in config.ttl. |
5
|
|
|
*/ |
6
|
|
|
class VocabularyConfig extends BaseConfig |
7
|
|
|
{ |
8
|
|
|
private $plugins; |
9
|
|
|
private $languageOrderCache = array(); |
10
|
|
|
|
11
|
|
|
public function __construct($resource, $globalPlugins=array()) |
12
|
|
|
{ |
13
|
|
|
$this->resource = $resource; |
14
|
|
|
$plugins = $this->resource->allLiterals('skosmos:usePlugin'); |
15
|
|
|
$pluginArray = array(); |
16
|
|
|
if ($plugins) { |
17
|
|
|
foreach ($plugins as $pluginlit) { |
18
|
|
|
$pluginArray[] = $pluginlit->getValue(); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
$this->plugins = new PluginRegister(array_merge($globalPlugins, $pluginArray)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get the default language of this vocabulary |
26
|
|
|
* @return string default language, e.g. 'en' |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
public function getDefaultLanguage() |
30
|
|
|
{ |
31
|
|
|
$deflang = $this->resource->getLiteral('skosmos:defaultLanguage'); |
32
|
|
|
if ($deflang) { |
33
|
|
|
return $deflang->getValue(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$langs = $this->getLanguages(); |
37
|
|
|
$deflang = reset($langs); // picking the first one from the list with reset since the keys are not numeric |
38
|
|
|
if (sizeof($langs) > 1) { |
39
|
|
|
trigger_error("Default language for vocabulary '" . $this->getShortName() . "' unknown, choosing '$deflang'.", E_USER_WARNING); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $deflang; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Wether the alphabetical index is small enough to be shown all at once. |
47
|
|
|
* @return boolean true if all concepts can be shown at once. |
48
|
|
|
*/ |
49
|
|
|
public function getAlphabeticalFull() |
50
|
|
|
{ |
51
|
|
|
return $this->getBoolean('skosmos:fullAlphabeticalIndex'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns a short name for a vocabulary if configured. If that has not been set |
56
|
|
|
* using vocabId as a fallback. |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getShortName() |
60
|
|
|
{ |
61
|
|
|
$shortname = $this->getLiteral('skosmos:shortName'); |
62
|
|
|
if ($shortname) |
63
|
|
|
return $shortname; |
64
|
|
|
|
65
|
|
|
// if no shortname exists fall back to the id |
66
|
|
|
return $this->getId(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the vocabulary feedback e-mail address and return it. |
71
|
|
|
* |
72
|
|
|
* @return string e-mail address or null if not defined. |
73
|
|
|
*/ |
74
|
|
|
public function getFeedbackRecipient() |
75
|
|
|
{ |
76
|
|
|
$email = $this->resource->get('skosmos:feedbackRecipient'); |
77
|
|
|
return isset($email) ? $email->getValue() : null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the human readable vocabulary title. |
82
|
|
|
* @return string the title of the vocabulary |
83
|
|
|
*/ |
84
|
|
|
public function getTitle($lang = null) |
85
|
|
|
{ |
86
|
|
|
return $this->getLiteral('dc:title', false, $lang); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns a boolean value set in the config.ttl config. |
91
|
|
|
* @return boolean |
92
|
|
|
*/ |
93
|
|
|
public function sortByNotation() |
94
|
|
|
{ |
95
|
|
|
return $this->getBoolean('skosmos:sortByNotation'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns a boolean value set in the config.ttl config. |
100
|
|
|
* @return boolean |
101
|
|
|
*/ |
102
|
|
|
public function showChangeList() |
103
|
|
|
{ |
104
|
|
|
return $this->getBoolean('skosmos:showChangeList'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* get the URLs from which the vocabulary data can be downloaded |
109
|
|
|
* @return array Array with MIME type as key, URL as value |
110
|
|
|
*/ |
111
|
|
|
public function getDataURLs() |
112
|
|
|
{ |
113
|
|
|
$ret = array(); |
114
|
|
|
$urls = $this->resource->allResources("void:dataDump"); |
115
|
|
|
foreach ($urls as $url) { |
116
|
|
|
// first try dc:format and dc11:format |
117
|
|
|
$mimetypelit = $url->getLiteral('dc:format'); |
118
|
|
|
if ($mimetypelit === null) { |
119
|
|
|
$mimetypelit = $url->getLiteral('dc11:format'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ($mimetypelit !== null) { |
123
|
|
|
$mimetype = $mimetypelit->getValue(); |
124
|
|
|
} else { |
125
|
|
|
$format = EasyRdf\Format::guessFormat(null, $url->getURI()); |
126
|
|
|
if ($format === null) { |
127
|
|
|
trigger_error("Could not guess format for <$url>.", E_USER_WARNING); |
128
|
|
|
continue; |
129
|
|
|
} |
130
|
|
|
$mimetypes = array_keys($format->getMimeTypes()); |
131
|
|
|
$mimetype = $mimetypes[0]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$langLit = $url->getLiteral('dc:language'); |
135
|
|
|
|
136
|
|
|
if ($langLit != null) { |
137
|
|
|
//when the mimetype has language variants |
138
|
|
|
$dataUrlLang = $langLit->getValue(); |
139
|
|
|
|
140
|
|
|
if (!isset($ret[$mimetype])) { |
141
|
|
|
$arr = array(); |
142
|
|
|
} else { |
143
|
|
|
$arr = $ret[$mimetype]; |
144
|
|
|
} |
145
|
|
|
$arr[$dataUrlLang] = $url->getURI(); |
146
|
|
|
$ret[$mimetype] = $arr; |
147
|
|
|
} else { |
148
|
|
|
$ret[$mimetype] = $url->getURI(); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
return $ret; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the main Concept Scheme URI of that Vocabulary, |
156
|
|
|
* or null if not set. |
157
|
|
|
* @return string concept scheme URI or null |
158
|
|
|
*/ |
159
|
|
|
|
160
|
|
|
public function getMainConceptSchemeURI() |
161
|
|
|
{ |
162
|
|
|
$val = $this->resource->getResource("skosmos:mainConceptScheme"); |
163
|
|
|
if ($val) { |
164
|
|
|
return $val->getURI(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return null; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Returns the class URI used for concept groups in this vocabulary, |
172
|
|
|
* or null if not set. |
173
|
|
|
* @return string group class URI or null |
174
|
|
|
*/ |
175
|
|
|
|
176
|
|
|
public function getGroupClassURI() |
177
|
|
|
{ |
178
|
|
|
$val = $this->resource->getResource("skosmos:groupClass"); |
179
|
|
|
if ($val) { |
180
|
|
|
return $val->getURI(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return null; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns the class URI used for thesaurus arrays in this vocabulary, |
188
|
|
|
* or null if not set. |
189
|
|
|
* @return string array class URI or null |
190
|
|
|
*/ |
191
|
|
|
|
192
|
|
|
public function getArrayClassURI() |
193
|
|
|
{ |
194
|
|
|
$val = $this->resource->getResource("skosmos:arrayClass"); |
195
|
|
|
if ($val) { |
196
|
|
|
return $val->getURI(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return null; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Returns custom properties displayed on the search page if configured. |
204
|
|
|
* @return string array class URI or null |
205
|
|
|
*/ |
206
|
|
|
|
207
|
|
View Code Duplication |
public function getAdditionalSearchProperties() |
|
|
|
|
208
|
|
|
{ |
209
|
|
|
$resources = $this->resource->allResources("skosmos:showPropertyInSearch"); |
210
|
|
|
$ret = array(); |
211
|
|
|
foreach ($resources as $res) { |
212
|
|
|
$prop = $res->getURI(); |
213
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible |
214
|
|
|
{ |
215
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
$ret[] = $prop; |
219
|
|
|
} |
220
|
|
|
return $ret; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Queries whether the property should be shown with all the label language variations. |
225
|
|
|
* @param string $property |
226
|
|
|
* @return boolean |
227
|
|
|
*/ |
228
|
|
|
public function hasMultiLingualProperty($property) |
229
|
|
|
{ |
230
|
|
|
$resources = $this->resource->allResources("skosmos:hasMultiLingualProperty"); |
231
|
|
|
foreach ($resources as $res) { |
232
|
|
|
$prop = $res->getURI(); |
233
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible |
234
|
|
|
{ |
235
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
if ($prop === $property) { |
239
|
|
|
return true; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
} |
243
|
|
|
return false; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Returns a boolean value set in the config.ttl config. |
248
|
|
|
* @return boolean |
249
|
|
|
*/ |
250
|
|
|
public function getShowHierarchy() |
251
|
|
|
{ |
252
|
|
|
return $this->getBoolean('skosmos:showTopConcepts'); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Returns a boolean value set in the config.ttl config. |
257
|
|
|
* @return boolean |
258
|
|
|
*/ |
259
|
|
|
public function showConceptSchemesInHierarchy() |
260
|
|
|
{ |
261
|
|
|
return $this->getBoolean('skosmos:conceptSchemesInHierarchy'); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Returns a boolean value set in the config.ttl config. |
266
|
|
|
* @return boolean defaults to true if fetching hasn't been explicitly denied. |
267
|
|
|
*/ |
268
|
|
|
public function getExternalResourcesLoading() |
269
|
|
|
{ |
270
|
|
|
return $this->getBoolean('skosmos:loadExternalResources', true); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Returns a boolean value set in the config.ttl config. |
275
|
|
|
* @return boolean |
276
|
|
|
*/ |
277
|
|
|
public function getShowLangCodes() |
278
|
|
|
{ |
279
|
|
|
return $this->getBoolean('skosmos:explicitLanguageTags'); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Returns skosmos:marcSourcecode value set in config.ttl. |
284
|
|
|
* @return string marcsource name |
285
|
|
|
*/ |
286
|
|
|
public function getMarcSourceCode($lang = null) |
287
|
|
|
{ |
288
|
|
|
return $this->getLiteral('skosmos:marcSourceCode', false, $lang); |
|
|
|
|
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Returns a boolean value set in the config.ttl config. |
293
|
|
|
* @return array array of concept class URIs (can be empty) |
294
|
|
|
*/ |
295
|
|
|
public function getIndexClasses() |
296
|
|
|
{ |
297
|
|
|
return $this->getResources("skosmos:indexShowClass"); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Returns skosmos:externalProperty values set in the config.ttl config. |
302
|
|
|
* @return array array of external property URIs (can be empty) |
303
|
|
|
*/ |
304
|
|
|
public function getExtProperties() |
305
|
|
|
{ |
306
|
|
|
return $this->getResources("skosmos:externalProperty"); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Get the languages supported by this vocabulary |
311
|
|
|
* @return array languages supported by this vocabulary (as language tag strings) |
312
|
|
|
*/ |
313
|
|
|
public function getLanguages() |
314
|
|
|
{ |
315
|
|
|
$langs = $this->resource->allLiterals('skosmos:language'); |
316
|
|
|
$ret = array(); |
317
|
|
|
foreach ($langs as $lang) { |
318
|
|
|
$langlit = Punic\Language::getName($lang->getValue(), $this->getEnvLang()); |
319
|
|
|
$ret[$langlit] = $lang->getValue(); |
320
|
|
|
} |
321
|
|
|
ksort($ret); |
322
|
|
|
|
323
|
|
|
return $ret; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Returns the vocabulary default sidebar view. |
328
|
|
|
* @return string name of the view |
329
|
|
|
*/ |
330
|
|
|
public function getDefaultSidebarView() |
331
|
|
|
{ |
332
|
|
|
$defview = $this->resource->getLiteral('skosmos:defaultSidebarView'); |
333
|
|
|
if ($defview) { |
334
|
|
|
$value = $defview->getValue(); |
335
|
|
|
if ($value === 'groups' || $value === 'hierarchy') { |
336
|
|
|
return $value; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
} |
340
|
|
|
if ($this->showAlphabeticalIndex() === false) { |
341
|
|
|
if ($this->getShowHierarchy()) { |
342
|
|
|
return 'hierarchy'; |
343
|
|
|
} else if ($this->getGroupClassURI()) { |
|
|
|
|
344
|
|
|
return 'groups'; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
return 'alphabetical'; // if not defined displaying the alphabetical index |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Extracts the vocabulary id string from the baseuri of the vocabulary. |
352
|
|
|
* @return string identifier eg. 'mesh'. |
353
|
|
|
*/ |
354
|
|
|
public function getId() |
355
|
|
|
{ |
356
|
|
|
$uriparts = explode("#", $this->resource->getURI()); |
357
|
|
|
if (count($uriparts) != 1) |
358
|
|
|
// hash namespace |
359
|
|
|
{ |
360
|
|
|
return $uriparts[1]; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
// slash namespace |
364
|
|
|
$uriparts = explode("/", $this->resource->getURI()); |
365
|
|
|
|
366
|
|
|
return $uriparts[count($uriparts) - 1]; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
public function getShowStatistics() { |
370
|
|
|
return $this->getBoolean('skosmos:showStatistics', true); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function getPlugins() |
374
|
|
|
{ |
375
|
|
|
return $this->plugins; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Returns the property/properties used for visualizing concept hierarchies. |
380
|
|
|
* @return string array class URI or null |
381
|
|
|
*/ |
382
|
|
|
|
383
|
|
View Code Duplication |
public function getHierarchyProperty() |
|
|
|
|
384
|
|
|
{ |
385
|
|
|
$resources = $this->resource->allResources("skosmos:hierarchyProperty"); |
386
|
|
|
$ret = array(); |
387
|
|
|
foreach ($resources as $res) { |
388
|
|
|
$prop = $res->getURI(); |
389
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // prefixing if possible |
390
|
|
|
{ |
391
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
$ret[] = $prop; |
395
|
|
|
} |
396
|
|
|
return empty($ret) ? array('skos:broader') : $ret; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Returns a boolean value set in the config.ttl config. |
401
|
|
|
* @return boolean |
402
|
|
|
*/ |
403
|
|
|
public function showNotation() |
404
|
|
|
{ |
405
|
|
|
return $this->getBoolean('skosmos:showNotation', true); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Returns a boolean value set in the config.ttl config. |
410
|
|
|
* @return boolean |
411
|
|
|
*/ |
412
|
|
|
public function showAlphabeticalIndex() |
413
|
|
|
{ |
414
|
|
|
return $this->getBoolean('skosmos:showAlphabeticalIndex', true); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Returns the alphabetical list qualifier in this vocabulary, |
419
|
|
|
* or null if not set. |
420
|
|
|
* @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
421
|
|
|
*/ |
422
|
|
|
public function getAlphabeticalListQualifier() |
423
|
|
|
{ |
424
|
|
|
return $this->resource->getResource('skosmos:alphabeticalListQualifier'); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* Returns a boolean value set in the config.ttl config. |
429
|
|
|
* @return boolean |
430
|
|
|
*/ |
431
|
|
|
public function getShowDeprecated() |
432
|
|
|
{ |
433
|
|
|
return $this->getBoolean('skosmos:showDeprecated', false); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
438
|
|
|
* @return array of objects or an empty array |
439
|
|
|
*/ |
440
|
|
|
public function getTypes($lang = null) |
441
|
|
|
{ |
442
|
|
|
$resources = $this->resource->allResources("dc:type"); |
443
|
|
|
$ret = array(); |
444
|
|
|
foreach ($resources as $res) { |
445
|
|
|
$prop = $res->getURI(); |
446
|
|
|
$label = $res->label($lang) ? $res->label($lang) : $res->label($this->getDefaultLanguage()); |
447
|
|
|
$ret[] = array('uri' => $prop, 'prefLabel' => $label->getValue()); |
448
|
|
|
} |
449
|
|
|
return $ret; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Returns an array of fallback languages that is ordered by priority and |
454
|
|
|
* defined in the vocabulary configuration as a collection. |
455
|
|
|
* Additionally, the chosen content language is inserted with the highest priority |
456
|
|
|
* and the vocab default language is inserted with the lowest priority. |
457
|
|
|
* @param string $clang |
458
|
|
|
* @return array of language code strings |
459
|
|
|
*/ |
460
|
|
|
public function getLanguageOrder($clang) |
461
|
|
|
{ |
462
|
|
|
if (array_key_exists($clang, $this->languageOrderCache)) { |
463
|
|
|
return $this->languageOrderCache[$clang]; |
464
|
|
|
} |
465
|
|
|
$ret = array($clang); |
466
|
|
|
$fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array(); |
467
|
|
|
foreach ($fallbacks as $lang) { |
468
|
|
|
if (!in_array($lang, $ret)) { |
469
|
|
|
$ret[] = (string)$lang; // Literal to string conversion |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
if (!in_array($this->getDefaultLanguage(), $ret)) { |
473
|
|
|
$ret[] = (string)$this->getDefaultLanguage(); |
474
|
|
|
} |
475
|
|
|
foreach ($this->getLanguages() as $lang) { |
476
|
|
|
if (!in_array($lang, $ret)) { |
477
|
|
|
$ret[] = $lang; |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
// store in cache so this doesn't have to be computed again |
481
|
|
|
$this->languageOrderCache[$clang] = $ret; |
482
|
|
|
return $ret; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Returns a boolean value set in the config.ttl config. |
487
|
|
|
* @return boolean |
488
|
|
|
*/ |
489
|
|
|
public function getUseModifiedDate(): bool |
490
|
|
|
{ |
491
|
|
|
return $this->getBoolean('skosmos:useModifiedDate', false); |
492
|
|
|
} |
493
|
|
|
} |
494
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: