VocabularyConfig::getExtProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 $globalPlugins;
9
    private $pluginRegister;
10
    private $pluginParameters = array();
11
    private $languageOrderCache = array();
12
    private $labelOverrides = array();
13
14
    public const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy",
15
    "skos:definition", "skos:broader", "isothes:broaderGeneric",
16
    "isothes:broaderPartitive", "isothes:broaderInstantial",
17
    "skos:narrower", "isothes:narrowerGeneric", "isothes:narrowerPartitive",
18
    "isothes:narrowerInstantial", "skos:related", "skos:altLabel",
19
    "skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment",
20
    "dc11:source", "dc:source", "skosmos:memberOf", "skosmos:memberOfArray");
21
22
    public const ISO25964_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy",
23
    // ISO 25964 allows placing all text fields (inc. SN and DEF) together
24
    // so we will do that, except for HN, which is clearly administrative
25
    "skos:note", "skos:scopeNote", "skos:definition", "rdfs:comment",
26
    "dc11:source", "dc:source", "skos:altLabel", "skos:broader",
27
    "isothes:broaderGeneric", "isothes:broaderPartitive",
28
    "isothes:broaderInstantial", "skos:narrower", "isothes:narrowerGeneric",
29
    "isothes:narrowerPartitive", "isothes:narrowerInstantial",
30
    "skos:related", "skos:historyNote", "skosmos:memberOf",
31
    "skosmos:memberOfArray");
32
33
    public function __construct(Model $model, EasyRdf\Resource $resource, array $globalPlugins = array())
34
    {
35
        parent::__construct($model, $resource);
36
        $this->globalPlugins = $globalPlugins;
37
        $this->setPropertyLabelOverrides();
38
        $pluginNames = $this->getPluginNames();
39
        $this->pluginRegister = new PluginRegister($pluginNames);
40
    }
41
42
    /**
43
     * Get an ordered array of plugin names with order configured in skosmos:vocabularyPlugins
44
     * @return array of plugin names
45
     */
46
    public function getPluginNames(): array
47
    {
48
        $this->pluginParameters = array();
49
        $pluginArray = array();
50
        $vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins');
51
        if (!$vocabularyPlugins instanceof EasyRdf\Collection) {
52
            $vocabularyPlugins = $this->resource->all('skosmos:vocabularyPlugins');
53
        }
54
        if ($vocabularyPlugins) {
55
            foreach ($vocabularyPlugins as $plugin) {
56
                if ($plugin instanceof EasyRdf\Literal) {
57
                    $pluginArray[] = $plugin->getValue();
58
                } else {
59
                    $pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue();
60
                    // Process parameters for parameterized plugins
61
                    $this->setPluginParametersFromResource($plugin);
62
                }
63
            }
64
        }
65
        $pluginArray = array_merge($pluginArray, $this->globalPlugins);
66
        return array_values(array_unique($pluginArray));
67
    }
68
69
    /**
70
     * Updates array of parameterized plugins adding parameter values
71
     * @param Easyrdf\Resource $pluginResource
72
     * @return void
73
     */
74
    private function setPluginParametersFromResource(Easyrdf\Resource $pluginResource): void
75
    {
76
        $pluginName = $pluginResource->getLiteral('skosmos:usePlugin')->getValue();
77
        $this->pluginParameters[$pluginName] = array();
78
79
        $pluginParams = $pluginResource->allResources('skosmos:parameters');
80
        foreach ($pluginParams as $parameter) {
81
            $paramLiterals = $parameter->allLiterals('schema:value');
82
            foreach ($paramLiterals as $paramLiteral) {
83
                $paramName = $parameter->getLiteral('schema:propertyID')->getValue();
84
                $paramValue = $paramLiteral->getValue();
85
                $paramLang = $paramLiteral->getLang();
86
                if ($paramLang) {
87
                    $paramName .= '_' . $paramLang;
88
                }
89
                $this->pluginParameters[$pluginName][$paramName] = $paramValue;
90
            }
91
        }
92
    }
93
94
95
    /**
96
     * Sets array of configured property label overrides
97
     *  @return void
98
     */
99
    private function setPropertyLabelOverrides(): void
100
    {
101
        $this->labelOverrides = array();
102
        $overrides = $this->resource->allResources('skosmos:propertyLabelOverride');
103
        if (!empty($overrides)) {
104
            foreach ($overrides as $override) {
105
                $this->setLabelOverride($override);
106
            }
107
        }
108
    }
