server/src/app/Models/DocumentBase.php
changeset 502 74fba571487e
parent 445 b1e5ad6b2a29
child 503 bd2701bd8142
equal deleted inserted replaced
501:7b2dcd2b31c1 502:74fba571487e
    20         //print($graph->dump('html'));
    20         //print($graph->dump('html'));
    21         parent::__construct($uri, $graph);
    21         parent::__construct($uri, $graph);
    22     }
    22     }
    23 
    23 
    24     private $id = null;
    24     private $id = null;
       
    25     private $cocoonId = null;
       
    26     private $countryCode = false;
    25 
    27 
    26     // memoization
    28     // memoization
    27     private $providedCHO = null;
    29     private $providedCHO = null;
    28     private $title = false;
    30     private $title = false;
    29     private $langs = null;
    31     private $langs = null;
    30     private $langsResolved = null;
    32     private $langsResolved = null;
    31     private $issued = false;
    33     private $issued = false;
    32     private $modified = false;
    34     private $modified = false;
    33     private $created = false;
    35     private $created = false;
    34 
    36 
    35 
       
    36     public function getProvidedCHO() {
    37     public function getProvidedCHO() {
    37         if(is_null($this->providedCHO)) {
    38         if(is_null($this->providedCHO)) {
    38             $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
    39             $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
    39         }
    40         }
    40         return $this->providedCHO;
    41         return $this->providedCHO;
    63             }
    64             }
    64         }
    65         }
    65         return $this->id;
    66         return $this->id;
    66     }
    67     }
    67 
    68 
       
    69     public function getCocoonId() {
       
    70         if(is_null($this->cocoonId)) {
       
    71             $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
       
    72             foreach ($ids as $id) {
       
    73                 if($id instanceof Literal && strpos($id->getValue(), config('corpusparole.cocoon_doc_id_base')) === 0) {
       
    74                     $this->cocoonId = substr($id->getValue(), strlen(config('corpusparole.cocoon_doc_id_base')));
       
    75                 }
       
    76             }
       
    77             if(is_null($this->cocoonId)) {
       
    78                 $this->id = CocoonUtils::getCocoonIdFromCorpusUri($this->uri);
       
    79             }
       
    80         }
       
    81         return $this->cocoonId;
       
    82     }
       
    83 
    68     public function getLanguages() {
    84     public function getLanguages() {
    69         if(is_null($this->langs)) {
    85         if(is_null($this->langs)) {
    70             try {
    86             try {
    71                 $this->langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
    87                 $this->langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
    72             } catch(\Exception $e) {
    88             } catch(\Exception $e) {
   190 
   206 
   191 
   207 
   192     public function getModifiedValue() {
   208     public function getModifiedValue() {
   193         $modified = $this->getModified();
   209         $modified = $this->getModified();
   194         return is_null($modified)?null:$modified->getValue();
   210         return is_null($modified)?null:$modified->getValue();
       
   211     }
       
   212 
       
   213     public function getCountryCode() {
       
   214         return $this->countryCode;
       
   215     }
       
   216 
       
   217     public function setCountryCode($code) {
       
   218         $this->countryCode = $code;
   195     }
   219     }
   196 
   220 
   197 
   221 
   198     public function jsonSerialize() {
   222     public function jsonSerialize() {
   199         if(!$this->graph) {
   223         if(!$this->graph) {
   201                 'id' => $this->getId(),
   225                 'id' => $this->getId(),
   202             ];
   226             ];
   203         } else {
   227         } else {
   204             $res = [
   228             $res = [
   205                 'id' => $this->getId(),
   229                 'id' => $this->getId(),
       
   230                 'cocoonId' => $this->getCocoonId(),
   206                 'uri' => $this->getUri(),
   231                 'uri' => $this->getUri(),
   207                 'title' => $this->getTitleValue(),
   232                 'title' => $this->getTitleValue(),
   208                 'languages' => $this->getLanguagesValue(),
   233                 'languages' => $this->getLanguagesValue(),
   209                 'modified' => $this->getModifiedValue(),
   234                 'modified' => $this->getModifiedValue(),
   210                 'issued' => $this->getIssuedValue(),
   235                 'issued' => $this->getIssuedValue(),
   212             ];
   237             ];
   213 
   238 
   214             if($this->languagesResolved) {
   239             if($this->languagesResolved) {
   215                 $res['languages_resolved'] = $this->getLanguagesResolved();
   240                 $res['languages_resolved'] = $this->getLanguagesResolved();
   216             }
   241             }
       
   242             if($this->getCountryCode() !== false) {
       
   243                 $res['countryCode'] = $this->getCountryCode();
       
   244             }
   217 
   245 
   218             return $res;
   246             return $res;
   219         }
   247         }
   220     }
   248     }
   221 }
   249 }