Completed
Push — master ( 7b7a12...52a3e6 )
by Henri
03:04
created

Concept::literalLanguageToString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2012-2013 Aalto University and University of Helsinki
4
 * MIT License
5
 * see LICENSE.txt for more information
6
 */
7
8
/**
9
 * Dataobject for a single concept.
10
 */
11
12
class Concept extends VocabularyDataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * Stores a label string if the concept has been found through
16
     * a altLabel/label in a another language than the ui.
17
     */
18
    private $foundby;
19
    /** Type of foundby match: 'alt', 'hidden' or 'lang' */
20
    private $foundbytype;
21
    /** the EasyRdf_Graph object of the concept */
22
    private $graph;
23
    private $clang;
24
25
    /** concept properties that should not be shown to users */
26
    private $DELETED_PROPERTIES = array(
27
        'skosext:broaderGeneric', # these are remnants of bad modeling
28
        'skosext:broaderPartitive', #
29
30
        'skos:hiddenLabel', # because it's supposed to be hidden
31
        'skos:prefLabel', # handled separately by getLabel
32
        'rdfs:label', # handled separately by getLabel
33
34
        'skos:topConceptOf', # because it's too technical, not relevant for users
35
        'skos:inScheme', # should be evident in any case
36
        'skos:member', # this is shouldn't be shown on the group page
37
        'dc:created', # handled separately
38
        'dc:modified', # handled separately
39
    );
40
41
    /** related concepts that should be shown to users in the appendix */
42
    private $MAPPING_PROPERTIES = array(
43
        'skos:exactMatch',
44
        'skos:narrowMatch',
45
        'skos:broadMatch',
46
        'skos:closeMatch',
47
        'skos:relatedMatch',
48
        'rdfs:seeAlso',
49
        'owl:sameAs',
50
    );
51
52
    /**
53
     * Initializing the concept object requires the following parameters.
54
     * @param Model $model
55
     * @param Vocabulary $vocab
56
     * @param EasyRdf_Resource $resource
57
     * @param EasyRdf_Graph $graph
58
     */
59
    public function __construct($model, $vocab, $resource, $graph, $clang)
60
    {
61
        parent::__construct($model, $vocab, $resource);
62
        $this->order = array("rdf:type", "dc:isReplacedBy", "skos:definition", "skos:broader", "skos:narrower", "skos:related", "skos:altLabel", "skosmos:memberOf", "skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment", "dc11:source", "dc:source", "skos:prefLabel");
63
        $this->graph = $graph;
64
        $this->clang = $clang;
65
        // setting the Punic plugins locale for localized datetime conversions
66
        if ($this->clang && $this->clang !== '') {
67
            Punic\Data::setDefaultLocale($clang);
68
        }
69
70
    }
71
72
    /**
73
     * Returns the concept uri.
74
     * @return string
75
     */
76
    public function getUri()
77
    {
78
        return $this->resource->getUri();
79
    }
80
81
    public function getType()
82
    {
83
        return $this->resource->types();
84
    }
85
86
    /**
87
     * Returns a boolean value indicating if the concept has been deprecated.
88
     * @return boolean
89
     */
90
    public function getDeprecated()
91
    {
92
        $deprecatedValue = $this->resource->getLiteral('owl:deprecated');
93
        return ($deprecatedValue !== null && filter_var($deprecatedValue->getValue(), FILTER_VALIDATE_BOOLEAN));
94
    }
95
96
    /**
97
     * Returns a label for the concept in the ui language or if not possible in any language.
98
     * @return string
99
     */
100
    public function getLabel()
101
    {
102
        $lang = $this->clang;
103
        // 1. label in current language
104
        if ($this->resource->label($lang) !== null) {
105
            return $this->resource->label($lang);
106
        }
107
108
        // 2. label in the vocabulary default language
109 View Code Duplication
        if ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
            return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage());
111
        }
112
113
        // 3. label in any language
114
        $label = $this->resource->label();
115
        // if the label lang code is a subset of the ui lang eg. en-GB
116
        if ($label !== null && strpos($label->getLang(), $this->getEnvLang() . '-') === 0) {
117
            return $label->getValue();
118
        }
119
120
        if ($label !== null) {
121
            return $label->getValue() . " (" . $label->getLang() . ")";
122
        }
123
124
        // empty
125
        return "";
126
    }
127
128
    /**
129
     * Returns a notation for the concept or null if it has not been defined.
130
     * @return string eg. '999'
131
     */
