Completed
Push — master ( bdfb26...7cc740 )
by Henri
03:07
created

Concept::isGroup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
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 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
    /**
88
     * Returns a boolean value indicating whether the resource is a group defined in the vocab config as skosmos:groupClass.
89
     * @return boolean
90
     */
91
    public function isGroup() {
92
        $groupClass = $this->getVocab()->getConfig()->getGroupClassURI();
93
        if ($groupClass) {
94
            $groupClass = EasyRdf_Namespace::shorten($groupClass) !== null ? EasyRdf_Namespace::shorten($groupClass) : $groupClass;
95
            return in_array($groupClass, $this->getType());
96
        }
97
        return false;
98
    }
99
100
    /**
101
     * Returns a boolean value indicating if the concept has been deprecated.
102
     * @return boolean
103
     */
104
    public function getDeprecated()
105
    {
106
        $deprecatedValue = $this->resource->getLiteral('owl:deprecated');
107
        return ($deprecatedValue !== null && filter_var($deprecatedValue->getValue(), FILTER_VALIDATE_BOOLEAN));
108
    }
109
110
    /**
111
     * Returns a label for the concept in the ui language or if not possible in any language.
112
     * @return string
113
     */
114
    public function getLabel()
115
    {
116
        $lang = $this->clang;
117
        // 1. label in current language
118
        if ($this->resource->label($lang) !== null) {
119
            return $this->resource->label($lang);
120
        }
121
122
        // 2. label in the vocabulary default language
123 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...
124
            return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage());
125
        }
126
127
        // 3. label in any language
128
        $label = $this->resource->label();
129
        // if the label lang code is a subset of the ui lang eg. en-GB
130
        if ($label !== null && strpos($label->getLang(), $this->getEnvLang() . '-') === 0) {
131
            return $label->getValue();
132
        }
133
134
        if ($label !== null) {
135
            return $label->getValue() . " (" . $label->getLang() . ")";
136
        }
137
138
        // empty
139
        return "";
140
    }
141
142
    /**
143
     * Returns a notation for the concept or null if it has not been defined.
144
     * @return string eg. '999'
145
     */
146
    public function getNotation()
147
    {
148
        $notation = $this->resource->get('skos:notation');
149
        if ($this->vocab->getConfig()->showNotation() && $notation !== null) {
150
            return $notation->getValue();
151
        }
152
153
        return null;
154
    }
155
156
    /**
157
     * Returns the Vocabulary object or undefined if that is not available.
158
     * @return Vocabulary
159
     */
160
    public function getVocab()
161
    {
162
        return $this->vocab;
163
    }
164
165
    /**
166
     * Returns the vocabulary shortname string or id if that is not available.
167
     * @return string
168
     */
169
    public function getShortName()
170
    {
171
        return $this->vocab ? $this->vocab->getShortName() : null;
172
    }
173
174
    /**
175
     * Returns the vocabulary shortname string or id if that is not available.
176
     * @return string
177
     */
178
    public function getVocabTitle()
179
    {
180
        return $this->vocab ? $this->vocab->getTitle() : null;
181
    }
182
183
    /**
184
     * Setter for the $clang property.
185
     * @param string $clang language code eg. 'en'
186
     */
187
    public function setContentLang($clang)
188
    {
189
        $this->clang = $clang;
190
    }
191
192
    public function getContentLang()
193
    {
194
        return $this->clang;
195
    }
196
197
    /**
198
     * Setter for the $foundby property.
199
     * @param string $label label that was matched
200
     * @param string $type type of match: 'alt', 'hidden', or 'lang'
201
     */
202
    public function setFoundBy($label, $type)
203
    {
204
        $this->foundby = $label;
205
        $this->foundbytype = $type;
206
    }
207
208
    /**
209
     * Getter for the $foundby property.
210
     * @return string
211
     */
212
    public function getFoundBy()
213
    {
214
        return $this->foundby;
215
    }
