author | ymh <ymh.work@gmail.com> |
Wed, 15 Feb 2017 10:51:15 +0100 | |
changeset 509 | fcc59d0ac8aa |
parent 277 | bd4bc1db4f40 |
permissions | -rw-r--r-- |
4 | 1 |
<?php |
2 |
namespace CorpusParole\Libraries\RdfModel; |
|
3 |
||
4 |
use CorpusParole\Libraries\RdfModel\RdfModelDelta; |
|
5 |
use EasyRdf\Resource; |
|
6 |
||
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
class RdfModelResource extends Resource { |
|
11 |
||
12 |
public function __construct($uri, $graph = null) { |
|
13 |
parent::__construct($uri, $graph); |
|
14 |
$this->uri = $uri; |
|
15 |
} |
|
16 |
||
17 |
protected $deltaList = []; |
|
18 |
protected $currentDelta = null; |
|
19 |
protected $uri = null; |
|
20 |
||
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
21 |
protected function additionalDeltaLists() { |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
22 |
return []; |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
23 |
} |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
24 |
|
4 | 25 |
public function isDirty() { |
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
26 |
return $this->deltaCount()>0; |
4 | 27 |
} |
28 |
||
29 |
public function deltaCount() { |
|
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
30 |
$deltaList = $this->getDeltaList(); |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
31 |
return is_null($deltaList)?0:count($deltaList); |
4 | 32 |
} |
33 |
||
34 |
public function getDeltaList() { |
|
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
35 |
$deltaList = is_null($this->deltaList)?[]:$this->deltaList; |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
36 |
$additionalDeltaLists = $this->additionalDeltaLists(); |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
37 |
if(!empty($additionalDeltaLists)) { |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
38 |
array_unshift($additionalDeltaLists, $deltaList); |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
39 |
$deltaList = call_user_func_array('array_merge', $additionalDeltaLists); |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
40 |
} |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
41 |
return $deltaList; |
4 | 42 |
} |
43 |
||
44 |
public function getUri() { |
|
45 |
return $this->uri; |
|
46 |
} |
|
47 |
||
28 | 48 |
public function getCurrentDelta() { |
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
49 |
return $this->currentDelta; |
28 | 50 |
} |
51 |
||
4 | 52 |
public function startDelta() { |
53 |
$this->currentDelta = new RdfModelDelta($this->getGraph()->getUri()); |
|
54 |
array_push($this->deltaList, $this->currentDelta); |
|
28 | 55 |
return $this->currentDelta; |
56 |
} |
|
57 |
||
58 |
protected function setSimpleProperty($baseNode, $property, $oldValue, $newValue) { |
|
59 |
$delta = $this->startDelta(); |
|
60 |
$baseNode->delete($property, $oldValue); |
|
61 |
$delta->getDeletedGraph()->add($baseNode, $property, $oldValue); |
|
62 |
$baseNode->add($property, $newValue); |
|
63 |
$delta->getAddedGraph()->add($baseNode, $property, $newValue); |
|
4 | 64 |
} |
65 |
||
66 |
||
67 |
} |