server/src/app/Models/Document.php
changeset 277 bd4bc1db4f40
parent 260 64caee7ce38d
child 371 0365fd9977a4
--- a/server/src/app/Models/Document.php	Thu Sep 08 19:15:46 2016 +0200
+++ b/server/src/app/Models/Document.php	Thu Sep 22 12:38:24 2016 +0200
@@ -41,6 +41,13 @@
         $this->geoInfo = false;
     }
 
+    protected function additionalDeltaLists() {
+
+        $geoInfo = $this->getGeoInfo();
+        $geoInfoDeltas = is_null($geoInfo)?[]:$geoInfo->getDeltaList();
+        return empty($geoInfoDeltas)?[]:[$geoInfoDeltas,];
+    }
+
 
     private function parseWebResources() {
 
@@ -208,19 +215,42 @@
     }
 
     /**
-     *
+     * get the GeoInfoObject
+     * Ths returned object should be limited for read only activities.
+     * If it needs to be edited use the addGeoInfo method.
      */
     public function getGeoInfo() {
         if($this->geoInfo === false) {
             $places = $this->getProvidedCHO()->all('<http://purl.org/dc/terms/spatial>');
             $this->geoInfo = null;
             if($places) {
-                $this->geoInfo = new GeoResource($places[0]->getUri(), $this->graph);
+                $this->geoInfo = new GeoResource($places[0]->getUri(), $this->graph, $this->getProvidedCHO());
             }
         }
         return $this->geoInfo;
     }
 
+    public function addGeoInfo() {
+        $geoInfo = $this->getGeoInfo();
+        if(!is_null($geoInfo)) {
+            // if there already is a geo info, just return it.
+            $geoInfo->setReadOnly(false);
+            $geoInfo->setNeedDelete(true);
+            return $geoInfo;
+         }
+
+        $this->geoInfo = false;
+
+        $geoinfoNode = $this->getGraph()->newBNode("http://www.europeana.eu/schemas/edm/Place");
+        $this->getProvidedCHO()->addResource("http://purl.org/dc/terms/spatial", $geoinfoNode);
+
+        $this->geoInfo = new GeoResource($geoinfoNode->getUri(), $this->graph, $this->getProvidedCHO());
+        $this->geoInfo->setReadOnly(false);
+        $this->geoInfo->setNeedDelete(false);
+
+        return $this->geoInfo;
+    }
+
     /**
      * change subjecs list
      */