216
217
    /**
218
     * Getter for the $foundbytype property.
219
     * @return string
220
     */
221
    public function getFoundByType()
222
    {
223
        return $this->foundbytype;
224
    }
225
226
    public function getMappingProperties()
227
    {
228
        $ret = array();
229
230
        $longUris = $this->resource->propertyUris();
231
        foreach ($longUris as &$prop) {
232 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...
233
                // shortening property labels if possible
234
                $prop = $sprop = EasyRdf_Namespace::shorten($prop);
235
            } else {
236
                $sprop = "<$prop>";
237
            }
238
            // EasyRdf requires full URIs to be in angle brackets
239
240
            if (in_array($prop, $this->MAPPING_PROPERTIES) && !in_array($prop, $this->DELETED_PROPERTIES)) {
241
                $propres = new EasyRdf_Resource($prop, $this->graph);
242
                $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label(); // current language
243
                $propobj = new ConceptProperty($prop, $proplabel);
244
                if ($propobj->getLabel() !== null) {
245
                    // only display properties for which we have a label
246
                    $ret[$prop] = $propobj;
247
                }
248
249
                // Iterating through every resource and adding these to the data object.
250
                foreach ($this->resource->allResources($sprop) as $val) {
251
                    if (isset($ret[$prop])) {
252
                        // checking if the target vocabulary can be found at the skosmos endpoint
253
                        $exuri = $val->getUri();
254
                        $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...
255
                        // if not querying the uri itself
256
                        if (!$exvoc) {
257
                            $response = null;
258
                            // if told to do so in the vocabulary configuration
259
                            if ($this->vocab->getConfig()->getExternalResourcesLoading()) {
260
                                $response = $this->model->getResourceFromUri($exuri);
261
                            }
262
263
                            if ($response) {
264
                                $ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $response, $prop), $this->clang);
265
                                continue;
266
                            }
267
                        }
268
                        $ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
269
                    }
270
                }
271
            }
272
        }
273
274
        // sorting the properties to a order preferred in the Skosmos concept page.
275
        $ret = $this->arbitrarySort($ret);
276
277
        return $ret;
278
    }
279
280
    /**
281
     * Iterates over all the properties of the concept and returns those in an array.
282
     * @return array
283
     */
284
    public function getProperties()
285
    {
286
        $properties = array();
287
        $narrowersByUri = array();
288
        $inCollection = array();
289
        $membersArray = array();
290
        $longUris = $this->resource->propertyUris();
291
        $duplicates = array();
292
        $ret = array();
293
294
        // looking for collections and linking those with their narrower concepts
295
        if ($this->vocab->getConfig()->getArrayClassURI() !== null) {
296
            $collections = $this->graph->allOfType($this->vocab->getConfig()->getArrayClassURI());
297
            if (sizeof($collections) > 0) {
298
                // indexing the narrowers once to avoid iterating all of them with every collection
299
                foreach ($this->resource->allResources('skos:narrower') as $narrower) {
300
                    $narrowersByUri[$narrower->getUri()] = $narrower;
301
                }
302
303
                foreach ($collections as $coll) {
304
                    $currCollMembers = $this->getCollectionMembers($coll, $narrowersByUri);
305
                    foreach ($currCollMembers as $collection) {
306
                        if ($collection->getSubMembers()) {
307
                            $submembers = $collection->getSubMembers();
308
                            foreach ($submembers as $member) {
309
                                $inCollection[$member->getUri()] = true;
310
                            }
311
312
                        }
313
                    }
314
315
                    if (isset($collection) && $collection->getSubMembers()) {
316
                        $membersArray = array_merge($currCollMembers, $membersArray);
317
                    }
318
319
                }
320
                $properties['skos:narrower'] = $membersArray;
321
            }
322
        }
323
324
        foreach ($longUris as &$prop) {
325 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...
326
                // shortening property labels if possible
327
                $prop = $sprop = EasyRdf_Namespace::shorten($prop);
328
            } else {
329
                $sprop = "<$prop>";
330
            }
331
            // EasyRdf requires full URIs to be in angle brackets
332
333
            if (!in_array($prop, $this->DELETED_PROPERTIES) || ($this->isGroup() === false && $prop === 'skos:member')) {
334
                $propres = new EasyRdf_Resource($prop, $this->graph);
335
                $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
336
                $superprop = $propres->get('rdfs:subPropertyOf') ? $propres->get('rdfs:subPropertyOf')->getURI() : null;
337
                if ($superprop) {
338
                    $superprop = EasyRdf_Namespace::shorten($superprop) ? EasyRdf_Namespace::shorten($superprop) : $superprop;
339
                }
340
                $propobj = new ConceptProperty($prop, $proplabel, $superprop);
341
342
                if ($propobj->getLabel() !== null) {
343
                    // only display properties for which we have a label
344
                    $ret[$prop] = $propobj;
345
                }
346
347
                // searching for subproperties of literals too
348
                foreach ($this->graph->allResources($prop, 'rdfs:subPropertyOf') as $subi) {
349
                    $suburi = EasyRdf_Namespace::shorten($subi->getUri()) ? EasyRdf_Namespace::shorten($subi->getUri()) : $subi->getUri();
350
                    $duplicates[$suburi] = $prop;
351
                }
352
353
                // Iterating through every literal and adding these to the data object.
354
                foreach ($this->resource->allLiterals($sprop) as $val) {
355
                    $literal = new ConceptPropertyValueLiteral($val, $prop);
356
                    // only add literals when they match the content/hit language or have no language defined
357
                    if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null)) {
358
                        $ret[$prop]->addValue($literal);
359
                    }
360
361
                }
