server/src/app/Models/Document.php
changeset 20 a9b98b16b053
parent 19 eadaf0b8f02e
child 28 b0b56e0f8c7f
--- a/server/src/app/Models/Document.php	Fri Nov 27 17:59:36 2015 +0100
+++ b/server/src/app/Models/Document.php	Tue Dec 01 13:33:08 2015 +0100
@@ -67,6 +67,11 @@
         return $this->title;
     }
 
+    public function getTitleValue() {
+        $title = $this->getTitle();
+        return is_null($title)?null:$title->getValue();
+    }
+
     public function getPublishers() {
         if(is_null($this->publishers)) {
             try {
@@ -89,6 +94,11 @@
         return $this->issued;
     }
 
+    public function getIssuedValue() {
+        $issued = $this->getIssued();
+        return is_null($issued)?null:$issued->getValue();
+    }
+
     public function getModified() {
         if(is_null($this->modified)) {
             try {
@@ -96,9 +106,6 @@
                 if(is_null($this->modified)) {
                     $this->modified = $this->getIssued();
                 }
-                else {
-                    $this->modified = $this->modified->getValue();
-                }
             } catch(\Exception $e) {
                 $this->modified = null;
             }
@@ -106,6 +113,11 @@
         return $this->modified;
     }
 
+    public function getModifiedValue() {
+        $modified = $this->getModified();
+        return is_null($modified)?null:$modified->getValue();
+    }
+
     public function getMediaArray() {
 
         if(is_null($this->mediaArray)) {
@@ -116,7 +128,7 @@
             $masterUrl = is_null($master)?null:$master->getUri();
 
             foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResources>") as $webResource) {
-                $extent = $webResource->getLiteral("dc:extent");
+                $extent = $webResource->getLiteral("<http://purl.org/dc/terms/extent>");
                 $extent = is_null($extent)?null:$extent->getValue();
                 $extent_ms = Utils::iso8601IntervalToMillis($extent);
                 $format = $webResource->getLiteral("dc11:format");
@@ -150,6 +162,28 @@
         return $res;
     }
 
+    public function getContributors() {
+        return array_reduce(
+            CocoonUtils::OLAC_ROLES,
+            function($res, $olacRole) {
+                return array_merge(
+                    $res,
+                    array_map(
+                        function($olacValue) use ($olacRole) {
+                            return [
+                                'name' => ($olacValue instanceof Literal)?$olacValue->getValue():null,
+                                'url' => ($olacValue instanceof Resource)?$olacValue->getUri():null,
+                                'role' => $olacRole
+                            ];
+                        },
+                        $this->getProvidedCHO()->all("<$olacRole>")
+                    )
+                );
+            },
+            []
+        );
+    }
+
     /**
      * change discourse type list
      */
@@ -195,7 +229,9 @@
             $mediaArray = array_map(
                 function($m) {
                     $f = Utils::processLiteralOrString($m['format']);
-                    return ['url' => $m['url'], 'format' => $f];},
+                    $res = $m;
+                    $res['format'] = $f;
+                    return $res;},
                 $this->getMediaArray()
             );
 
@@ -207,9 +243,10 @@
             return [
                 'id' => $this->getId(),
                 'uri' => $this->getUri(),
-                'title' => $this->getTitle()->getValue(),
-                'modified' => $this->getModified(),
+                'title' => $this->getTitleValue(),
+                'modified' => $this->getModifiedValue(),
                 'publishers' => $publishers,
+                'contributors' => $this->getContributors(),
                 'mediaArray'=> $mediaArray
             ];
         }