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
|
|
|
|
13
|
|
|
public function __construct($model, $vocab, $resource, $literal, $prop) |
14
|
|
|
{ |
15
|
|
|
parent::__construct($model, $vocab, $resource); |
16
|
|
|
$this->literal = $literal; |
17
|
|
|
$this->type = $prop; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function __toString() |
21
|
|
|
{ |
22
|
|
|
if ($this->getLabel() === null) { |
23
|
|
|
return ""; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return $this->getLabel(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getLang() |
30
|
|
|
{ |
31
|
|
|
return $this->literal->getLang(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getType() |
35
|
|
|
{ |
36
|
|
|
return $this->type; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getLabel() |
40
|
|
|
{ |
41
|
|
|
// if the property is a date object converting it to a human readable representation. |
42
|
|
|
if ($this->literal instanceof EasyRdf\Literal\Date) { |
43
|
|
|
try { |
44
|
|
|
$val = $this->literal->getValue(); |
45
|
|
|
return Punic\Calendar::formatDate($val, 'short'); |
46
|
|
|
} catch (Exception $e) { |
47
|
|
|
trigger_error($e->getMessage(), E_USER_WARNING); |
48
|
|
|
return (string) $this->literal; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
return $this->literal->getValue(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getUri() |
55
|
|
|
{ |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getNotation() |
60
|
|
|
{ |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function hasXlProperties() |
65
|
|
|
{ |
66
|
|
|
$graph = $this->resource->getGraph(); |
67
|
|
|
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal); |
68
|
|
|
return !empty($resources); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getXlProperties() |
72
|
|
|
{ |
73
|
|
|
$ret = array(); |
74
|
|
|
$graph = $this->resource->getGraph(); |
75
|
|
|
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal); |
76
|
|
|
foreach ($resources as $xlres) { |
77
|
|
|
foreach ($xlres->properties() as $prop) { |
|
|
|
|
78
|
|
|
foreach($graph->allLiterals($xlres, $prop) as $val) { |
|
|
|
|
79
|
|
|
if ($prop !== 'rdf:type') { |
80
|
|
|
$ret[$prop] = $val; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
return $ret; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.