362
363
                // Iterating through every resource and adding these to the data object.
364
                foreach ($this->resource->allResources($sprop) as $val) {
365
                    // skipping narrower concepts which are already shown in a collection
366
                    if ($sprop === 'skos:narrower' && array_key_exists($val->getUri(), $inCollection)) {
367
                        continue;
368
                    }
369
370
                    // hiding rdf:type property if it's just skos:Concept
371
                    if ($sprop === 'rdf:type' && $val->shorten() === 'skos:Concept') {
372
                        continue;
373
                    }
374
375
                    // handled by getMappingProperties()
376
                    if (in_array($sprop, $this->MAPPING_PROPERTIES)) {
377
                        continue;
378
                    }
379
380 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...
381
                        $ret[$prop]->addValue(new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
382
                    }
383
384
                }
385
            }
386
        }
387
        // adding narrowers part of a collection
388
        foreach ($properties as $prop => $values) {
389
            foreach ($values as $value) {
390
                $ret[$prop]->addValue($value, $this->clang);
391
            }
392
        }
393
394
        foreach ($ret as $key => $prop) {
395
            if (sizeof($prop->getValues()) === 0) {
396
                unset($ret[$key]);
397
            }
398
        }
399
400
        $ret = $this->removeDuplicatePropertyValues($ret, $duplicates);
401
        // sorting the properties to the order preferred in the Skosmos concept page.
402
        $ret = $this->arbitrarySort($ret);
403
        return $ret;
404
    }
405
406
    /**
407
     * Removes properties that have duplicate values.
408
     * @param $ret the array of properties generated by getProperties
409
     * @param $duplicates array of properties found are a subProperty of a another property
410
     * @return array of ConceptProperties
411
     */
412
    public function removeDuplicatePropertyValues($ret, $duplicates)
413
    {
414
        $propertyValues = array();
415
416
        foreach ($ret as $prop) {
417
            foreach ($prop->getValues() as $value) {
418
                $label = $value->getLabel();
419
                $propertyValues[(method_exists($label, 'getValue')) ? $label->getValue() : $label][] = $value->getType();
420
            }
421
        }
422
423
        foreach ($propertyValues as $value => $propnames) {
424
            // if there are multiple properties with the same string value.
425
            if (count($propnames) > 1) {
426
                foreach ($propnames as $property) {
427
                    // if there is a more accurate property delete the more generic one.
428
                    if (isset($duplicates[$property])) {
429
                        unset($ret[$property]);
430
                    }
431
                }
432
433
            }
434
        }
435
        return $ret;
436
    }