109
110
    /**
111
     * Updates array of label overrides by adding a new override from the configuration file
112
     * @param Easyrdf\Resource $labelOverride
113
     * @return void
114
     */
115
    private function setLabelOverride(Easyrdf\Resource $override): void
116
    {
117
        $labelProperty = $override->getResource('skosmos:property');
118
        $labelPropUri = $labelProperty->shorten();
119
        if (empty($this->labelOverrides[$labelPropUri])) {
120
            $this->labelOverrides[$labelPropUri]  = array();
121
        }
122
        $newOverrides = array();
123
124
        $labels = $override->allLiterals('rdfs:label'); //property label overrides
125
        foreach ($labels as $label) {
126
            $newOverrides['label'][$label->getLang()] = $label->getValue();
127
        }
128
        $descriptions = $override->allLiterals('rdfs:comment'); //optionally override property label tooltips
129
        foreach ($descriptions as $description) {
130
            $newOverrides['description'][$description->getLang()] = $description->getValue();
131
        }
132
        $this->labelOverrides[$labelPropUri] = array_merge($newOverrides, $this->labelOverrides[$labelPropUri]);
133
    }
134
135
    /**
136
     * Get the SPARQL endpoint URL for this vocabulary
137
     *
138
     * @return string|null endpoint URL, or null if not set
139
     */
140
    public function getSparqlEndpoint()
141
    {
142
        $endpoint = $this->resource->get('void:sparqlEndpoint');
143
        if ($endpoint) {
144
            return $endpoint->getUri();
145
        }
146
        return null;
147
    }
148
149
    /**
150
     * Get the SPARQL graph URI for this vocabulary
151
     *
152
     * @return string|null graph URI, or null if not set
153
     */
154
    public function getSparqlGraph()
155
    {
156
        $graph = $this->resource->get('skosmos:sparqlGraph');
157
        if ($graph) {
158
            $graph = $graph->getUri();
159
        }
160
161
        return $graph;
162
    }
163
164
    /**
165
     * Get the SPARQL dialect for this vocabulary
166
     *
167
     * @return string|null dialect name
168
     */
169
    public function getSparqlDialect()
170
    {
171
        $dialect = $this->resource->get('skosmos:sparqlDialect');
172
        if ($dialect) {
173
            $dialect = $dialect->getValue();
174
        }
175
176
        return $dialect;
177
    }
178
179
    /**
180
     * Get the default language of this vocabulary
181
     * @return string default language, e.g. 'en'
182
     */
183
184
    public function getDefaultLanguage()
185
    {
186
        $deflang = $this->resource->getLiteral('skosmos:defaultLanguage');
187
        if ($deflang) {
0 ignored issues
show
introduced by
$deflang is of type EasyRdf\Literal, thus it always evaluated to true.
Loading history...
188
            return $deflang->getValue();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $deflang->getValue() also could return the type DateTime|boolean which is incompatible with the documented return type string.
Loading history...
189
        }
190
191
        $langs = $this->getLanguages();
192
        $deflang = reset($langs); // picking the first one from the list with reset since the keys are not numeric
193
        if (sizeof($langs) > 1) {
194
            trigger_error("Default language for vocabulary '" . $this->getShortName() . "' unknown, choosing '$deflang'.", E_USER_WARNING);
195
        }
196
197
        return $deflang;
198
    }
199
200
    /**
201
     * Returns a short name for a vocabulary if configured. If that has not been set
202
     * using vocabId as a fallback.
203
     * @return string
204
     */
205
    public function getShortName()
206
    {
207
        $shortname = $this->getLiteral('skosmos:shortName');
208
        if ($shortname) {
209
            return $shortname;
210
        }
211
212
        // if no shortname exists fall back to the id
213
        return $this->getId();
214
    }
215
216
    /**
217
     * Get the vocabulary feedback e-mail address and return it.
218
     *
219
     * @return string e-mail address or null if not defined.
220
     */
221
    public function getFeedbackRecipient()
222
    {
223
        $email = $this->resource->get('skosmos:feedbackRecipient');
224
        return isset($email) ? $email->getValue() : null;
225
    }
226
227
    /**
228
     * Returns the human readable vocabulary title.
229
     * @return string the title of the vocabulary
230
     */
231
    public function getTitle($lang = null)
