--- a/server/src/app/Models/DocumentBase.php Mon Feb 06 16:05:02 2017 +0100
+++ b/server/src/app/Models/DocumentBase.php Wed Feb 08 15:25:24 2017 +0100
@@ -22,6 +22,8 @@
}
private $id = null;
+ private $cocoonId = null;
+ private $countryCode = false;
// memoization
private $providedCHO = null;
@@ -32,7 +34,6 @@
private $modified = false;
private $created = false;
-
public function getProvidedCHO() {
if(is_null($this->providedCHO)) {
$this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
@@ -65,6 +66,21 @@
return $this->id;
}
+ public function getCocoonId() {
+ if(is_null($this->cocoonId)) {
+ $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
+ foreach ($ids as $id) {
+ if($id instanceof Literal && strpos($id->getValue(), config('corpusparole.cocoon_doc_id_base')) === 0) {
+ $this->cocoonId = substr($id->getValue(), strlen(config('corpusparole.cocoon_doc_id_base')));
+ }
+ }
+ if(is_null($this->cocoonId)) {
+ $this->id = CocoonUtils::getCocoonIdFromCorpusUri($this->uri);
+ }
+ }
+ return $this->cocoonId;
+ }
+
public function getLanguages() {
if(is_null($this->langs)) {
try {
@@ -194,6 +210,14 @@
return is_null($modified)?null:$modified->getValue();
}
+ public function getCountryCode() {
+ return $this->countryCode;
+ }
+
+ public function setCountryCode($code) {
+ $this->countryCode = $code;
+ }
+
public function jsonSerialize() {
if(!$this->graph) {
@@ -203,6 +227,7 @@
} else {
$res = [
'id' => $this->getId(),
+ 'cocoonId' => $this->getCocoonId(),
'uri' => $this->getUri(),
'title' => $this->getTitleValue(),
'languages' => $this->getLanguagesValue(),
@@ -214,6 +239,9 @@
if($this->languagesResolved) {
$res['languages_resolved'] = $this->getLanguagesResolved();
}
+ if($this->getCountryCode() !== false) {
+ $res['countryCode'] = $this->getCountryCode();
+ }
return $res;
}