437
438
    /**
439
     * Gets the creation date and modification date if available.
440
     * @return String containing the date information in a human readable format.
441
     */
442
    public function getDate()
443
    {
444
        $ret = '';
445
        $created = '';
446
        $modified = '';
447
        try {
448
            // finding the created properties
449
            if ($this->resource->get('dc:created')) {
450
                $created = $this->resource->get('dc:created')->getValue();
451
            }
452
453
            // finding the modified properties
454
            if ($this->resource->get('dc:modified')) {
455
                $modified = $this->resource->get('dc:modified')->getValue();
456
            }
457
458
            // making a human readable string from the timestamps
459
            if ($created != '') {
460
                $ret = gettext('skosmos:created') . ' ' . (Punic\Calendar::formatDate($created, 'short'));
461
            }
462
463
            if ($modified != '') {
464
                if ($created != '') {
465
                    $ret .= ', ' . gettext('skosmos:modified') . ' ' . (Punic\Calendar::formatDate($modified, 'short'));
466
                } else {
467
                    $ret .= ' ' . ucfirst(gettext('skosmos:modified')) . ' ' . (Punic\Calendar::formatDate($modified, 'short'));
468
                }
469
470
            }
471
        } catch (Exception $e) {
472
            trigger_error($e->getMessage(), E_USER_WARNING);
473
            $ret = '';
474
            if ($this->resource->get('dc:modified')) {
475
                $modified = (string) $this->resource->get('dc:modified');
476
                $ret = gettext('skosmos:modified') . ' ' . $modified; 
477
            }
478
            if ($this->resource->get('dc:created')) {
479
                $created .= (string) $this->resource->get('dc:created');
480
                $ret .= ' ' . gettext('skosmos:created') . ' ' . $created; 
481
            }
482
        }
483
        return $ret;
484
    }
485
486
    /**
487
     * Gets the members of a specific collection.
488
     * @param $coll
489
     * @param array containing all narrowers as EasyRdf_Resource
490
     * @return array containing ConceptPropertyValue objects
491
     */
492
    private function getCollectionMembers($coll, $narrowers)
493
    {
494
        $membersArray = array();
495
        $collLabel = $coll->label()->getValue($this->clang) ? $coll->label($this->clang) : $coll->label();
496
        if ($collLabel) {
497
            $collLabel = $collLabel->getValue();
498
        }
499
500
        $membersArray[$collLabel] = new ConceptPropertyValue($this->model, $this->vocab, $coll, 'skos:narrower', $this->clang);
501
        foreach ($coll->allResources('skos:member') as $member) {
502
            if (array_key_exists($member->getUri(), $narrowers)) {
503
                $narrower = $narrowers[$member->getUri()];
504 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...
505
                    $membersArray[$collLabel]->addSubMember(new ConceptPropertyValue($this->model, $this->vocab, $narrower, 'skos:member', $this->clang), $this->clang);
506
                }
507
508
            }
509
        }
510
511
        return $membersArray;
512
    }
513
514
    /**
515
     * Gets the groups the concept belongs to.
516
     */
517
    public function getGroupProperties()
518
    {
519
        return $this->getReverseResources(false);
520
    }
521
522
    /**
523
     * Gets the groups/arrays the concept belongs to.
524
     */