232
    {
233
        $title = $this->getLiteral('dc:title', null, $lang);
234
        if ($title === null) {
0 ignored issues
show
introduced by
The condition $title === null is always false.
Loading history...
235
            // not found using given language or without language tag
236
            // try any language
237
            $literal = $this->resource->getLiteral('dc:title');
238
            if ($literal) {
239
                $title = $literal->getValue();
240
            }
241
        }
242
        return $title;
243
    }
244
245
    /**
246
     * Returns the human readable vocabulary description.
247
     * @return string the description of the vocabulary
248
     */
249
    public function getDescription($lang = null)
250
    {
251
        return $this->getLiteral('dc:description', false, $lang);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $default of BaseConfig::getLiteral(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

251
        return $this->getLiteral('dc:description', /** @scrutinizer ignore-type */ false, $lang);
Loading history...
252
    }
253
254
    /**
255
     * Returns the sorting strategy for notation codes set in the config.ttl
256
     * config: either "lexical", "natural", or null if sorting by notations is
257
     * disabled. A "true" value in the configuration file is interpreted as
258
     * "lexical".
259
     * @return string|bool
260
     */
261
    public function getSortByNotation(): ?string
262
    {
263
        $value = $this->getLiteral('skosmos:sortByNotation');
264
        if ($value == "lexical" || $value == "natural") {
265
            return $value;
266
        }
267
        // not a special value - interpret as boolean instead
268
        $bvalue = $this->getBoolean('skosmos:sortByNotation');
269
        // "true" is interpreted as "lexical"
270
        return $bvalue ? "lexical" : null;
271
    }
272
273
    /**
274
     * get the URLs from which the vocabulary data can be downloaded
275
     * @return array Array with MIME type as key, URL as value
276
     */
277
    public function getDataURLs()
278
    {
279
        $ret = array();
280
        $urls = $this->resource->allResources("void:dataDump");
281
        foreach ($urls as $url) {
282
            // first try dc:format and dc11:format
283
            $mimetypelit = $url->getLiteral('dc:format');
284
            if ($mimetypelit === null) {
285
                $mimetypelit = $url->getLiteral('dc11:format');
286
            }
287
288
            if ($mimetypelit !== null) {
289
                $mimetype = $mimetypelit->getValue();
290
            } else {
291
                $format = EasyRdf\Format::guessFormat(null, $url->getURI());
292
                if ($format === null) {
293
                    trigger_error("Could not guess format for <$url>.", E_USER_WARNING);
294
                    continue;
295
                }
296
                $mimetypes = array_keys($format->getMimeTypes());
297
                $mimetype = $mimetypes[0];
298
            }
299
300
            $langLit = $url->getLiteral('dc:language');
301
302
            if ($langLit != null) {
303
                //when the mimetype has language variants
304
                $dataUrlLang = $langLit->getValue();
305
306
                if (!isset($ret[$mimetype])) {
307
                    $arr = array();
308
                } else {
309
                    $arr = $ret[$mimetype];
310
                }
311
                $arr[$dataUrlLang] = $url->getURI();
312
                $ret[$mimetype] = $arr;
313
            } else {
314
                $ret[$mimetype] = $url->getURI();
315
            }
316
        }
317
        return $ret;
318
    }
319
320
    /**
321
     * Returns the main Concept Scheme URI of that Vocabulary,
322
     * or null if not set.
323
     * @return string concept scheme URI or null
324
     */
325
326
    public function getMainConceptSchemeURI()
327
    {
328
        $val = $this->resource->getResource("skosmos:mainConceptScheme");
329
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
330
            return $val->getURI();
331
        }
332
333
        return null;
334
    }
335
336
    /**
337
     * Returns the class URI used for concept groups in this vocabulary,
338
     * or null if not set.
339
     * @return string group class URI or null
340
     */
341
342
    public function getGroupClassURI()
343
    {
344
        $val = $this->resource->getResource("skosmos:groupClass");
345
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
346
            return $val->getURI();
347
        }
348
349
        return null;
350
    }
351
352
    /**
353
     * Returns the class URI used for thesaurus arrays in this vocabulary,
354
     * or null if not set.
355
     * @return string array class URI or null
356
     */
357
358
    public function getArrayClassURI()
359
    {
360
        $val = $this->resource->getResource("skosmos:arrayClass");
361
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
362
            return $val->getURI();
363
        }
364
365
        return null;
366
    }
367
368
    /**
369
     * Returns custom properties displayed on the search page if configured.
370
     * @return array array class URI or null
371
     */
372
373
    public function getAdditionalSearchProperties()
