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 ""; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getType() |
55
|
|
|
{ |
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getContainsHtml() { |
60
|
|
|
return preg_match("/\/[a-z]*>/i", $this->literal->getValue()) != 0; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getLabel() |
64
|
|
|
{ |
65
|
|
|
// if the property is a date object converting it to a human readable representation. |
66
|
|
|
if ($this->literal instanceof EasyRdf\Literal\Date) { |
67
|
|
|
try { |
68
|
|
|
$val = $this->literal->getValue(); |
69
|
|
|
return Punic\Calendar::formatDate($val, 'short'); |
|
|
|
|
70
|
|
|
} catch (Exception $e) { |
71
|
|
|
trigger_error($e->getMessage(), E_USER_WARNING); |
72
|
|
|
return (string) $this->literal; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
return $this->literal->getValue(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getUri() |
79
|
|
|
{ |
80
|
|
|
return null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getNotation() |
84
|
|
|
{ |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function hasXlProperties() |
89
|
|
|
{ |
90
|
|
|
$graph = $this->resource->getGraph(); |
91
|
|
|
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal); |
92
|
|
|
return !empty($resources); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getXlProperties() |
96
|
|
|
{ |
97
|
|
|
$ret = array(); |
98
|
|
|
$graph = $this->resource->getGraph(); |
99
|
|
|
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal); |
100
|
|
|
foreach ($resources as $xlres) { |
101
|
|
|
foreach ($xlres->properties() as $prop) { |
102
|
|
|
foreach($graph->allLiterals($xlres, $prop) as $val) { |
103
|
|
|
if ($prop !== 'rdf:type') { |
104
|
|
|
$ret[$prop] = $val; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
return $ret; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|