server/src/app/Libraries/RdfModel/RdfModelResource.php
author ymh <ymh.work@gmail.com>
Tue, 19 Jan 2016 19:18:34 +0100
changeset 109 d22ed5792f8e
parent 28 b0b56e0f8c7f
child 277 bd4bc1db4f40
permissions -rw-r--r--
Correct transaction management. cf. bug https://openrdf.atlassian.net/browse/SES-2295 and tomcat default management of PUT request with form data (application/x-www-form-urlencoded encoded)

<?php
namespace CorpusParole\Libraries\RdfModel;

use CorpusParole\Libraries\RdfModel\RdfModelDelta;
use EasyRdf\Resource;

/**
 *
 */
class RdfModelResource extends Resource {

    public function __construct($uri, $graph = null) {
        parent::__construct($uri, $graph);
        $this->uri = $uri;
    }

    protected $deltaList = [];
    protected $currentDelta = null;
    protected $uri = null;

    public function isDirty() {
        return !is_null($this->deltaList) && count($this->deltaList)>0;
    }

    public function deltaCount() {
        return is_null($this->deltaList)?0:count($this->deltaList);
    }

    public function getDeltaList() {
        return $this->deltaList;
    }

    public function getUri() {
        return $this->uri;
    }

    public function getCurrentDelta() {
        return $this->getCurrentDelta;
    }

    public function startDelta() {
        $this->currentDelta = new RdfModelDelta($this->getGraph()->getUri());
        array_push($this->deltaList, $this->currentDelta);
        return $this->currentDelta;
    }

    protected function setSimpleProperty($baseNode, $property, $oldValue, $newValue) {
        $delta = $this->startDelta();
        $baseNode->delete($property, $oldValue);
        $delta->getDeletedGraph()->add($baseNode, $property, $oldValue);
        $baseNode->add($property, $newValue);
        $delta->getAddedGraph()->add($baseNode, $property, $newValue);
    }


}