374
    {
375
        $resources = $this->resource->allResources("skosmos:showPropertyInSearch");
376
        $ret = array();
377
        foreach ($resources as $res) {
378
            $prop = $res->getURI();
379
            if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible
380
                $prop = EasyRdf\RdfNamespace::shorten($prop);
381
            }
382
383
            $ret[] = $prop;
384
        }
385
        return $ret;
386
    }
387
388
    /**
389
     * Queries whether the property should be shown with all the label language variations.
390
     * @param string $property
391
     * @return boolean
392
     */
393
    public function hasMultiLingualProperty($property)
394
    {
395
        $resources = $this->resource->allResources("skosmos:hasMultiLingualProperty");
396
        foreach ($resources as $res) {
397
            $prop = $res->getURI();
398
            if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible
399
                $prop = EasyRdf\RdfNamespace::shorten($prop);
400
            }
401
402
            if ($prop === $property) {
403
                return true;
404
            }
405
406
        }
407
        return false;
408
    }
409
410
    /**
411
     * Returns a boolean value set in the config.ttl config.
412
     * @return boolean
413
     */
414
    public function getShowTopConcepts()
415
    {
416
        return $this->getBoolean('skosmos:showTopConcepts');
417
    }
418
419
    /**
420
     * Returns a boolean value set in the config.ttl config.
421
     * @return boolean
422
     */
423
    public function showConceptSchemesInHierarchy()
424
    {
425
        return $this->getBoolean('skosmos:conceptSchemesInHierarchy');
426
    }
427
428
    /**
429
     * Returns a boolean value set in the config.ttl config.
430
     * @return boolean defaults to true if fetching hasn't been explicitly denied.
431
     */
432
    public function getExternalResourcesLoading()
433
    {
434
        return $this->getBoolean('skosmos:loadExternalResources', true);
435
    }
436
437
    /**
438
     * Returns a boolean value set in the config.ttl config.
439
     * @return boolean
440
     */
441
    public function getShowLangCodes()
442
    {
443
        return $this->getBoolean('skosmos:explicitLanguageTags');
444
    }
445
446
    /**
447
     * Returns a boolean value set in the config.ttl config.
448
     * @return boolean
449
     */
450
    public function searchByNotation()
451
    {
452
        return $this->getBoolean('skosmos:searchByNotation');
453
    }
454
455
    /**
456
     * Returns skosmos:marcSourcecode value set in config.ttl.
457
     * @return string marcsource name
458
     */
459
    public function getMarcSourceCode($lang = null)