132
    public function getNotation()
133
    {
134
        $notation = $this->resource->get('skos:notation');
135
        if ($notation !== null) {
136
            return $notation->getValue();
137
        }
138
139
        return null;
140
    }
141
142
    /**
143
     * Returns the Vocabulary object or undefined if that is not available.
144
     * @return Vocabulary
145
     */
146
    public function getVocab()
147
    {
148
        return $this->vocab;
149
    }
150
151
    /**
152
     * Returns the vocabulary shortname string or id if that is not available.
153
     * @return string
154
     */
155
    public function getShortName()
156
    {
157
        return $this->vocab ? $this->vocab->getShortName() : null;
158
    }
159
160
    /**
161
     * Returns the vocabulary shortname string or id if that is not available.
162
     * @return string
163
     */
164
    public function getVocabTitle()
165
    {
166
        return $this->vocab ? $this->vocab->getTitle() : null;
167
    }
168
169
    /**
170
     * Setter for the $clang property.
171
     * @param string $clang language code eg. 'en'
172
     */
173
    public function setContentLang($clang)
174
    {
175
        $this->clang = $clang;
176
    }
177
178
    public function getContentLang()
179
    {
180
        return $this->clang;
181
    }
182
183
    /**
184
     * Setter for the $foundby property.
185
     * @param string $label label that was matched
186
     * @param string $type type of match: 'alt', 'hidden', or 'lang'
187
     */
188
    public function setFoundBy($label, $type)
189
    {
190
        $this->foundby = $label;
191
        $this->foundbytype = $type;
192
    }
193
194
    /**
195
     * Getter for the $foundby property.
196
     * @return string
197
     */
198
    public function getFoundBy()
199
    {
200
        return $this->foundby;
201
    }
202
203
    /**
204
     * Getter for the $foundbytype property.
205
     * @return string
206
     */
207
    public function getFoundByType()
208
    {
209
        return $this->foundbytype;
210
    }
211
212
    public function getMappingProperties()
213
    {
214
        $ret = array();
215
216
        $longUris = $this->resource->propertyUris();
217
        foreach ($longUris as &$prop) {
218 View Code Duplication
            if (EasyRdf_Namespace::shorten($prop) !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
                // shortening property labels if possible
220
                $prop = $sprop = EasyRdf_Namespace::shorten($prop);
221
            } else {
222
                $sprop = "<$prop>";
223
            }
224
            // EasyRdf requires full URIs to be in angle brackets
225
226
            if (in_array($prop, $this->MAPPING_PROPERTIES) && !in_array($prop, $this->DELETED_PROPERTIES)) {
227
                $propres = new EasyRdf_Resource($prop, $this->graph);
228
                $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label(); // current language
229
                $propobj = new ConceptProperty($prop, $proplabel);
230
                if ($propobj->getLabel() !== null) {
231
                    // only display properties for which we have a label
232
                    $ret[$prop] = $propobj;
233
                }
234
235
                // Iterating through every resource and adding these to the data object.
236
                foreach ($this->resource->allResources($sprop) as $val) {
237
                    if (isset($ret[$prop])) {
238
                        // checking if the target vocabulary can be found at the skosmos endpoint
239
                        $exuri = $val->getUri();
240
                        $exvoc = $this->model->guessVocabularyFromURI($exuri);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $exvoc is correct as $this->model->guessVocabularyFromURI($exuri) (which targets Model::guessVocabularyFromURI()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
241
                        // if not querying the uri itself
242
                        if (!$exvoc) {
243
                            $response = null;
244
                            // if told to do so in the vocabulary configuration
245
                            if ($this->vocab->getConfig()->getExternalResourcesLoading()) {
246
                                $response = $this->model->getResourceFromUri($exuri);
247
                            }
248
249
                            if ($response) {
250
                                $ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $response, $prop), $this->clang);
251
                                continue;
252
                            }
253
                        }
254
                        $ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
255
                    }
256
                }
257
            }
258
        }
259
260
        // sorting the properties to a order preferred in the Skosmos concept page.
261
        $ret = $this->arbitrarySort($ret);
262
263
        return $ret;
264
    }
265
266
    /**
267
     * Iterates over all the properties of the concept and returns those in an array.
268
     * @return array
269
     */
270
    public function getProperties()
