add rights, Prepare #0025746
authorymh <ymh.work@gmail.com>
Mon, 06 Feb 2017 16:05:02 +0100
changeset 501 7b2dcd2b31c1
parent 500 4f507ba2bb4c
child 502 74fba571487e
add rights, Prepare #0025746
server/src/app/Models/Document.php
server/src/tests/Models/DocumentTest.php
--- a/server/src/app/Models/Document.php	Mon Feb 06 15:22:39 2017 +0100
+++ b/server/src/app/Models/Document.php	Mon Feb 06 16:05:02 2017 +0100
@@ -33,6 +33,7 @@
     private $descriptions = null;
     private $geoInfo = false;
     private $alternativeTitle = false;
+    private $rights = false;
 
     protected function clearMemoizationCache() {
         parent::clearMemoizationCache();
@@ -44,6 +45,7 @@
         $this->descriptions = null;
         $this->transcript = false;
         $this->geoInfo = false;
+        $this->rights = false;
     }
 
     protected function additionalDeltaLists() {
@@ -345,6 +347,26 @@
         return is_null($alternativeTitle)?null:$alternativeTitle->getValue();
     }
 
+
+    /**
+     * Get Rights
+     */
+    public function getRights() {
+        if($this->rights === false) {
+            try {
+                $this->rights = $this->getResource('<http://www.europeana.eu/schemas/edm/rights>');
+            } catch(\Exception $e) {
+                $this->rights = null;
+            }
+        }
+        return $this->rights;
+    }
+
+    public function getRightsValue() {
+        $rights = $this->getRights();
+        return is_null($rights)?null:$rights->getUri();
+    }
+
     public function isIsomorphic($doc) {
         return Isomorphic::isomorphic($this->graph, $doc->graph);
     }
@@ -408,6 +430,7 @@
                 'geoInfo' => $geoInfo,
                 'descriptions' => $descriptions,
                 'alternativeTitle' => $this->getAlternativeTitleValue(),
+                'rights' => $this->getRightsValue()
             ]);
 
         }
--- a/server/src/tests/Models/DocumentTest.php	Mon Feb 06 15:22:39 2017 +0100
+++ b/server/src/tests/Models/DocumentTest.php	Mon Feb 06 16:05:02 2017 +0100
@@ -431,7 +431,7 @@
             [ "id", "uri", "title", "languages", "modified", "issued",
               "created", "publishers", "contributors", "subjects", "types",
               "transcript", "mediaArray", "geoInfo", "descriptions",
-              "alternativeTitle" ],
+              "alternativeTitle", "rights"],
             array_keys($json)
         );
         $this->assertEquals(sprintf('%1$s/crdo-CFPP2000_35_SOUNDid', config('corpusparole.handle_prefix')), $json['id']);