server/src/app/Models/Document.php
changeset 3 2b3247d02769
parent 2 00e2916104fe
child 4 f55970e41793
--- a/server/src/app/Models/Document.php	Tue Jun 23 17:01:39 2015 +0200
+++ b/server/src/app/Models/Document.php	Wed Jun 24 01:36:46 2015 +0200
@@ -3,20 +3,20 @@
 
 use Config;
 use CorpusParole\Libraries\Utils;
+use CorpusParole\Libraries\RdfModel\RdfModelResource;
 use Log;
 
 /**
  * Model class for Document. Inherit from EasyRdf_Resource
+ * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}
  */
-class Document extends \EasyRdf_Resource {
+class Document extends RdfModelResource {
 
     public function __construct($uri, $graph = null) {
-        parent::__construct($uri, $graph);
-        $this->innerDocument = $this->getResource('foaf:primaryTopic');
+        parent::__construct($uri, $graph, 'foaf:primaryTopic');
     }
 
     private $id = null;
-    private $innerDocument = null;
 
     public function getId() {
         if(is_null($this->id)) {
@@ -65,13 +65,18 @@
     }
 
     public function updateDiscourseTypes(array $discoursesTypes) {
+
+        $this->startDelta();
+
         foreach($this->getDiscourseTypes() as $discourseType) {
             $this->innerDocument->delete('dc11:type', $discourseType);
+            $this->currentDelta->deletedGraph->add($this->innerDocument, 'dc11:type', $discourseType);
         }
         // re-add them
 
         foreach($discoursesTypes as $dType) {
             $this->innerDocument->add('dc11:type', new \EasyRdf_Literal($dType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri']));
+            $this->currentDelta->addedGraph->add($this->innerDocument, 'dc11:type', $discourseType);
         }
     }