460
    {
461
        return $this->getLiteral('skosmos:marcSourceCode', false, $lang);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $default of BaseConfig::getLiteral(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

461
        return $this->getLiteral('skosmos:marcSourceCode', /** @scrutinizer ignore-type */ false, $lang);
Loading history...
462
    }
463
464
    /**
465
     * Returns the boolean value of the skosmos:showNotationAsProperty setting.
466
     * @return boolean
467
     */
468
    public function getShowNotationAsProperty()
469
    {
470
        return $this->getBoolean('skosmos:showNotationAsProperty', true);
471
    }
472
473
    /**
474
     * Returns a boolean value set in the config.ttl config.
475
     * @return array array of concept class URIs (can be empty)
476
     */
477
    public function getIndexClasses()
478
    {
479
        return $this->getResources("skosmos:indexShowClass");
480
    }
481
482
    /**
483
     * Returns skosmos:externalProperty values set in the config.ttl config.
484
     * @return array array of external property URIs (can be empty)
485
     */
486
    public function getExtProperties()
487
    {
488
        return $this->getResources("skosmos:externalProperty");
489
    }
490
491
    /**
492
     * Get the languages supported by this vocabulary
493
     * @return array languages supported by this vocabulary (as language tag strings)
494
     */
495
    public function getLanguages()
496
    {
497
        $langs = $this->resource->allLiterals('skosmos:language');
498
        $ret = array();
499
        foreach ($langs as $lang) {
500
            $langlit = Punic\Language::getName($lang->getValue(), $this->getLang());
501
            $ret[$langlit] = $lang->getValue();
502
        }
503
        ksort($ret);
504
505
        return $ret;
506
    }
507
508
    /**
509
     * Returns the parameters of parameterized plugins
510
     * @return array of plugin parameters
511
     */
512
    public function getPluginParameters()
513
    {
514
        return $this->pluginParameters;
515
    }
516
517
    /**
518
     * Get the list of property label overrides
519
     * @return array of custom property labels
520
     */
521
    public function getPropertyLabelOverrides()
522
    {
523
        return $this->labelOverrides;
524
    }
525
526
    /**
527
     * Returns the vocabulary default sidebar view.
528
     * @return string name of the view
529
     */
530
    public function getDefaultSidebarView()
531
    {
532
        $defview = $this->resource->getLiteral('skosmos:defaultSidebarView');
533
        $sidebarViews = $this->getSidebarViews();
534
        if ($defview) {
0 ignored issues
show
introduced by
$defview is of type EasyRdf\Literal, thus it always evaluated to true.
Loading history...
535
            $value = $defview->getValue();
536
            if (in_array($value, $sidebarViews)) {
537
                return $value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value also could return the type DateTime|boolean which is incompatible with the documented return type string.
Loading history...
538
            } else {
539
                return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view
540
            }
541
        }
542
543
        if (in_array('alphabetical', $sidebarViews)) {
544
            return 'alphabetical'; // if not defined, displaying alphabetical index
545
        } else {
546
            return $sidebarViews[0]; // if no alphabetical index, displaying first provided view
547
        }
548
    }
549
550
    /**
551
     * Returns the concept page default sidebar view.
552
     * @return string name of the view
553
     */
554
    public function getDefaultConceptSidebarView()
555
    {
556
        $defview = $this->resource->getLiteral('skosmos:defaultConceptSidebarView');
557
        $sidebarViews = $this->getSidebarViews();
558
        if ($defview) {
0 ignored issues
show
introduced by
$defview is of type EasyRdf\Literal, thus it always evaluated to true.
Loading history...
559
            $value = $defview->getValue();
560
            if (in_array($value, $sidebarViews)) {
561
                return $value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value also could return the type DateTime|boolean which is incompatible with the documented return type string.
Loading history...
562
            } else {
563
                return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view
564
            }
565
        }
566
567
        if (in_array('hierarchy', $sidebarViews)) {
568
            return 'hierarchy'; // if not defined, displaying hierarchy
569
        } else {
570
            return $sidebarViews[0]; // if no hierarchy, displaying first provided view
571
        }
572
    }
573
574
    /**
575
     * Returns sidebar views used in this vocabulary
576
     * @return array of available views
577
     */
578
    public function getSidebarViews()
579
    {
580
        $views = $this->resource->getResource('skosmos:sidebarViews');
581
        if ($views) {
0 ignored issues
show
introduced by
$views is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
582
            $viewsArray = array();
583
            foreach ($views as $view) {
584
                if (in_array($view, array('hierarchy', 'alphabetical', 'fullalphabetical', 'changes', 'groups'))) {
585
                    $viewsArray[] = $view->getValue();
586
                }
587
            }
588
            return $viewsArray;
589
        }
590
        return array('alphabetical', 'hierarchy', 'groups', 'changes'); // if not defined, using all views in default order
591
592
    }
593
594
    /**
595
     * Extracts the vocabulary id string from the baseuri of the vocabulary.
596
     * @return string identifier eg. 'mesh'.
597
     */
598
    public function getId()
599
    {
600
        $uriparts = explode("#", $this->resource->getURI());
601
        if (count($uriparts) != 1) {
602
            // hash namespace
603
            return $uriparts[1];
604
        }
605
606
        // slash namespace
607
        $uriparts = explode("/", $this->resource->getURI());
608
609
        return $uriparts[count($uriparts) - 1];
610
    }
611
612
    public function getShowStatistics()
613
    {
614
        return $this->getBoolean('skosmos:showStatistics', true);
615
    }
616
617
    public function getPluginRegister()
618
    {
619
        return $this->pluginRegister;
620
    }
621
622
    /**
623
     * Returns the property/properties used for visualizing concept hierarchies.
624
     * @return array array class URI or null
625
     */
626
627
    public function getHierarchyProperty()
628
    {
629
        $resources = $this->resource->allResources("skosmos:hierarchyProperty");
630
        $ret = array();
631
        foreach ($resources as $res) {
632
            $prop = $res->getURI();
633
            if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // prefixing if possible
634
                $prop = EasyRdf\RdfNamespace::shorten($prop);
635
            }
636
637
            $ret[] = $prop;
638
        }
639
        return empty($ret) ? array('skos:broader') : $ret;
640
    }
641
642
    /**
643
     * Returns a boolean value set in the config.ttl config.
644
     * @return boolean
645
     */
