server/src/app/Models/DocumentBase.php
changeset 326 226d5b17a119
parent 325 31a4987f6017
child 445 b1e5ad6b2a29
equal deleted inserted replaced
325:31a4987f6017 326:226d5b17a119
    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 = false;
    31     private $issued = false;
    32     private $modified = false;
    32     private $modified = false;
    33     private $created = false;
    33     private $created = false;
    34 
    34 
    35 
    35 
    41     }
    41     }
    42 
    42 
    43     protected function clearMemoizationCache() {
    43     protected function clearMemoizationCache() {
    44         $this->providedCHO = null;
    44         $this->providedCHO = null;
    45         $this->title = false;
    45         $this->title = false;
    46         $this->lang = null;
    46         $this->langs = null;
    47         $this->langResolved = null;
    47         $this->langsResolved = null;
    48         $this->issued = false;
    48         $this->issued = false;
    49         $this->modified = false;
    49         $this->modified = false;
    50         $this->created = false;
    50         $this->created = false;
    51     }
    51     }
    52 
    52 
    63             }
    63             }
    64         }
    64         }
    65         return $this->id;
    65         return $this->id;
    66     }
    66     }
    67 
    67 
    68     public function getLanguage() {
    68     public function getLanguages() {
    69         if(is_null($this->lang)) {
    69         if(is_null($this->langs)) {
    70             try {
    70             try {
    71                 $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>');
    72                 if(count($langs) > 0) {
    72             } catch(\Exception $e) {
    73                     $this->lang = $langs[0];
    73                 $this->langs = [];
    74                 }
    74             }
    75             } catch(\Exception $e) {
    75         }
    76                 $this->lang = null;
    76         return $this->langs;
    77             }
    77     }
    78         }
    78 
    79         return $this->lang;
    79     public function getLanguagesValue() {
    80     }
    80         return array_map(function($lang) {
    81 
    81             if($lang instanceof Resource) {
    82     public function getLanguageValue() {
    82                 return $lang->getUri();
    83         $lang = $this->getLanguage();
    83             } else if($lang instanceof Literal) {
    84         if($lang instanceof Resource) {
    84                 return $lang->getValue();
    85             return $lang->getUri();
    85             }
    86         } else if($lang instanceof Literal) {
    86         }, $this->getLanguages());
    87             return $lang->getValue();
    87     }
    88         }
    88 
    89         return null;
    89     public function getLanguagesResolved() {
    90     }
    90         return $this->langsResolved;
    91 
    91     }
    92     public function getLanguageResolved() {
    92 
    93         return $this->langResolved;
    93     public function setLanguagesResolved($languagesResolved) {
    94     }
    94         $this->langsResolved = $languagseResolved;
    95 
       
    96     public function setLanguageResolved($languageResolved) {
       
    97         $this->langResolved = $languageResolved;
       
    98     }
    95     }
    99 
    96 
   100 
    97 
   101     public function getTitle() {
    98     public function getTitle() {
   102         if($this->title === false) {
    99         if($this->title === false) {
   179         if($value && (!$modified || $modified->getValue() !== $value) ) {
   176         if($value && (!$modified || $modified->getValue() !== $value) ) {
   180 
   177 
   181             $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
   178             $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
   182             $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);
   183 
   180 
   184             $this->modified = null;
   181             $this->modified = false;
   185         }
   182         }
   186     }
   183     }
   187 
   184 
   188 
   185 
   189     public function getModifiedValue() {
   186     public function getModifiedValue() {
   200         } else {
   197         } else {
   201             $res = [
   198             $res = [
   202                 'id' => $this->getId(),
   199                 'id' => $this->getId(),
   203                 'uri' => $this->getUri(),
   200                 'uri' => $this->getUri(),
   204                 'title' => $this->getTitleValue(),
   201                 'title' => $this->getTitleValue(),
   205                 'language' => $this->getLanguageValue(),
   202                 'languages' => $this->getLanguagesValue(),
   206                 'modified' => $this->getModifiedValue(),
   203                 'modified' => $this->getModifiedValue(),
   207                 'issued' => $this->getIssuedValue()            ];
   204                 'issued' => $this->getIssuedValue()            ];
   208 
   205 
   209             if($this->language_resolved) {
   206             if($this->languagesResolved) {
   210                 $res['language_resolved'] = $this->getLanguageResolved();
   207                 $res['languages_resolved'] = $this->getLanguagesResolved();
   211             }
   208             }
   212 
   209 
   213             return $res;
   210             return $res;
   214         }
   211         }
   215     }
   212     }