Completed
Push — master ( a76259...eb3b50 )
by Henri
15:52
created

Concept::getNotation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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