server/src/app/Models/MediaResource.php
changeset 168 17f10b56c079
equal deleted inserted replaced
167:009efee954f7 168:17f10b56c079
       
     1 <?php
       
     2 namespace CorpusParole\Models;
       
     3 
       
     4 use CorpusParole\Libraries\RdfModel\RdfModelResource;
       
     5 use CorpusParole\Libraries\Utils;
       
     6 
       
     7 use JsonSerializable;
       
     8 use Log;
       
     9 
       
    10 
       
    11 /**
       
    12  */
       
    13 class MediaResource extends WebResource  {
       
    14 
       
    15     private $master = false;
       
    16     private $extent = -1;
       
    17     private $extentMs = -1;
       
    18 
       
    19     public function __construct(...$args) {
       
    20         //print($graph->dump('html'));
       
    21         parent::__construct(...$args);
       
    22         list(,,$master) = $args;
       
    23         $this->master = $master;
       
    24     }
       
    25 
       
    26     public function isMaster() {
       
    27         return $this->master;
       
    28     }
       
    29 
       
    30     protected function doClearMemoizationCache() {
       
    31         $this->extent = -1;
       
    32         $this->extentMs = -1;
       
    33     }
       
    34 
       
    35     public function getExtent() {
       
    36         if($this->extent === -1) {
       
    37             $extent = $this->getLiteral("<http://purl.org/dc/terms/extent>");
       
    38             $this->extent = is_null($extent)?null:$extent->getValue();
       
    39         }
       
    40 
       
    41         return $this->extent;
       
    42     }
       
    43 
       
    44     public function getExtentMs() {
       
    45         if($this->extentMs === -1 ) {
       
    46             $this->extentMs = Utils::iso8601IntervalToMillis($this->getExtent());
       
    47         }
       
    48         return $this->extentMs;
       
    49     }
       
    50 
       
    51 
       
    52     protected function jsonSerializeExtra() {
       
    53         return [
       
    54             'extent' => $this->getExtent(),
       
    55             'extent_ms' => $this->getExtentMs(),
       
    56             'master' => $this->isMaster()
       
    57         ];
       
    58     }
       
    59 
       
    60 }