diff -r 4a3899b6a7ed -r 766af1228b05 server/src/app/Models/DocumentBase.php --- a/server/src/app/Models/DocumentBase.php Sun Oct 16 22:23:31 2016 +0530 +++ b/server/src/app/Models/DocumentBase.php Sun Oct 16 23:19:57 2016 +0530 @@ -26,10 +26,11 @@ // memoization private $providedCHO = null; private $title = false; - private $lang = null; - private $langResolved = null; - private $issued = null; - private $modified = null; + private $langs = null; + private $langsResolved = null; + private $issued = false; + private $modified = false; + private $created = false; public function getProvidedCHO() { @@ -42,10 +43,11 @@ protected function clearMemoizationCache() { $this->providedCHO = null; $this->title = false; - $this->lang = null; - $this->langResolved = null; - $this->issued = null; - $this->modified = null; + $this->langs = null; + $this->langsResolved = null; + $this->issued = false; + $this->modified = false; + $this->created = false; } public function getId() { @@ -63,36 +65,33 @@ return $this->id; } - public function getLanguage() { - if(is_null($this->lang)) { + public function getLanguages() { + if(is_null($this->langs)) { try { - $langs = $this->getProvidedCHO()->all(''); - if(count($langs) > 0) { - $this->lang = $langs[0]; - } + $this->langs = $this->getProvidedCHO()->all(''); } catch(\Exception $e) { - $this->lang = null; + $this->langs = []; } } - return $this->lang; + return $this->langs; } - public function getLanguageValue() { - $lang = $this->getLanguage(); - if($lang instanceof Resource) { - return $lang->getUri(); - } else if($lang instanceof Literal) { - return $lang->getValue(); - } - return null; + public function getLanguagesValue() { + return array_map(function($lang) { + if($lang instanceof Resource) { + return $lang->getUri(); + } else if($lang instanceof Literal) { + return $lang->getValue(); + } + }, $this->getLanguages()); } - public function getLanguageResolved() { - return $this->langResolved; + public function getLanguagesResolved() { + return $this->langsResolved; } - public function setLanguageResolved($languageResolved) { - $this->langResolved = $languageResolved; + public function setLanguagesResolved($languagesResolved) { + $this->langsResolved = $languagseResolved; } @@ -125,7 +124,7 @@ } public function getIssued() { - if(is_null($this->issued)) { + if($this->issued === false) { try { $this->issued = $this->getProvidedCHO()->getLiteral(""); } catch(\Exception $e) { @@ -140,8 +139,19 @@ return is_null($issued)?null:$issued->getValue(); } + public function getCreated() { + if($this->created === false) { + try { + $this->created = $this->getProvidedCHO()->getLiteral(""); + } catch(\Exception $e) { + $this->created = null; + } + } + return $this->created; + } + public function getModified() { - if(is_null($this->modified)) { + if($this->modified === false) { try { $this->modified = $this->getProvidedCHO()->getLiteral(""); if(is_null($this->modified)) { @@ -168,7 +178,7 @@ $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF"); $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified); - $this->modified = null; + $this->modified = false; } } @@ -189,12 +199,12 @@ 'id' => $this->getId(), 'uri' => $this->getUri(), 'title' => $this->getTitleValue(), - 'language' => $this->getLanguageValue(), + 'languages' => $this->getLanguagesValue(), 'modified' => $this->getModifiedValue(), 'issued' => $this->getIssuedValue() ]; - if($this->language_resolved) { - $res['language_resolved'] = $this->getLanguageResolved(); + if($this->languagesResolved) { + $res['languages_resolved'] = $this->getLanguagesResolved(); } return $res;