646
    public function showNotation()
647
    {
648
        return $this->getBoolean('skosmos:showNotation', true);
649
    }
650
651
    /**
652
     * Returns the alphabetical list qualifier in this vocabulary,
653
     * or null if not set.
654
     * @return EasyRdf\Resource|null alphabetical list qualifier resource or null
655
     */
656
    public function getAlphabeticalListQualifier()
657
    {
658
        return $this->resource->getResource('skosmos:alphabeticalListQualifier');
659
    }
660
661
    /**
662
     * Returns a boolean value set in the config.ttl config.
663
     * @return boolean
664
     */
665
    public function getShowDeprecated()
666
    {
667
        return $this->getBoolean('skosmos:showDeprecated', false);
668
    }
669
670
    /**
671
     * Returns a boolean value set in the config.ttl config.
672
     * @return boolean
673
     */
674
    public function getShowDeprecatedChanges()
675
    {
676
        return $this->getBoolean('skosmos:showDeprecatedChanges', false);
677
    }
678
679
    /**
680
     * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration.
681
     * @return array of objects or an empty array
682
     */
683
    public function getTypes($lang = null)
684
    {
685
        $resources = $this->resource->allResources("dc:type");
686
        $ret = array();
687
        foreach ($resources as $res) {
688
            $prop = $res->getURI();
689
            $label = $res->label($lang) ? $res->label($lang) : $res->label($this->getDefaultLanguage());
690
            $ret[] = array('uri' => $prop, 'prefLabel' =>  $label->getValue());
691
        }
692
        return $ret;
693
    }
694
695
    /**
696
     * Returns an array of fallback languages that is ordered by priority and
697
     * defined in the vocabulary configuration as a collection.
698
     * Additionally, the chosen content language is inserted with the highest priority
699
     * and the vocab default language is inserted with the lowest priority.
700
     * @param string $clang
701
     * @return array of language code strings
702
     */
703
    public function getLanguageOrder($clang)
704
    {
705
        if (array_key_exists($clang, $this->languageOrderCache)) {
706
            return $this->languageOrderCache[$clang];
707
        }
708
        $ret = array($clang);
709
        $fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array();
710
        foreach ($fallbacks as $lang) {
711
            if (!in_array($lang, $ret)) {
712
                $ret[] = (string)$lang; // Literal to string conversion
713
            }
714
        }
715
        if (!in_array($this->getDefaultLanguage(), $ret)) {
716
            $ret[] = (string)$this->getDefaultLanguage();
717
        }
718
        foreach ($this->getLanguages() as $lang) {
719
            if (!in_array($lang, $ret)) {
720
                $ret[] = $lang;
721
            }
722
        }
723
        // store in cache so this doesn't have to be computed again
724
        $this->languageOrderCache[$clang] = $ret;
725
        return $ret;
726
    }
727
728
    /**
729
     * @return boolean
730
     */
731
    public function isUseModifiedDate()
732
    {
733
        return $this->getBoolean('skosmos:useModifiedDate', false);
734
    }
735
736
    /**
737
     * @return array
738
     */
739
    public function getPropertyOrder()
740
    {
741
        $order = $this->getResource()->getResource('skosmos:propertyOrder');
742
        if ($order === null) {
743
            return self::DEFAULT_PROPERTY_ORDER;
744
        }
745
746
        $short = EasyRdf\RdfNamespace::shorten($order);
747
        if ($short == 'skosmos:iso25964PropertyOrder') {
748
            return self::ISO25964_PROPERTY_ORDER;
749
        } elseif ($short == 'skosmos:defaultPropertyOrder') {
750
            return self::DEFAULT_PROPERTY_ORDER;
751
        }
752
753
        // check for custom order definition
754
        $orderList = $order->getResource('rdf:value');
755
        if ($orderList !== null && $orderList instanceof EasyRdf\Collection) {
756
            $ret = array();
757
            foreach ($orderList as $prop) {
758
                $short = $prop->shorten();
0 ignored issues
show
Bug introduced by
The method shorten() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

758
                /** @scrutinizer ignore-call */ 
759
                $short = $prop->shorten();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
759
                $ret[] = ($short !== null) ? $short : $prop->getURI();
760
            }
761
            return $ret;
762
        }
763
764
        trigger_error("Property order for vocabulary '{$this->getShortName()}' unknown, using default order", E_USER_WARNING);
765
        return self::DEFAULT_PROPERTY_ORDER;
766
    }
767
}
768