271
    {
272
        $properties = array();
273
        $narrowersByUri = array();
274
        $inCollection = array();
275
        $membersArray = array();
276
        $longUris = $this->resource->propertyUris();
277
        $duplicates = array();
278
        $ret = array();
279
280
        // looking for collections and linking those with their narrower concepts
281
        if ($this->vocab->getConfig()->getArrayClassURI() !== null) {
282
            $collections = $this->graph->allOfType($this->vocab->getConfig()->getArrayClassURI());
283
            if (sizeof($collections) > 0) {
284
                // indexing the narrowers once to avoid iterating all of them with every collection
285
                foreach ($this->resource->allResources('skos:narrower') as $narrower) {
286
                    $narrowersByUri[$narrower->getUri()] = $narrower;
287
                }
288
289
                foreach ($collections as $coll) {
290
                    $currCollMembers = $this->getCollectionMembers($coll, $narrowersByUri);
291
                    foreach ($currCollMembers as $collection) {
292
                        if ($collection->getSubMembers()) {
293
                            $submembers = $collection->getSubMembers();
294
                            foreach ($submembers as $member) {
295
                                $inCollection[$member->getUri()] = true;
296
                            }
297
298
                        }
299
                    }
300
301
                    if (isset($collection) && $collection->getSubMembers()) {
302
                        $membersArray = array_merge($currCollMembers, $membersArray);
303
                    }
304
305
                }
306
                $properties['skos:narrower'] = $membersArray;
307
            }
308
        }
309
310
        foreach ($longUris as &$prop) {
311 View Code Duplication
            if (EasyRdf_Namespace::shorten($prop) !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
                // shortening property labels if possible
313
                $prop = $sprop = EasyRdf_Namespace::shorten($prop);
314
            } else {
315
                $sprop = "<$prop>";
316
            }
317
            // EasyRdf requires full URIs to be in angle brackets
318
319
            if (!in_array($prop, $this->DELETED_PROPERTIES)) {
320
                $propres = new EasyRdf_Resource($prop, $this->graph);
321
                $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
322
                $superprop = $propres->get('rdfs:subPropertyOf') ? $propres->get('rdfs:subPropertyOf')->getURI() : null;
323
                if ($superprop) {
324
                    $superprop = EasyRdf_Namespace::shorten($superprop) ? EasyRdf_Namespace::shorten($superprop) : $superprop;
325
                }
326
                $propobj = new ConceptProperty($prop, $proplabel, $superprop);
327
328
                if ($propobj->getLabel() !== null) {
329
                    // only display properties for which we have a label
330
                    $ret[$prop] = $propobj;
331
                }
332
333
                // searching for subproperties of literals too
334
                foreach ($this->graph->allResources($prop, 'rdfs:subPropertyOf') as $subi) {
335
                    $suburi = EasyRdf_Namespace::shorten($subi->getUri()) ? EasyRdf_Namespace::shorten($subi->getUri()) : $subi->getUri();
336
                    $duplicates[$suburi] = $prop;
337
                }
338
339
                // Iterating through every literal and adding these to the data object.
340
                foreach ($this->resource->allLiterals($sprop) as $val) {
341
                    $literal = new ConceptPropertyValueLiteral($val, $prop);
342
                    // only add literals when they match the content/hit language or have no language defined
343
                    if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null)) {
344
                        $ret[$prop]->addValue($literal);
345
                    }
346
347
                }
348
349
                // Iterating through every resource and adding these to the data object.
350
                foreach ($this->resource->allResources($sprop) as $val) {
351
                    // skipping narrower concepts which are already shown in a collection
352
                    if ($sprop === 'skos:narrower' && array_key_exists($val->getUri(), $inCollection)) {
353
                        continue;
354
                    }
355
356
                    // hiding rdf:type property if it's just skos:Concept
357
                    if ($sprop === 'rdf:type' && $val->shorten() === 'skos:Concept') {
358
                        continue;
359
                    }
360
361
                    // handled by getMappingProperties()
362
                    if (in_array($sprop, $this->MAPPING_PROPERTIES)) {
363
                        continue;
364
                    }
365
366 View Code Duplication
                    if (isset($ret[$prop])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367
                        $ret[$prop]->addValue(new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
368
                    }
369
370
                }
371
            }
372
        }
373
        // adding narrowers part of a collection
374
        foreach ($properties as $prop => $values) {
375
            foreach ($values as $value) {
376
                $ret[$prop]->addValue($value, $this->clang);
377
            }
378
        }
379
380
        foreach ($ret as $key => $prop) {
381
            if (sizeof($prop->getValues()) === 0) {
382
                unset($ret[$key]);
383
            }
384
        }
