server/src/app/Models/DocumentBase.php
changeset 339 766af1228b05
parent 326 226d5b17a119
child 445 b1e5ad6b2a29
equal deleted inserted replaced
338:4a3899b6a7ed 339:766af1228b05
    24     private $id = null;
    24     private $id = null;
    25 
    25 
    26     // memoization
    26     // memoization
    27     private $providedCHO = null;
    27     private $providedCHO = null;
    28     private $title = false;
    28     private $title = false;
    29     private $lang = null;
    29     private $langs = null;
    30     private $langResolved = null;
    30     private $langsResolved = null;
    31     private $issued = null;
    31     private $issued = false;
    32     private $modified = null;
    32     private $modified = false;
       
    33     private $created = false;
    33 
    34 
    34 
    35 
    35     public function getProvidedCHO() {
    36     public function getProvidedCHO() {
    36         if(is_null($this->providedCHO)) {
    37         if(is_null($this->providedCHO)) {
    37             $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
    38             $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
    40     }
    41     }
    41 
    42 
    42     protected function clearMemoizationCache() {
    43     protected function clearMemoizationCache() {
    43         $this->providedCHO = null;
    44         $this->providedCHO = null;
    44         $this->title = false;
    45         $this->title = false;
    45         $this->lang = null;
    46         $this->langs = null;
    46         $this->langResolved = null;
    47         $this->langsResolved = null;
    47         $this->issued = null;
    48         $this->issued = false;
    48         $this->modified = null;
    49         $this->modified = false;
       
    50         $this->created = false;
    49     }
    51     }
    50 
    52 
    51     public function getId() {
    53     public function getId() {
    52         if(is_null($this->id)) {
    54         if(is_null($this->id)) {
    53             $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
    55             $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
    61             }
    63             }
    62         }
    64         }
    63         return $this->id;
    65         return $this->id;
    64     }
    66     }
    65 
    67 
    66     public function getLanguage() {
    68     public function getLanguages() {
    67         if(is_null($this->lang)) {
    69         if(is_null($this->langs)) {
    68             try {
    70             try {
    69                 $langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
    71                 $this->langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
    70                 if(count($langs) > 0) {
    72             } catch(\Exception $e) {
    71                     $this->lang = $langs[0];
    73                 $this->langs = [];
    72                 }
    74             }
    73             } catch(\Exception $e) {
    75         }
    74                 $this->lang = null;
    76         return $this->langs;
    75             }
    77     }
    76         }
    78 
    77         return $this->lang;
    79     public function getLanguagesValue() {
    78     }
    80         return array_map(function($lang) {
    79 
    81             if($lang instanceof Resource) {
    80     public function getLanguageValue() {
    82                 return $lang->getUri();
    81         $lang = $this->getLanguage();
    83             } else if($lang instanceof Literal) {
    82         if($lang instanceof Resource) {
    84                 return $lang->getValue();
    83             return $lang->getUri();
    85             }
    84         } else if($lang instanceof Literal) {
    86         }, $this->getLanguages());
    85             return $lang->getValue();
    87     }
    86         }
    88 
    87         return null;
    89     public function getLanguagesResolved() {
    88     }
    90         return $this->langsResolved;
    89 
    91     }
    90     public function getLanguageResolved() {
    92 
    91         return $this->langResolved;
    93     public function setLanguagesResolved($languagesResolved) {
    92     }
    94         $this->langsResolved = $languagseResolved;
    93 
       
    94     public function setLanguageResolved($languageResolved) {
       
    95         $this->langResolved = $languageResolved;
       
    96     }
    95     }
    97 
    96 
    98 
    97 
    99     public function getTitle() {
    98     public function getTitle() {
   100         if($this->title === false) {
    99         if($this->title === false) {
   123         $title = $this->getTitle();
   122         $title = $this->getTitle();
   124         return is_null($title)?null:$title->getValue();
   123         return is_null($title)?null:$title->getValue();
   125     }
   124     }
   126 
   125 
   127     public function getIssued() {
   126     public function getIssued() {
   128         if(is_null($this->issued)) {
   127         if($this->issued === false) {
   129             try {
   128             try {
   130                 $this->issued = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/issued>");
   129                 $this->issued = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/issued>");
   131             } catch(\Exception $e) {
   130             } catch(\Exception $e) {
   132                 $this->issued = null;
   131                 $this->issued = null;
   133             }
   132             }
   138     public function getIssuedValue() {
   137     public function getIssuedValue() {
   139         $issued = $this->getIssued();
   138         $issued = $this->getIssued();
   140         return is_null($issued)?null:$issued->getValue();
   139         return is_null($issued)?null:$issued->getValue();
   141     }
   140     }
   142 
   141 
       
   142     public function getCreated() {
       
   143         if($this->created === false) {
       
   144             try {
       
   145                 $this->created = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/created>");
       
   146             } catch(\Exception $e) {
       
   147                 $this->created = null;
       
   148             }
       
   149         }
       
   150         return $this->created;
       
   151     }
       
   152 
   143     public function getModified() {
   153     public function getModified() {
   144         if(is_null($this->modified)) {
   154         if($this->modified === false) {
   145             try {
   155             try {
   146                 $this->modified = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/modified>");
   156                 $this->modified = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/modified>");
   147                 if(is_null($this->modified)) {
   157                 if(is_null($this->modified)) {
   148                     $this->modified = $this->getIssued();
   158                     $this->modified = $this->getIssued();
   149                 }
   159                 }
   166         if($value && (!$modified || $modified->getValue() !== $value) ) {
   176         if($value && (!$modified || $modified->getValue() !== $value) ) {
   167 
   177 
   168             $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
   178             $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
   169             $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
   179             $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
   170 
   180 
   171             $this->modified = null;
   181             $this->modified = false;
   172         }
   182         }
   173     }
   183     }
   174 
   184 
   175 
   185 
   176     public function getModifiedValue() {
   186     public function getModifiedValue() {
   187         } else {
   197         } else {
   188             $res = [
   198             $res = [
   189                 'id' => $this->getId(),
   199                 'id' => $this->getId(),
   190                 'uri' => $this->getUri(),
   200                 'uri' => $this->getUri(),
   191                 'title' => $this->getTitleValue(),
   201                 'title' => $this->getTitleValue(),
   192                 'language' => $this->getLanguageValue(),
   202                 'languages' => $this->getLanguagesValue(),
   193                 'modified' => $this->getModifiedValue(),
   203                 'modified' => $this->getModifiedValue(),
   194                 'issued' => $this->getIssuedValue()            ];
   204                 'issued' => $this->getIssuedValue()            ];
   195 
   205 
   196             if($this->language_resolved) {
   206             if($this->languagesResolved) {
   197                 $res['language_resolved'] = $this->getLanguageResolved();
   207                 $res['languages_resolved'] = $this->getLanguagesResolved();
   198             }
   208             }
   199 
   209 
   200             return $res;
   210             return $res;
   201         }
   211         }
   202     }
   212     }