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 |
|
|
21 |
public function isDirty() { |
|
22 |
return !is_null($this->deltaList) && count($this->deltaList)>0; |
|
23 |
} |
|
24 |
|
|
25 |
public function deltaCount() { |
|
26 |
return is_null($this->deltaList)?0:count($this->deltaList); |
|
27 |
} |
|
28 |
|
|
29 |
public function getDeltaList() { |
|
30 |
return $this->deltaList; |
|
31 |
} |
|
32 |
|
|
33 |
public function getUri() { |
|
34 |
return $this->uri; |
|
35 |
} |
|
36 |
|
28
|
37 |
public function getCurrentDelta() { |
|
38 |
return $this->getCurrentDelta; |
|
39 |
} |
|
40 |
|
4
|
41 |
public function startDelta() { |
|
42 |
$this->currentDelta = new RdfModelDelta($this->getGraph()->getUri()); |
|
43 |
array_push($this->deltaList, $this->currentDelta); |
28
|
44 |
return $this->currentDelta; |
|
45 |
} |
|
46 |
|
|
47 |
protected function setSimpleProperty($baseNode, $property, $oldValue, $newValue) { |
|
48 |
$delta = $this->startDelta(); |
|
49 |
$baseNode->delete($property, $oldValue); |
|
50 |
$delta->getDeletedGraph()->add($baseNode, $property, $oldValue); |
|
51 |
$baseNode->add($property, $newValue); |
|
52 |
$delta->getAddedGraph()->add($baseNode, $property, $newValue); |
4
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
} |