Passed
Pull Request — master (#1380)
by
unknown
04:32
created

VocabularyConfig::getResultDistinguisher()   A

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 $pluginRegister;
9
    private $pluginParameters = array();
10
    private $languageOrderCache = array();
11
    private $labelOverrides = array();
12
13
    const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy",
14
    "skos:definition", "skos:broader", "isothes:broaderGeneric",
15
    "isothes:broaderPartitive", "isothes:broaderInstantial",
16
    "skos:narrower", "isothes:narrowerGeneric", "isothes:narrowerPartitive",
17
    "isothes:narrowerInstantial", "skos:related", "skos:altLabel",
18
    "skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment",
19
    "dc11:source", "dc:source", "skosmos:memberOf", "skosmos:memberOfArray");
20
21
    const ISO25964_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy",
22
    // ISO 25964 allows placing all text fields (inc. SN and DEF) together
23
    // so we will do that, except for HN, which is clearly administrative
24
    "skos:note", "skos:scopeNote", "skos:definition", "rdfs:comment",
25
    "dc11:source", "dc:source", "skos:altLabel", "skos:broader",
26
    "isothes:broaderGeneric", "isothes:broaderPartitive",
27
    "isothes:broaderInstantial", "skos:narrower", "isothes:narrowerGeneric",
28
    "isothes:narrowerPartitive", "isothes:narrowerInstantial",
29
    "skos:related", "skos:historyNote", "skosmos:memberOf",
30
    "skosmos:memberOfArray");
31
32
    public function __construct($resource, $globalPlugins=array())
33
    {
34
        $this->resource = $resource;
35
        $this->globalPlugins = $globalPlugins;
0 ignored issues
show
Bug Best Practice introduced by
The property globalPlugins does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
        $this->setPropertyLabelOverrides();
37
        $pluginArray = $this->getPluginArray();
38
        $this->pluginRegister = new PluginRegister($pluginArray);
39
    }
40
41
    /**
42
     * Get an ordered array of plugin names with order configured in skosmos:vocabularyPlugins
43
     * @return array of plugin names
44
     */
45
    public function getPluginArray() : array
46
    {
47
        $this->setParameterizedPlugins();
48
        $pluginArray = array();
49
        $vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins');
50
        if (!$vocabularyPlugins instanceof EasyRdf\Collection) {
51
            $vocabularyPlugins = $this->resource->all('skosmos:vocabularyPlugins');
52
        }
53
        if ($vocabularyPlugins) {
54
            foreach ($vocabularyPlugins as $plugin) {
55
                if ($plugin instanceof EasyRdf\Literal) {
56
                    $pluginArray[] = $plugin->getValue();
57
                }
58
                else {
59
                    $pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue();
60
                }
61
            }
62
        }
63
        $pluginArray = array_merge($pluginArray, $this->globalPlugins);
64
65
        $paramPlugins = $this->resource->allResources('skosmos:useParamPlugin');
66
        if ($paramPlugins) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $paramPlugins of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
67
            foreach ($paramPlugins as $plugin) {
68
                $pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue();
69
            }
70
        }
71
        $plugins = $this->resource->allLiterals('skosmos:usePlugin');
72
        if ($plugins) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $plugins of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
73
            foreach ($plugins as $pluginlit) {
74
                $pluginArray[] = $pluginlit->getValue();
75
            }
76
        }
77
        return array_values(array_unique($pluginArray));
78
    }
79
80
    /**
81
     * Sets array of parameterized plugins
82
     * @return void
83
     */
84
    private function setParameterizedPlugins() : void
85
    {
86
        $this->pluginParameters = array();
87
88
        $vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins');
89
        if (!$vocabularyPlugins instanceof EasyRdf\Collection) {
90
            $vocabularyPlugins = $this->resource->all('skosmos:vocabularyPlugins');
91
        }
92
        if ($vocabularyPlugins) {
93
            foreach ($vocabularyPlugins as $plugin) {
94
                if ($plugin instanceof EasyRdf\Resource) {
95
                    $this->setPluginParameters($plugin);
96
                }
97
            }
98
        }
99
        $pluginResources = $this->resource->allResources('skosmos:useParamPlugin');
100
        if ($pluginResources) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pluginResources of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
101
            foreach ($pluginResources as $pluginResource) {
102
                $this->setPluginParameters($pluginResource);
103
            }
104
        }
105
    }
106
107
    /**
108
     * Updates array of parameterized plugins adding parameter values
109
     * @param Easyrdf\Resource $pluginResource
110
     * @return void
111
     */
