server/src/app/Models/DocumentBase.php
author ymh <ymh.work@gmail.com>
Sat, 06 Aug 2016 21:27:53 +0700
changeset 260 64caee7ce38d
child 325 31a4987f6017
permissions -rw-r--r--
Split document model in document and document results
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Models;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use Config;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use CorpusParole\Libraries\Utils;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
use CorpusParole\Libraries\CocoonUtils;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
use CorpusParole\Libraries\RdfModel\RdfModelResource;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use JsonSerializable;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
use Log;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
use EasyRdf\Literal;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
use EasyRdf\Resource;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
use EasyRdf\Graph;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
/**
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 */
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
class DocumentBase extends RdfModelResource implements JsonSerializable {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    public function __construct($uri, $graph = null) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        //print($graph->dump('html'));
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        parent::__construct($uri, $graph);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    private $id = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    // memoization
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    private $providedCHO = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    private $title = false;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    private $lang = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    private $langResolved = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    private $issued = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    private $modified = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    public function getProvidedCHO() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        if(is_null($this->providedCHO)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
            $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        return $this->providedCHO;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    protected function clearMemoizationCache() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        $this->providedCHO = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        $this->title = false;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        $this->lang = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        $this->langResolved = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        $this->issued = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        $this->modified = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    public function getId() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        if(is_null($this->id)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
            $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
            foreach ($ids as $id) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
                if($id instanceof Literal && strpos($id->getValue(), config('corpusparole.corpus_id_scheme')) === 0) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
                    $this->id = $id->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
                }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
            if(is_null($this->id)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
                $this->id = CocoonUtils::getIdFromCorpusUri($this->uri);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        return $this->id;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    public function getLanguage() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        if(is_null($this->lang)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
                $langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
                if(count($langs) > 0) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
                    $this->lang = $langs[0];
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
                }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
                $this->lang = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        return $this->lang;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    public function getLanguageValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        $lang = $this->getLanguage();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
        if($lang instanceof Resource) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
            return $lang->getUri();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        } else if($lang instanceof Literal) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
            return $lang->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        return null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
    public function getLanguageResolved() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        return $this->langResolved;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    public function setLanguageResolved($languageResolved) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
        $this->langResolved = $languageResolved;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
    public function getTitle() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        if($this->title === false) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
                $this->title = $this->getProvidedCHO()->getLiteral('<http://purl.org/dc/elements/1.1/title>');
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
                $this->title = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        return $this->title;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
    public function setTitle($value, $lang="fr") {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        $oldTitle = $this->getTitle();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        if($oldTitle && $oldTitle->getValue() != $value && $oldTitle->getLang() != $lang) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
            $literalTitle = new Literal($value, $lang, null);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
            $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/title', $oldTitle, $literalTitle);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
            //clear cache
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
            $this->title = false;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    public function getTitleValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        $title = $this->getTitle();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        return is_null($title)?null:$title->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
    public function getIssued() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
        if(is_null($this->issued)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
                $this->issued = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/issued>");
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
                $this->issued = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        return $this->issued;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
    public function getIssuedValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        $issued = $this->getIssued();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
        return is_null($issued)?null:$issued->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
    public function getModified() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
        if(is_null($this->modified)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
                $this->modified = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/modified>");
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
                if(is_null($this->modified)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
                    $this->modified = $this->getIssued();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
                }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
                $this->modified = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        return $this->modified;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
    public function setModified($value = null) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
        if(is_null($value)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            $value = gmdate(\DateTime::ATOM);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
        } elseif ($value instanceof \DateTime) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
            $value = $value->format(\DateTime::ATOM);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $value);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
        $modified = $this->getModified();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
        if($value && (!$modified || $modified->getValue() !== $value) ) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
            $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
            $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
            $this->modified = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
    public function getModifiedValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
        $modified = $this->getModified();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
        return is_null($modified)?null:$modified->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
    public function jsonSerialize() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
        if(!$this->graph) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
            return [
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
                'id' => $this->getId(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
            ];
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
        } else {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            $res = [
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
                'id' => $this->getId(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
                'uri' => $this->getUri(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
                'title' => $this->getTitleValue(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
                'language' => $this->getLanguageValue(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
                'modified' => $this->getModifiedValue(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
                'issued' => $this->getIssuedValue()            ];
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
            if($this->language_resolved) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
                $res['language_resolved'] = $this->getLanguageResolved();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
            return $res;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
}