Completed
Push — master ( 5e2d67...2eb11f )
by Henri
02:54
created

ConceptProperty::getSubPropertyOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class for handling concept properties.
5
 */
6
class ConceptProperty
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
    /** stores the property type */
9
    private $prop;
10
    /** stores the property supertype */
11
    private $super;
12
    /** stores the property label */
13
    private $label;
14
    /** stores the property values */
15
    private $values;
16
    /** flag whether the values are sorted, as we do lazy sorting */
17
    private $is_sorted;
18
19
    /**
20
     * Label parameter seems to be optional in this phase.
21
     * @param string $prop property type eg. 'rdf:type'.
22
     * @param string $label
23
     */
24
    public function __construct($prop, $label, $super)
25
    {
26
        $this->prop = $prop;
27
        $this->label = $label;
28
        $this->values = array();
29
        $this->is_sorted = true;
30
        $this->super = $super;
31
    }
32
33
    /**
34
     * Gets the gettext translation for a property or returns the identifier as a fallback.
35
     */
36
    public function getLabel()
37
    {
38
        // first see if we have a translation
39
        // we don't maintain DC 1.1 translations separate from DC Terms
40
        $prop = (substr($this->prop, 0, 5) == 'dc11:') ?
41
            str_replace('dc11:', 'dc:', $this->prop) : $this->prop;
42
        $label = gettext($prop);
43
        if ($label != $prop) {
44
            return $label;
45
        }
46
47
        // if not, see if there was a label for the property in the graph
48
        if ($this->label) {
49
            return $this->label;
50
        }
51
52
        // when no label is found, don't show the property at all
53
        return null;
54
    }
55
56
    /**
57
     * Returns a gettext translation for the property tooltip.
58
     * @return string
59
     */
60
    public function getDescription()
61
    {
62
        $helpprop = $this->prop . "_help";
63
64
        return gettext($helpprop); // can't use string constant, it'd be picked up by xgettext
65
    }
66
67
    /**
68
     * Returns an array of the property values.
69
     * @return array containing ConceptPropertyValue objects.
70
     */
71
    public function getValues()
72
    {
73
        if (!$this->is_sorted) {
74
            $this->sortValues();
75
        }
76
        return $this->values;
77
    }
78
79
    public function addValue($value)
80
    {
81
        $this->values[$value->getLabel() . $value->getUri()] = $value;
82
        $this->is_sorted = false;
83
    }
84
85
    private function sortValues()
86
    {
87
        if (!empty($this->values)) {
88
            uksort($this->values, function($a, $b) {
89
                return strnatcasecmp($a,$b);
90
            });
91
        }
92
        $this->is_sorted = true;
93
    }
94
95
    /**
96
     * Returns property type as a string.
97
     * @return string eg. 'rdf:type'.
98
     */
99
    public function getType()
100
    {
101
        return $this->prop;
102
    }
103
    
104
    /**
105
     * Returns property supertype (?property skos:subPropertyOf ?super) as a string.
106
     * @return string eg. 'skos:hiddenLabel'.
107
     */
108
    public function getSubPropertyOf()
109
    {
110
        return $this->super;
111
    }
112
}
113