112
    private function setPluginParameters(Easyrdf\Resource $pluginResource) : void
113
    {
114
        $pluginName = $pluginResource->getLiteral('skosmos:usePlugin')->getValue();
115
        $this->pluginParameters[$pluginName] = array();
116
117
        $pluginParams = $pluginResource->allResources('skosmos:parameters');
118
        foreach ($pluginParams as $parameter) {
119
120
            $paramLiterals = $parameter->allLiterals('schema:value');
121
            foreach ($paramLiterals as $paramLiteral) {
122
                $paramName = $parameter->getLiteral('schema:propertyID')->getValue();
123
                $paramValue = $paramLiteral->getValue();
124
                $paramLang = $paramLiteral->getLang();
125
                if ($paramLang) {
126
                    $paramName .= '_' . $paramLang;
127
                }
128
                $this->pluginParameters[$pluginName][$paramName] = $paramValue;
129
            }
130
        }
131
    }
132
133
    /**
134
     * Sets array of configured property label overrides
135
     *  @return void
136
     */
137
    private function setPropertyLabelOverrides() : void
138
    {
139
        $this->labelOverrides = array();
140
        $overrides = $this->resource->allResources('skosmos:propertyLabelOverride');
141
        if (!empty($overrides)) {
142
            foreach ($overrides as $override) {
143
                $this->setLabelOverride($override);
144
            }
145
        }
146
    }
147
148
    /**
149
     * Updates array of label overrides by adding a new override from the configuration file
150
     * @param Easyrdf\Resource $labelOverride
151
     * @return void
152
     */
153
    private function setLabelOverride(Easyrdf\Resource $override) : void
154
    {
155
        $labelProperty = $override->getResource('skosmos:property');
156
        $labelPropUri = $labelProperty->shorten();
157
        if (empty($this->labelOverrides[$labelPropUri])) {
158
            $this->labelOverrides[$labelPropUri]  = array();
159
        }
160
        $newOverrides = array();
161
162
        $labels = $override->allLiterals('rdfs:label'); //property label overrides
163
        foreach ($labels as $label) {
164
            $newOverrides['label'][$label->getLang()] = $label->getValue();
165
        }
166
        $descriptions = $override->allLiterals('rdfs:comment'); //optionally override property label tooltips
167
        foreach ($descriptions as $description) {
168
             $newOverrides['description'][$description->getLang()] = $description->getValue();
169
        }
170
        $this->labelOverrides[$labelPropUri] = array_merge($newOverrides, $this->labelOverrides[$labelPropUri]);
171
    }
172
173
    /**
174
     * Get the SPARQL endpoint URL for this vocabulary
175
     *
176
     * @return string|null endpoint URL, or null if not set
177
     */
178
    public function getSparqlEndpoint()
179
    {
180
        $endpoint = $this->resource->get('void:sparqlEndpoint');
181
        if ($endpoint) {
182
            return $endpoint->getUri();
183
        }
184
        return null;
185
    }
186
187
    /**
188
     * Get the SPARQL graph URI for this vocabulary
189
     *
190
     * @return string|null graph URI, or null if not set
191
     */
192
    public function getSparqlGraph()
193
    {
194
        $graph = $this->resource->get('skosmos:sparqlGraph');
195
        if ($graph) {
196
            $graph = $graph->getUri();
197
        }
198
199
        return $graph;
200
    }
201
202
    /**
203
     * Get the SPARQL dialect for this vocabulary
204
     *
205
     * @return string|null dialect name
206
     */
207
    public function getSparqlDialect()
208
    {
209
        $dialect = $this->resource->get('skosmos:sparqlDialect');
210
        if ($dialect) {
211
            $dialect = $dialect->getValue();
212
        }
213
214
        return $dialect;
215
    }
216
217
    /**
218
     * Get the default language of this vocabulary
219
     * @return string default language, e.g. 'en'
220
     */
221
222
    public function getDefaultLanguage()
223
    {
224
        $deflang = $this->resource->getLiteral('skosmos:defaultLanguage');
225
        if ($deflang) {
0 ignored issues
show
introduced by
$deflang is of type EasyRdf\Literal, thus it always evaluated to true.
Loading history...
226
            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...
227
        }
228
229
        $langs = $this->getLanguages();
230
        $deflang = reset($langs); // picking the first one from the list with reset since the keys are not numeric
231
        if (sizeof($langs) > 1) {
232
            trigger_error("Default language for vocabulary '" . $this->getShortName() . "' unknown, choosing '$deflang'.", E_USER_WARNING);
233
        }
234
235
        return $deflang;
236
    }