385
386
        $ret = $this->removeDuplicatePropertyValues($ret, $duplicates);
387
        // sorting the properties to the order preferred in the Skosmos concept page.
388
        $ret = $this->arbitrarySort($ret);
389
        return $ret;
390
    }
391
392
    /**
393
     * Removes properties that have duplicate values.
394
     * @param $ret the array of properties generated by getProperties
395
     * @param $duplicates array of properties found are a subProperty of a another property
396
     * @return array of ConceptProperties
397
     */
398
    public function removeDuplicatePropertyValues($ret, $duplicates)
399
    {
400
        $propertyValues = array();
401
402
        foreach ($ret as $prop) {
403
            foreach ($prop->getValues() as $value) {
404
                $label = $value->getLabel();
405
                $propertyValues[(method_exists($label, 'getValue')) ? $label->getValue() : $label][] = $value->getType();
406
            }
407
        }
408
409
        foreach ($propertyValues as $value => $propnames) {
410
            // if there are multiple properties with the same string value.
411
            if (count($propnames) > 1) {
412
                foreach ($propnames as $property) {
413
                    // if there is a more accurate property delete the more generic one.
414
                    if (isset($duplicates[$property])) {
415
                        unset($ret[$property]);
416
                    }
417
                }
418
419
            }
420
        }
421
        return $ret;
422
    }
423
424
    /**
425
     * Gets the creation date and modification date if available.
426
     * @return String containing the date information in a human readable format.
427
     */
428
    public function getDate()
429
    {
430
        $ret = '';
431
        $created = '';
432
        $modified = '';
433
        try {
434
            // finding the created properties
435
            if ($this->resource->get('dc:created')) {
436
                $created = $this->resource->get('dc:created')->getValue();
437
            }
438
439
            // finding the modified properties
440
            if ($this->resource->get('dc:modified')) {
441
                $modified = $this->resource->get('dc:modified')->getValue();
442
            }
443
444
            // making a human readable string from the timestamps
445
            if ($created != '') {
446
                $ret = gettext('skosmos:created') . ' ' . (Punic\Calendar::formatDate($created, 'short'));
447
            }
448
449
            if ($modified != '') {
450
                if ($created != '') {
451
                    $ret .= ', ' . gettext('skosmos:modified') . ' ' . (Punic\Calendar::formatDate($modified, 'short'));
452
                } else {
453
                    $ret .= ' ' . ucfirst(gettext('skosmos:modified')) . ' ' . (Punic\Calendar::formatDate($modified, 'short'));
454
                }
455
456
            }
457
        } catch (Exception $e) {
458
            trigger_error($e->getMessage(), E_USER_WARNING);
459
            $ret = '';
460
            if ($this->resource->get('dc:modified')) {
461
                $modified = (string) $this->resource->get('dc:modified');
462
                $ret = gettext('skosmos:modified') . ' ' . $modified; 
463
            }
464
            if ($this->resource->get('dc:created')) {
465
                $created .= (string) $this->resource->get('dc:created');
466
                $ret .= ' ' . gettext('skosmos:created') . ' ' . $created; 
467
            }
468
        }
469
        return $ret;
470
    }
471
472
    /**
473
     * Gets the members of a specific collection.
474
     * @param $coll
475
     * @param array containing all narrowers as EasyRdf_Resource
476
     * @return array containing ConceptPropertyValue objects
477
     */
478
    private function getCollectionMembers($coll, $narrowers)
479
    {
480
        $membersArray = array();
481
        $collLabel = $coll->label()->getValue($this->clang) ? $coll->label($this->clang) : $coll->label();
482
        if ($collLabel) {
483
            $collLabel = $collLabel->getValue();
484
        }
485
486
        $membersArray[$collLabel] = new ConceptPropertyValue($this->model, $this->vocab, $coll, 'skos:narrower', $this->clang);
487
        foreach ($coll->allResources('skos:member') as $member) {
488
            if (array_key_exists($member->getUri(), $narrowers)) {
489
                $narrower = $narrowers[$member->getUri()];
490 View Code Duplication
                if (isset($narrower)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
491
                    $membersArray[$collLabel]->addSubMember(new ConceptPropertyValue($this->model, $this->vocab, $narrower, 'skos:member', $this->clang), $this->clang);
492
                }
493
494
            }
495
        }
496
497
        return $membersArray;
498
    }
499
500
    /**
501
     * Gets the groups the concept belongs to.
502
     */
