server/src/app/Models/Document.php
changeset 18 f2a40bbc27f6
parent 4 f55970e41793
child 19 eadaf0b8f02e
equal deleted inserted replaced
17:ac3dc090e987 18:f2a40bbc27f6
     1 <?php
     1 <?php
     2 namespace CorpusParole\Models;
     2 namespace CorpusParole\Models;
     3 
     3 
     4 use Config;
     4 use Config;
     5 use CorpusParole\Libraries\Utils;
     5 use CorpusParole\Libraries\Utils;
       
     6 use CorpusParole\Libraries\CocoonUtils;
     6 use CorpusParole\Libraries\RdfModel\RdfModelResource;
     7 use CorpusParole\Libraries\RdfModel\RdfModelResource;
     7 use JsonSerializable;
     8 use JsonSerializable;
     8 use Log;
     9 use Log;
     9 use EasyRdf\Literal;
    10 use EasyRdf\Literal;
    10 use EasyRdf\Resource;
    11 use EasyRdf\Resource;
    24 
    25 
    25     private $id = null;
    26     private $id = null;
    26 
    27 
    27     public function getId() {
    28     public function getId() {
    28         if(is_null($this->id)) {
    29         if(is_null($this->id)) {
    29             $this->id = substr($this->uri, strlen(Config::get('corpusparole.cocoon_doc_id_base_uri')));
    30             $this->id = CocoonUtils::getIdFromUri($this->uri);
    30         }
    31         }
    31         return $this->id;
    32         return $this->id;
    32     }
    33     }
    33 
    34 
    34     public function getTitle() {
    35     public function getTitle() {
    57         } catch(\Exception $e) {
    58         } catch(\Exception $e) {
    58             // do nothing
    59             // do nothing
    59         }
    60         }
    60         foreach ($formats as $f) {
    61         foreach ($formats as $f) {
    61             $uri = $f->getUri();
    62             $uri = $f->getUri();
    62             $mimetype = Utils::get_mimetype($uri);
    63             $mimetype = Utils::getMimetype($uri);
    63             array_push($res, ["url" => $uri, "format" => $mimetype]);
    64             array_push($res, ["url" => $uri, "format" => $mimetype]);
    64         }
    65         }
    65 
    66 
    66         $format = null;
    67         $format = null;
    67         try {
    68         try {
   125                 'id' => $this->getId(),
   126                 'id' => $this->getId(),
   126             ];
   127             ];
   127         } else {
   128         } else {
   128             $mediaArray = array_map(
   129             $mediaArray = array_map(
   129                 function($m) {
   130                 function($m) {
   130                     $f = Utils::process_literal_or_string($m['format']);
   131                     $f = Utils::processLiteralOrString($m['format']);
   131                     return ['url' => $m['url'], 'format' => $f];},
   132                     return ['url' => $m['url'], 'format' => $f];},
   132                 $this->getMediaArray()
   133                 $this->getMediaArray()
   133             );
   134             );
   134 
   135 
   135             $publishers = array_map(
   136             $publishers = array_map(
   136                 function($v) { return Utils::process_literal_or_string($v); },
   137                 function($v) { return Utils::processLiteralOrString($v); },
   137                 $this->getPublishers()
   138                 $this->getPublishers()
   138             );
   139             );
   139 
   140 
   140             return [
   141             return [
   141                 'id' => $this->getId(),
   142                 'id' => $this->getId(),