237
238
    /**
239
     * Whether the alphabetical index is small enough to be shown all at once.
240
     * @return boolean true if all concepts can be shown at once.
241
     */
242
    public function getAlphabeticalFull()
243
    {
244
        return $this->getBoolean('skosmos:fullAlphabeticalIndex');
245
    }
246
247
    /**
248
     * Returns a short name for a vocabulary if configured. If that has not been set
249
     * using vocabId as a fallback.
250
     * @return string
251
     */
252
    public function getShortName()
253
    {
254
        $shortname = $this->getLiteral('skosmos:shortName');
255
        if ($shortname)
256
          return $shortname;
257
258
        // if no shortname exists fall back to the id
259
        return $this->getId();
260
    }
261
262
    /**
263
     * Get the vocabulary feedback e-mail address and return it.
264
     *
265
     * @return string e-mail address or null if not defined.
266
     */
267
    public function getFeedbackRecipient()
268
    {
269
        $email = $this->resource->get('skosmos:feedbackRecipient');
270
        return isset($email) ? $email->getValue() : null;
271
    }
272
273
    /**
274
     * Returns the human readable vocabulary title.
275
     * @return string the title of the vocabulary
276
     */
277
    public function getTitle($lang = null)
278
    {
279
        return $this->getLiteral('dc:title', 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

279
        return $this->getLiteral('dc:title', /** @scrutinizer ignore-type */ false, $lang);
Loading history...
280
    }
281
282
    /**
283
     * Returns the sorting strategy for notation codes set in the config.ttl
284
     * config: either "lexical", "natural", or null if sorting by notations is 
285
     * disabled. A "true" value in the configuration file is interpreted as
286
     * "lexical".
287
     * @return string|bool
288
     */
289
    public function getSortByNotation(): ?string
290
    {
291
        $value = $this->getLiteral('skosmos:sortByNotation');
292
        if ($value == "lexical" || $value == "natural") {
293
            return $value;
294
        }
295
        // not a special value - interpret as boolean instead
296
        $bvalue = $this->getBoolean('skosmos:sortByNotation');
297
        // "true" is interpreted as "lexical"
298
        return $bvalue ? "lexical" : null;
299
    }
300
301
    /**
302
     * Returns a boolean value set in the config.ttl config.
303
     * @return boolean
304
     */
305
    public function showChangeList()
306
    {
307
        return $this->getBoolean('skosmos:showChangeList');
308
    }
309
310
    /**
311
     * get the URLs from which the vocabulary data can be downloaded
312
     * @return array Array with MIME type as key, URL as value
313
     */
314
    public function getDataURLs()
315
    {
316
        $ret = array();
317
        $urls = $this->resource->allResources("void:dataDump");
318
        foreach ($urls as $url) {
319
            // first try dc:format and dc11:format
320
            $mimetypelit = $url->getLiteral('dc:format');
321
            if ($mimetypelit === null) {
322
                $mimetypelit = $url->getLiteral('dc11:format');
323
            }
324
325
            if ($mimetypelit !== null) {
326
                $mimetype = $mimetypelit->getValue();
327
            } else {
328
                $format = EasyRdf\Format::guessFormat(null, $url->getURI());
329
                if ($format === null) {
330
                    trigger_error("Could not guess format for <$url>.", E_USER_WARNING);
331
                    continue;
332
                }
333
                $mimetypes = array_keys($format->getMimeTypes());
334
                $mimetype = $mimetypes[0];
335
            }
336
337
            $langLit = $url->getLiteral('dc:language');
338
339
            if ($langLit != null) {
340
                //when the mimetype has language variants
341
                $dataUrlLang = $langLit->getValue();
342
343
                if (!isset($ret[$mimetype])) {
344
                  $arr = array();
345
                } else {
346
                  $arr = $ret[$mimetype];
347
                }
348
                $arr[$dataUrlLang] = $url->getURI();
349
                $ret[$mimetype] = $arr;
350
            } else {
351
                $ret[$mimetype] = $url->getURI();
352
            }
353
        }
354
        return $ret;
355
    }
356
357
    /**
358
     * Returns the main Concept Scheme URI of that Vocabulary,
359
     * or null if not set.
360
     * @return string concept scheme URI or null
361
     */
362
363
    public function getMainConceptSchemeURI()
364
    {
365
        $val = $this->resource->getResource("skosmos:mainConceptScheme");
366
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
367
            return $val->getURI();
368
        }
369
370
        return null;
371
    }
