server/src/app/Models/Document.php
changeset 169 8fddc113095e
parent 168 17f10b56c079
child 260 64caee7ce38d
--- a/server/src/app/Models/Document.php	Thu Jun 02 18:24:19 2016 +0200
+++ b/server/src/app/Models/Document.php	Sun Jun 05 00:28:45 2016 +0200
@@ -20,7 +20,7 @@
 class Document extends DocumentResult {
 
     public function __construct($uri, $graph = null) {
-        //print($graph->dump('html'));
+        //                print($graph->dump('html'));
         parent::__construct($uri, $graph);
     }
 
@@ -29,6 +29,7 @@
     private $transcript = false;
     private $contributors = null;
     private $subjects = null;
+    private $geoInfo = false;
 
     protected function clearMemoizationCache() {
         parent::clearMemoizationCache();
@@ -37,6 +38,7 @@
         $this->contributors = null;
         $this->subjects = null;
         $this->transcript = false;
+        $this->geoInfo = false;
     }
 
 
@@ -217,6 +219,20 @@
     }
 
     /**
+     *
+     */
+    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);
+            }
+        }
+        return $this->geoInfo;
+    }
+
+    /**
      * change subjecs list
      */
     public function setSubjects($subjects) {
@@ -278,6 +294,7 @@
                         );
 
             $transcript = is_null($this->getTranscript())?null:$this->getTranscript()->jsonSerialize();
+            $geoInfo = is_null($this->getGeoInfo())?null:$this->getGeoInfo()->jsonSerialize();
 
             $publishers = array_map(
                 function($v) { return Utils::processLiteralResourceOrString($v); },
@@ -299,7 +316,8 @@
                 'contributors' => $contributors,
                 'subjects' => $subjects,
                 'transcript' => $transcript,
-                'mediaArray'=> $mediaArray
+                'mediaArray'=> $mediaArray,
+                'geoInfo' => $geoInfo
             ]);
 
         }