Completed
Push — master ( 00fcb4...f21d74 )
by Henri
04:06
created

ConceptPropertyValue::getReifiedPropertyValues()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
1
<?php
2
3
/**
4
 * Class for handling concept property values.
5
 */
6
class ConceptPropertyValue 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...
7
{
8
    /** submembers */
9
    private $submembers;
10
    /** property type */
11
    private $type;
12
    /** content language */
13
    private $clang;
14
15 View Code Duplication
    public function __construct($model, $vocab, $resource, $prop, $clang = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
16
    {
17
        parent::__construct($model, $vocab, $resource);
18
        $this->submembers = array();
19
        $this->type = $prop;
20
        $this->clang = $clang;
21
    }
22
23
    public function __toString()
24
    {
25
        $label = is_string($this->getLabel()) ? $this->getLabel() : $this->getLabel()->getValue();
26
        if ($this->vocab->getConfig()->sortByNotation()) {
27
            $label = $this->getNotation() . $label;
28
        }
29
30
        return $label;
31
    }
32
33
    public function getLang()
34
    {
35
        return $this->getEnvLang();
36
    }
37
38
    public function getLabel($lang = '')
39
    {
40
        if ($this->clang) {
41
            $lang = $this->clang;
42
        }
43
44
        if ($this->resource->label($lang) !== null) { // current language
45
            return $this->resource->label($lang);
46 View Code Duplication
        } elseif ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) { // vocab default language
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...
47
            return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage());
48
        } elseif ($this->resource->label() !== null) { // any language
49
            return $this->resource->label();
50
        } elseif ($this->resource->getLiteral('rdf:value', $lang) !== null) { // current language
51
            return $this->resource->getLiteral('rdf:value', $lang);
52
        } elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language
53
            return $this->resource->getLiteral('rdf:value');
54
        }
55
        $label = $this->resource->shorten() ? $this->resource->shorten() : $this->getUri();
56
        return $label;
57
    }
58
59
    public function getType()
60
    {
61
        return $this->type;
62
    }
63
64
    public function getUri()
65
    {
66
        return $this->resource->getUri();
67
    }
68
69
    public function getVocab()
70
    {
71
        return $this->vocab;
72
    }
73
74
    public function getVocabName()
75
    {
76
        return $this->vocab->getTitle();
77
    }
78
79
    public function addSubMember($member, $lang = '')
80
    {
81
        $label = $member->getLabel($lang) ? $member->getLabel($lang) : $member->getLabel();
82
        $this->submembers[$label->getValue()] = $member;
83
        $this->sortSubMembers();
84
    }
85
86
    public function getSubMembers()
87
    {
88
        if (empty($this->submembers)) {
89
            return null;
90
        }
91
92
        return $this->submembers;
93
    }
94
95
    private function sortSubMembers()
96
    {
97
        if (!empty($this->submembers)) {
98
            ksort($this->submembers);
99
        }
100
101
    }
102
103
    public function isExternal() {
104
        $propertyUris = $this->resource->propertyUris();
105
        return empty($propertyUris);
106
    }
107
108
    public function getNotation()
109
    {
110
        if ($this->vocab->getConfig()->showNotation() && $this->resource->get('skos:notation')) {
111
            return $this->resource->get('skos:notation')->getValue();
112
        }
113
114
    }
115
116
    public function isReified() {
117
        return (!$this->resource->label() && $this->resource->getLiteral('rdf:value'));
118
    }
119
    
120
    public function getReifiedPropertyValues() {
121
        $ret = array();
122
        $props = $this->resource->properties();
123
        foreach($props as $prop) {
124
            if ($prop !== 'rdf:value') { // shown elsewhere
125
                $ret[$prop] = $this->resource->get($prop);
126
            }
127
        }
128
        return $ret;
129
    }
130
131
}
132