server/src/app/Models/DocumentBase.php
author ymh <ymh.work@gmail.com>
Tue, 11 Oct 2016 16:39:11 +0200
changeset 327 13564bb13ccc
parent 326 226d5b17a119
child 445 b1e5ad6b2a29
permissions -rw-r--r--
In the serialized document the lan files id 'languages' and not 'language'
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;
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    29
    private $langs = null;
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    30
    private $langsResolved = null;
325
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    31
    private $issued = false;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    32
    private $modified = false;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    33
    private $created = false;
260
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
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    public function getProvidedCHO() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        if(is_null($this->providedCHO)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
            $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
    39
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        return $this->providedCHO;
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
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    protected function clearMemoizationCache() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        $this->providedCHO = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        $this->title = false;
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    46
        $this->langs = null;
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    47
        $this->langsResolved = null;
325
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    48
        $this->issued = false;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    49
        $this->modified = false;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
    50
        $this->created = false;
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    public function getId() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        if(is_null($this->id)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
            $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
    56
            foreach ($ids as $id) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
                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
    58
                    $this->id = $id->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
                }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            if(is_null($this->id)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
                $this->id = CocoonUtils::getIdFromCorpusUri($this->uri);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
            }
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
        return $this->id;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    68
    public function getLanguages() {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    69
        if(is_null($this->langs)) {
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
            try {
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    71
                $this->langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
            } catch(\Exception $e) {
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    73
                $this->langs = [];
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        }
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    76
        return $this->langs;
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    79
    public function getLanguagesValue() {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    80
        return array_map(function($lang) {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    81
            if($lang instanceof Resource) {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    82
                return $lang->getUri();
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    83
            } else if($lang instanceof Literal) {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    84
                return $lang->getValue();
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    85
            }
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    86
        }, $this->getLanguages());
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    89
    public function getLanguagesResolved() {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    90
        return $this->langsResolved;
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    93
    public function setLanguagesResolved($languagesResolved) {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
    94
        $this->langsResolved = $languagseResolved;
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    }
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
    public function getTitle() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        if($this->title === false) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
                $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
   102
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
                $this->title = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
            }
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
        return $this->title;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
    }
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
    public function setTitle($value, $lang="fr") {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        $oldTitle = $this->getTitle();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        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
   112
            $literalTitle = new Literal($value, $lang, null);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
            $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
   114
            //clear cache
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
            $this->title = false;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        }
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
    public function getTitleValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
        $title = $this->getTitle();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        return is_null($title)?null:$title->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    }
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
    public function getIssued() {
325
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   127
        if($this->issued === false) {
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
                $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
   130
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
                $this->issued = null;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
            }
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
        return $this->issued;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
    }
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
    public function getIssuedValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
        $issued = $this->getIssued();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        return is_null($issued)?null:$issued->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
325
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   142
    public function getCreated() {
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   143
        if($this->created === false) {
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   144
            try {
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   145
                $this->created = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/created>");
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   146
            } catch(\Exception $e) {
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   147
                $this->created = null;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   148
            }
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   149
        }
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   150
        return $this->created;
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   151
    }
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   152
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
    public function getModified() {
325
31a4987f6017 Add fields to document index
ymh <ymh.work@gmail.com>
parents: 260
diff changeset
   154
        if($this->modified === false) {
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
            try {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
                $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
   157
                if(is_null($this->modified)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
                    $this->modified = $this->getIssued();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
                }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
            } catch(\Exception $e) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
                $this->modified = null;
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
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
        return $this->modified;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
    public function setModified($value = null) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
        if(is_null($value)) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
            $value = gmdate(\DateTime::ATOM);
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
        } elseif ($value instanceof \DateTime) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
            $value = $value->format(\DateTime::ATOM);
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
        $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $value);
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
        $modified = $this->getModified();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
        if($value && (!$modified || $modified->getValue() !== $value) ) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
            $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
   179
            $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
   180
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
   181
            $this->modified = false;
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
    public function getModifiedValue() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
        $modified = $this->getModified();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
        return is_null($modified)?null:$modified->getValue();
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
    public function jsonSerialize() {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
        if(!$this->graph) {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
            return [
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
                'id' => $this->getId(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
            ];
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
        } else {
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
            $res = [
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
                'id' => $this->getId(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
                'uri' => $this->getUri(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
                'title' => $this->getTitleValue(),
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
   202
                'languages' => $this->getLanguagesValue(),
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
                'modified' => $this->getModifiedValue(),
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
                'issued' => $this->getIssuedValue()            ];
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
   206
            if($this->languagesResolved) {
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 325
diff changeset
   207
                $res['languages_resolved'] = $this->getLanguagesResolved();
260
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
            }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
            return $res;
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
        }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
    }
64caee7ce38d Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
}