372
373
    /**
374
     * Returns the class URI used for concept groups in this vocabulary,
375
     * or null if not set.
376
     * @return string group class URI or null
377
     */
378
379
    public function getGroupClassURI()
380
    {
381
        $val = $this->resource->getResource("skosmos:groupClass");
382
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
383
            return $val->getURI();
384
        }
385
386
        return null;
387
    }
388
389
    /**
390
     * Returns the class URI used for thesaurus arrays in this vocabulary,
391
     * or null if not set.
392
     * @return string array class URI or null
393
     */
394
395
    public function getArrayClassURI()
396
    {
397
        $val = $this->resource->getResource("skosmos:arrayClass");
398
        if ($val) {
0 ignored issues
show
introduced by
$val is of type EasyRdf\Resource, thus it always evaluated to true.
Loading history...
399
            return $val->getURI();
400
        }
401
402
        return null;
403
    }
404
405
    /**
406
     * Returns custom properties displayed on the search page if configured.
407
     * @return array array class URI or null
408
     */
409
410
    public function getAdditionalSearchProperties()
411
    {
412
        $resources = $this->resource->allResources("skosmos:showPropertyInSearch");
413
        $ret = array();
414
        foreach ($resources as $res) {
415
            $prop = $res->getURI();
416
            if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible
417
            {
418
                $prop = EasyRdf\RdfNamespace::shorten($prop);
419
            }
420
421
            $ret[] = $prop;
422
        }
423
        return $ret;
424
    }
425
426
    /**
427
     * Returns the result distinguisher property path in case of a shared prefLabel for this vocabulary,
428
     * or null if not set.
429
     * @return string Result distinguisher property path or null
430
     */
431
    public function getResultDistinguisher()
432
    {
433
        return $this->getLiteral("skosmos:resultDistinguisher");
434
    }
435
436
    /**
437
     * Queries whether the property should be shown with all the label language variations.
438
     * @param string $property
439
     * @return boolean
440
     */
441
    public function hasMultiLingualProperty($property)
442
    {
443
        $resources = $this->resource->allResources("skosmos:hasMultiLingualProperty");
444
        foreach ($resources as $res) {
445
            $prop = $res->getURI();
446
            if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible
447
            {
448
                $prop = EasyRdf\RdfNamespace::shorten($prop);
449
            }
450
451
            if ($prop === $property) {
452
                return true;
453
            }
454
455
        }
456
        return false;
457
    }
458
459
    /**
460
     * Returns a boolean value set in the config.ttl config.
461
     * @return boolean
462
     */
463
    public function getShowHierarchy()
464
    {
465
        return $this->getBoolean('skosmos:showTopConcepts');
466
    }
467
468
    /**
469
     * Returns a boolean value set in the config.ttl config.
470
     * @return boolean
471
     */
472
    public function showConceptSchemesInHierarchy()
473
    {
474
        return $this->getBoolean('skosmos:conceptSchemesInHierarchy');
475
    }
476
477
    /**
478
     * Returns a boolean value set in the config.ttl config.
479
     * @return boolean defaults to true if fetching hasn't been explicitly denied.
480
     */
481
    public function getExternalResourcesLoading()
482
    {
483
        return $this->getBoolean('skosmos:loadExternalResources', true);
484
    }
485
486
    /**
487
     * Returns a boolean value set in the config.ttl config.
488
     * @return boolean
489
     */
490
    public function getShowLangCodes()
491
    {
492
        return $this->getBoolean('skosmos:explicitLanguageTags');
493
    }
494
495
    /**
496
     * Returns a boolean value set in the config.ttl config.
497
     * @return boolean
498
     */
499
    public function searchByNotation()
500
    {
501
        return $this->getBoolean('skosmos:searchByNotation');
502
    }
503
504
    /**
505
     * Returns skosmos:marcSourcecode value set in config.ttl.
506
     * @return string marcsource name
507
     */
508
    public function getMarcSourceCode($lang = null)
509
    {
510
        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

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

771
                /** @scrutinizer ignore-call */ 
772
                $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...
772
                $ret[] = ($short !== null) ? $short : $prop->getURI();
773
            }
774
            return $ret;
775
        }
776
        
777
        trigger_error("Property order for vocabulary '{$this->getShortName()}' unknown, using default order", E_USER_WARNING);
778
        return self::DEFAULT_PROPERTY_ORDER;
779
    }
780
}
781