server/src/app/Models/MediaResource.php
author ymh <ymh.work@gmail.com>
Tue, 20 Mar 2018 15:02:40 +0100
changeset 573 25f3d28f51b2
parent 168 17f10b56c079
permissions -rw-r--r--
Added tag 0.0.25 for changeset 190ae1dee68d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Models;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use CorpusParole\Libraries\RdfModel\RdfModelResource;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use CorpusParole\Libraries\Utils;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
use JsonSerializable;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use Log;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
/**
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 */
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
class MediaResource extends WebResource  {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    private $master = false;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    private $extent = -1;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    private $extentMs = -1;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    public function __construct(...$args) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        //print($graph->dump('html'));
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        parent::__construct(...$args);
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        list(,,$master) = $args;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        $this->master = $master;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    public function isMaster() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        return $this->master;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    protected function doClearMemoizationCache() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        $this->extent = -1;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        $this->extentMs = -1;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    public function getExtent() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        if($this->extent === -1) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
            $extent = $this->getLiteral("<http://purl.org/dc/terms/extent>");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
            $this->extent = is_null($extent)?null:$extent->getValue();
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
        return $this->extent;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    public function getExtentMs() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        if($this->extentMs === -1 ) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
            $this->extentMs = Utils::iso8601IntervalToMillis($this->getExtent());
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        return $this->extentMs;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    protected function jsonSerializeExtra() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        return [
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
            'extent' => $this->getExtent(),
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
            'extent_ms' => $this->getExtentMs(),
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
            'master' => $this->isMaster()
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        ];
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
}