503
    public function getGroupProperties()
504
    {
505
        return $this->getReverseResources(false);
506
    }
507
508
    /**
509
     * Gets the groups/arrays the concept belongs to.
510
     */
511
    public function getReverseResources($includeArrays) {
512
        $groups = array();
513
        $reverseResources = $this->graph->resourcesMatching('skos:member', $this->resource);
514
        if (isset($reverseResources)) {
515
            $arrayClassURI = $this->vocab !== null ? $this->vocab->getConfig()->getArrayClassURI() : null;
516
            $arrayClass = $arrayClassURI !== null ? EasyRdf_Namespace::shorten($arrayClassURI) : null;
517
            foreach ($reverseResources as $reverseResource) {
518
                if (in_array($arrayClass, $reverseResource->types()) === $includeArrays) {
519
                    $property = in_array($arrayClass, $reverseResource->types()) ? "skosmos:memberOfArray" : "skosmos:memberOf";
520
                    $collLabel = $reverseResource->label($this->clang) ? $reverseResource->label($this->clang) : $reverseResource->label();
521
                    if ($collLabel) {
522
                        $collLabel = $collLabel->getValue();
523
                    }
524
525
                    $groups[$collLabel] = new ConceptPropertyValue($this->model, $this->vocab, $reverseResource, $property, $this->clang);
526
                    ksort($groups);
527
                    $super = $this->graph->resourcesMatching('skos:member', $reverseResource);
528
                    while (isset($super) && !empty($super)) {
529
                        foreach ($super as $res) {
530
                            $superprop = new ConceptPropertyValue($this->model, $this->vocab, $res, 'skosmos:memberOfSuper', $this->clang);
531
                            array_unshift($groups, $superprop);
532
                            $super = $this->graph->resourcesMatching('skos:member', $res);
533
                        }
534
                    }
535
                }
536
            }
537
        }
538
        return $groups;
539
    }
540
541
    public function getArrayProperties() {
542
        return $this->getReverseResources(true);
543
    }
544
545
    /**
546
     * Reads the literal language code and gets a name for it from Punic or alternatively
547
     * tries to search for a gettext translation.
548
     * @param EasyRdf_Literal $lit
549
     * @return string e.g. 'English'
550
     */
551
    private function literalLanguageToString($lit) {
552
        // using empty string as the language literal when there is no langcode set
553
        $langName = '';
554
        if ($lit->getLang()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $lit->getLang() of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
555
            $langName = Punic\Language::getName($lit->getLang(), $this->getEnvLang()) !== $lit->getLang() ? Punic\Language::getName($lit->getLang(), $this->getEnvLang()) : gettext($lit->getLang());
556
        }
557
        return $langName;
558
    }
559
560
    /**
561
     * Gets the values for the property in question in all other languages than the ui language.
562
     */
563
    public function getForeignLabels()
564
    {
565
        $labels = array();
566 View Code Duplication
        foreach ($this->resource->allLiterals('skos:prefLabel') as $lit) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
567
            // filtering away subsets of the current language eg. en vs en-GB
568
            if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
569
                $labels[$this->literalLanguageToString($lit)][] = new ConceptPropertyValueLiteral($lit, 'skos:prefLabel');
570
            }
571
        }
572 View Code Duplication
        foreach ($this->resource->allLiterals('skos:altLabel') as $lit) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
573
            // filtering away subsets of the current language eg. en vs en-GB
574
            if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
575
                $labels[$this->literalLanguageToString($lit)][] = new ConceptPropertyValueLiteral($lit, 'skos:altLabel');
576
            }
577
        }
578
        ksort($labels);
579
        return $labels;
580
    }
581
582
    /**
583
     * Gets the values for the property in question in all other languages than the ui language.
584
     * @param string $property
585
     */
586
    public function getAllLabels($property)
587
    {
588
        $labels = array();
589
        if (EasyRdf_Namespace::shorten($property) !== null) {
590
            // shortening property labels if possible
591
            $property = EasyRdf_Namespace::shorten($property);
592
        } else {
593
            $property = "<$property>";
594
        }
595
        // EasyRdf requires full URIs to be in angle brackets
596
        foreach ($this->resource->allLiterals($property) as $lit) {
597
            $labels[Punic\Language::getName($lit->getLang(), $this->getEnvLang())][] = new ConceptPropertyValueLiteral($lit, $property);
598
        }
599
        ksort($labels);
600
        return $labels;
601
    }
602
}
603