server/src/app/Models/Document.php
changeset 260 64caee7ce38d
parent 169 8fddc113095e
child 277 bd4bc1db4f40
--- a/server/src/app/Models/Document.php	Tue Aug 23 23:05:25 2016 +0200
+++ b/server/src/app/Models/Document.php	Sat Aug 06 21:27:53 2016 +0700
@@ -17,7 +17,7 @@
  * Model class for Document. Inherit from EasyRd\Resource
  * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}
  */
-class Document extends DocumentResult {
+class Document extends DocumentBase {
 
     public function __construct($uri, $graph = null) {
         //                print($graph->dump('html'));
@@ -42,17 +42,6 @@
     }
 
 
-    public function getPublishers() {
-        if(is_null($this->publishers)) {
-            try {
-                $this->publishers = $this->getProvidedCHO()->all('dc11:publisher');
-            } catch(\Exception $e) {
-               $this->publishers = [];
-            }
-        }
-        return $this->publishers;
-    }
-
     private function parseWebResources() {
 
         $this->mediaArray = [];
@@ -63,29 +52,29 @@
 
         foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResource>") as $webResource) {
             $formatLit = $webResource->getLiteral("dc11:format");
-             $format = is_null($formatLit)?null:$formatLit->getValue();
-             if(is_null($format)) {
-                 throw new ModelsException("parseWebResources: No dc:11 format on web resource");
-             }
+            $format = is_null($formatLit)?null:$formatLit->getValue();
+            if(is_null($format)) {
+                throw new ModelsException("parseWebResources: No dc:11 format on web resource");
+            }
 
-             if(0 === strpos($format, 'audio/') ||
-                0 === strpos($format, 'video/') ||
-                0 === strpos($format, 'Sampling:') ) {
-                 array_push(
-                     $this->mediaArray,
-                     new MediaResource(
-                         $webResource->getUri(),
-                         $this->graph,
-                         (($webResource->getUri() === $masterUrl)?true:false))
-                 );
-             } else if(
-                 0 === strpos($format, 'application/xml') ||
-                 0 === strpos($format, 'application/pdf') ) {
-                 $this->transcript = new TranscriptResource($webResource->getUri(), $this->graph);
-             }
-             else {
-                 throw new ModelsException("parseWebResources: unknown format");
-             }
+            if(0 === strpos($format, 'audio/') ||
+               0 === strpos($format, 'video/') ||
+               0 === strpos($format, 'Sampling:') ) {
+                array_push(
+                    $this->mediaArray,
+                    new MediaResource(
+                        $webResource->getUri(),
+                        $this->graph,
+                        (($webResource->getUri() === $masterUrl)?true:false))
+                );
+            } else if(
+                0 === strpos($format, 'application/xml') ||
+                0 === strpos($format, 'application/pdf') ) {
+                $this->transcript = new TranscriptResource($webResource->getUri(), $this->graph);
+            }
+            else {
+                throw new ModelsException("parseWebResources: unknown format");
+            }
         }
 
     }
@@ -263,6 +252,27 @@
 
     }
 
+    public function getPublishers() {
+        if(is_null($this->publishers)) {
+            try {
+                $this->publishers = $this->getProvidedCHO()->all('dc11:publisher');
+            } catch(\Exception $e) {
+               $this->publishers = [];
+            }
+        }
+        return $this->publishers;
+    }
+
+    public function getPublishersValues() {
+        $publishers = $this->getPublishers();
+        return array_map(
+            function($v) { return Utils::processLiteralResourceOrString($v); },
+            $this->getPublishers()
+        );
+    }
+
+
+
     public function isIsomorphic($doc) {
         return Isomorphic::isomorphic($this->graph, $doc->graph);
     }
@@ -296,10 +306,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); },
-                $this->getPublishers()
-            );
+            $publishers = $this->getPublishersValues();
 
             $contributors = array_map(
                 function($c) { unset($c['nameLiteral']); return $c; },