1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class for handling concept property values. |
5
|
|
|
*/ |
6
|
|
|
class ConceptPropertyValueLiteral extends VocabularyDataObject |
7
|
|
|
{ |
8
|
|
|
/** the literal object for the property value */ |
9
|
|
|
private $literal; |
10
|
|
|
/** property type */ |
11
|
|
|
private $type; |
12
|
|
|
/** content language */ |
13
|
|
|
private $clang; |
14
|
|
|
|
15
|
|
|
public function __construct($model, $vocab, $resource, $literal, $prop, $clang = '') |
16
|
|
|
{ |
17
|
|
|
parent::__construct($model, $vocab, $resource); |
18
|
|
|
$this->literal = $literal; |
19
|
|
|
$this->type = $prop; |
20
|
|
|
$this->clang = $clang; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __toString() |
24
|
|
|
{ |
25
|
|
|
if ($this->getLabel() === null) { |
26
|
|
|
return ""; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $this->getLabel(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getLang() |
33
|
|
|
{ |
34
|
|
|
return $this->literal->getLang(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* A method for fetching a datatype. |
39
|
|
|
*/ |
40
|
|
|
public function getDatatype(): ?string |
41
|
|
|
{ |
42
|
|
|
$datatype = $this->literal->getDatatype(); |
43
|
|
|
if ($datatype === null) { |
44
|
|
|
return null; |
45
|
|
|
} |
46
|
|
|
$graph = $this->resource->getGraph(); |
47
|
|
|
if ($graph->resource($datatype)->label($this->clang)) { |
48
|
|
|
$dtLabel = $graph->resource($datatype)->label($this->clang); |
49
|
|
|
return $dtLabel->getValue(); |
50
|
|
|
} |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getType() |
55
|
|
|
{ |
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getContainsHtml() |
60
|
|
|
{ |
61
|
|
|
return preg_match("/\/[a-z]*>/i", $this->getLabel()) != 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getLabel() |
65
|
|
|
{ |
66
|
|
|
// if the property is a date object converting it to a human readable representation. |
67
|
|
|
if ($this->literal instanceof EasyRdf\Literal\Date) { |
68
|
|
|
try { |
69
|
|
|
$val = $this->literal->getValue(); |
70
|
|
|
return Punic\Calendar::formatDate($val, 'short'); |
71
|
|
|
} catch (Exception $e) { |
72
|
|
|
trigger_error($e->getMessage(), E_USER_WARNING); |
73
|
|
|
return (string) $this->literal; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
return $this->literal->getValue(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getSortKey() |
80
|
|
|
{ |
81
|
|
|
return strtolower($this->getLabel()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getUri() |
85
|
|
|
{ |
86
|
|
|
return null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getNotation() |
90
|
|
|
{ |
91
|
|
|
return null; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function hasXlProperties() |
95
|
|
|
{ |
96
|
|
|
$xlLabel = $this->getXlLabel(); |
97
|
|
|
return ($xlLabel !== null && !empty($xlLabel->getProperties())); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getXlLabel() |
101
|
|
|
{ |
102
|
|
|
$graph = $this->resource->getGraph(); |
103
|
|
|
$labelResources = $graph->resourcesMatching('skosxl:literalForm', $this->literal); |
104
|
|
|
foreach($labelResources as $labres) { |
105
|
|
|
return new LabelSkosXL($this->model, $labres); |
106
|
|
|
} |
107
|
|
|
return null; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|