525
    public function getReverseResources($includeArrays) {
526
        $groups = array();
527
        $reverseResources = $this->graph->resourcesMatching('skos:member', $this->resource);
528
        if (isset($reverseResources)) {
529
            $arrayClassURI = $this->vocab !== null ? $this->vocab->getConfig()->getArrayClassURI() : null;
530
            $arrayClass = $arrayClassURI !== null ? EasyRdf_Namespace::shorten($arrayClassURI) : null;
531
            $superGroups = $this->resource->all('isothes:superGroup');
532
            $superGroupUris = array_map(function($obj) { return $obj->getUri(); }, $superGroups);
533
            foreach ($reverseResources as $reverseResource) {
534
                if (in_array($arrayClass, $reverseResource->types()) === $includeArrays) {
535
                    // not adding the memberOf if the reverse resource is already covered by isothes:superGroup see issue #433
536
                    if (in_array($reverseResource->getUri(), $superGroupUris)) {
537
                        continue;
538
                    }
539
                    $property = in_array($arrayClass, $reverseResource->types()) ? "skosmos:memberOfArray" : "skosmos:memberOf";
540
                    $collLabel = $reverseResource->label($this->clang) ? $reverseResource->label($this->clang) : $reverseResource->label();
541
                    if ($collLabel) {
542
                        $collLabel = $collLabel->getValue();
543
                    }
544
545
                    $groups[$collLabel] = new ConceptPropertyValue($this->model, $this->vocab, $reverseResource, $property, $this->clang);
546
                    ksort($groups);
547
                    $super = $this->graph->resourcesMatching('skos:member', $reverseResource);
548
                    while (isset($super) && !empty($super)) {
549
                        foreach ($super as $res) {
550
                            $superprop = new ConceptPropertyValue($this->model, $this->vocab, $res, 'skosmos:memberOfSuper', $this->clang);
551
                            array_unshift($groups, $superprop);
552
                            $super = $this->graph->resourcesMatching('skos:member', $res);
553
                        }
554
                    }
555
                }
556
            }
557
        }
558
        return $groups;
559
    }
560
561
    public function getArrayProperties() {
562
        return $this->getReverseResources(true);
563
    }
564
565
    /**
566
     * Reads the literal language code and gets a name for it from Punic or alternatively
567
     * tries to search for a gettext translation.
568
     * @param EasyRdf_Literal $lit
569
     * @return string e.g. 'English'
570
     */
571
    private function literalLanguageToString($lit) {
572
        // using empty string as the language literal when there is no langcode set
573
        $langName = '';
574
        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...
575
            $langName = Punic\Language::getName($lit->getLang(), $this->getEnvLang()) !== $lit->getLang() ? Punic\Language::getName($lit->getLang(), $this->getEnvLang()) : gettext($lit->getLang());
576
        }
577
        return $langName;
578
    }
579
580
    /**
581
     * Gets the values for the property in question in all other languages than the ui language.
582
     */
583
    public function getForeignLabels()
584
    {
585
        $labels = array();
586 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...
587
            // filtering away subsets of the current language eg. en vs en-GB
588
            if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
589
                $labels[$this->literalLanguageToString($lit)][] = new ConceptPropertyValueLiteral($lit, 'skos:prefLabel');
590
            }
591
        }
592 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...
593
            // filtering away subsets of the current language eg. en vs en-GB
594
            if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
595
                $labels[$this->literalLanguageToString($lit)][] = new ConceptPropertyValueLiteral($lit, 'skos:altLabel');
596
            }
597
        }
598
        ksort($labels);
599
        return $labels;
600
    }
601
602
    /**
603
     * Gets the values for the property in question in all other languages than the ui language.
604
     * @param string $property
605
     */
606
    public function getAllLabels($property)
607
    {
608
        $labels = array();
609
        // shortening property labels if possible, EasyRdf requires full URIs to be in angle brackets
610
        $property = (EasyRdf_Namespace::shorten($property) !== null) ? EasyRdf_Namespace::shorten($property) : "<$property>";
611
        foreach ($this->resource->allLiterals($property) as $lit) {
612
            $labels[Punic\Language::getName($lit->getLang(), $this->getEnvLang())][] = new ConceptPropertyValueLiteral($lit, $property);
613
        }
614
        ksort($labels);
615
        return $labels;
616
    }
617
}
618