server/src/app/Models/Document.php
author ymh <ymh.work@gmail.com>
Fri, 04 Mar 2016 10:08:52 +0100
changeset 138 3079cbf80006
parent 130 fac22d8c2df8
child 141 c0e8626a271c
permissions -rw-r--r--
add subjects save + set modified date when saing document in rest api
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Models;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use Config;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use CorpusParole\Libraries\Utils;
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
     6
use CorpusParole\Libraries\CocoonUtils;
3
2b3247d02769 Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
     7
use CorpusParole\Libraries\RdfModel\RdfModelResource;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
     8
use JsonSerializable;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
use Log;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    10
use EasyRdf\Literal;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    11
use EasyRdf\Resource;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    12
use EasyRdf\Graph;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    13
use EasyRdf\Isomorphic;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    14
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
/**
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    17
 * Model class for Document. Inherit from EasyRd\Resource
3
2b3247d02769 Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    18
 * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 */
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    20
class Document extends RdfModelResource implements JsonSerializable {
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    public function __construct($uri, $graph = null) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    23
        //print($graph->dump('html'));
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    24
        parent::__construct($uri, $graph);
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    private $id = null;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    29
    // memoization
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    30
    private $providedCHO = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    31
    private $title = false;
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    32
    private $lang = null;
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    33
    private $langResolved = null;
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    34
    private $publishers = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    35
    private $mediaArray = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    36
    private $issued = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    37
    private $modified = null;
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    38
    private $contributors = null;
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
    39
    private $subjects = null;
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    40
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    41
    public function getProvidedCHO() {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    42
        if(is_null($this->providedCHO)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    43
            $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>");
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    44
        }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    45
        return $this->providedCHO;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    46
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    47
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    48
    private function clearMemoizationCache() {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    49
        $this->providedCHO = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    50
        $this->title = false;
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    51
        $this->lang = null;
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    52
        $this->langResolved = null;
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    53
        $this->publishers = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    54
        $this->mediaArray = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    55
        $this->issued = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
        $this->modified = null;
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    57
        $this->contributors = null;
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
    58
        $this->subjects = null;
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    59
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    60
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    public function getId() {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        if(is_null($this->id)) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    63
            $ids = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/identifier>');
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    64
            foreach ($ids as $id) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    65
                if($id instanceof Literal && strpos($id->getValue(), config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    66
                    $this->id = $id->getValue();
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    67
                }
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 115
diff changeset
    68
            }
115
34ffc04cef62 add dc:identifier to providedCHO
ymh <ymh.work@gmail.com>
parents: 111
diff changeset
    69
            if(is_null($this->id)) {
34ffc04cef62 add dc:identifier to providedCHO
ymh <ymh.work@gmail.com>
parents: 111
diff changeset
    70
                $this->id = CocoonUtils::getIdFromCorpusUri($this->uri);
34ffc04cef62 add dc:identifier to providedCHO
ymh <ymh.work@gmail.com>
parents: 111
diff changeset
    71
            }
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
        }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        return $this->id;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    76
    public function getLanguage() {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    77
        if(is_null($this->lang)) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    78
            try {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    79
                $langs = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/language>');
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    80
                if(count($langs) > 0) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    81
                    $this->lang = $langs[0];
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    82
                }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    83
            } catch(\Exception $e) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    84
                $this->lang = null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    85
            }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    86
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    87
        return $this->lang;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    88
    }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    89
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    90
    public function getLanguageValue() {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    91
        $lang = $this->getLanguage();
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    92
        if($lang instanceof Resource) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    93
            return $lang->getUri();
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    94
        } else if($lan instanceof Literal) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    95
            return $lang->getValue();
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    96
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    97
        return null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    98
    }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    99
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   100
    public function getLanguageResolved() {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   101
        return $this->langResolved;
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   102
    }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   103
    public function setLanguageResolved($languageResolved) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   104
        $this->langResolved = $languageResolved;
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   105
    }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   106
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   107
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    public function getTitle() {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   109
        if($this->title === false) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   110
            try {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   111
                $this->title = $this->getProvidedCHO()->getLiteral('<http://purl.org/dc/elements/1.1/title>');
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   112
            } catch(\Exception $e) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   113
                $this->title = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   114
            }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   115
        }
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   116
        return $this->title;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   119
    public function setTitle($value, $lang="fr") {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   120
        $oldTitle = $this->getTitle();
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   121
        if($oldTitle && $oldTitle->getValue() != $value && $oldTitle->getLang() != $lang) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   122
            $literalTitle = new Literal($value, $lang, null);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   123
            $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/title', $oldTitle, $literalTitle);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   124
            //clear cache
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   125
            $this->title = false;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   126
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   127
    }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   128
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   129
    public function getTitleValue() {
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   130
        $title = $this->getTitle();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   131
        return is_null($title)?null:$title->getValue();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   132
    }
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   133
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
    public function getPublishers() {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   135
        if(is_null($this->publishers)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   136
            try {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   137
                $this->publishers = $this->getProvidedCHO()->all('dc11:publisher');
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   138
            } catch(\Exception $e) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   139
               $this->publishers = [];
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   140
            }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   141
        }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   142
        return $this->publishers;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   143
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   144
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   145
    public function getIssued() {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   146
        if(is_null($this->issued)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   147
            try {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   148
                $this->issued = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/issued>");
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   149
            } catch(\Exception $e) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   150
                $this->issued = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   151
            }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   152
        }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   153
        return $this->issued;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   154
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   155
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   156
    public function getIssuedValue() {
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   157
        $issued = $this->getIssued();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   158
        return is_null($issued)?null:$issued->getValue();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   159
    }
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   160
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   161
    public function getModified() {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   162
        if(is_null($this->modified)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   163
            try {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   164
                $this->modified = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/modified>");
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   165
                if(is_null($this->modified)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   166
                    $this->modified = $this->getIssued();
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   167
                }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   168
            } catch(\Exception $e) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   169
                $this->modified = null;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   170
            }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   171
        }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   172
        return $this->modified;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   175
    public function getModifiedValue() {
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   176
        $modified = $this->getModified();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   177
        return is_null($modified)?null:$modified->getValue();
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   178
    }
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   179
138
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   180
    public function setModified($value = null) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   181
        if(is_null($value)) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   182
            $value = gmdate(\DateTime::ATOM);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   183
        } elseif ($value instanceof \DateTime) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   184
            $value = $value->format(\DateTime::ATOM);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   185
        }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   186
        $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $value);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   187
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   188
        $modified = $this->getModified();
138
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   189
        if($value && (!$modified || $modified->getValue() !== $value) ) {
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   190
138
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   191
            $newModified = new Literal($value, null, "http://purl.org/dc/terms/W3CDTF");
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   192
            $this->setSimpleProperty($this->getProvidedCHO(), 'http://purl.org/dc/terms/modified', $modified, $newModified);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   193
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   194
            $this->modified = null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   195
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   196
    }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   197
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
    public function getMediaArray() {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   200
        if(is_null($this->mediaArray)) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   201
            //TODO: add media type
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   202
            $this->mediaArray = [];
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   203
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   204
            $master = $this->get('<http://www.europeana.eu/schemas/edm/isShownBy>');
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   205
            $masterUrl = is_null($master)?null:$master->getUri();
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   206
111
af85c436048f change edm:WebResources to edm:WebResources
ymh <ymh.work@gmail.com>
parents: 28
diff changeset
   207
            foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResource>") as $webResource) {
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   208
                $extent = $webResource->getLiteral("<http://purl.org/dc/terms/extent>");
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   209
                $extent = is_null($extent)?null:$extent->getValue();
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   210
                $extent_ms = Utils::iso8601IntervalToMillis($extent);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   211
                $format = $webResource->getLiteral("dc11:format");
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   212
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   213
                $this->mediaArray[$webResource->getUri()] = [
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   214
                    'url' => $webResource->getUri(),
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   215
                    'format' => is_null($format)?null:$format->getValue(),
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   216
                    'extent' => $extent,
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   217
                    'extent_ms' => $extent_ms,
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   218
                    'master' => (($webResource->getUri() === $masterUrl)?true:false)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   219
                ];
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   220
            }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   221
        }
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   222
        return $this->mediaArray;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
    public function getTypes() {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   226
        return $this->getProvidedCHO()->all('dc11:type');
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
    public function getDiscourseTypes() {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
        return array_values(array_filter($this->getTypes(), function($v) {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   231
            return $v instanceof Literal && $v->getDatatypeUri() === Config::get('corpusparole.olac_discourse_type')['uri'];
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
        }));
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
    public function getOtherTypes() {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
        $res = array_values(array_filter($this->getTypes(), function($v) {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   237
            return $v instanceof Resource || $v->getDatatypeUri() !== Config::get('corpusparole.olac_discourse_type')['uri'];
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
        }));
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
        return $res;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   242
    public function getContributors() {
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   243
        if(is_null($this->contributors)) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   244
            $this->contributors = array_reduce(
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   245
                CocoonUtils::OLAC_ROLES,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   246
                function($res, $olacRole) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   247
                    return array_merge(
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   248
                        $res,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   249
                        array_map(
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   250
                            function($olacValue) use ($olacRole) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   251
                                return [
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   252
                                    'name' => ($olacValue instanceof Literal)?$olacValue->getValue():null,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   253
                                    'nameLiteral' => ($olacValue instanceof Literal)?$olacValue:null,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   254
                                    'url' => ($olacValue instanceof Resource)?$olacValue->getUri():null,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   255
                                    'role' => $olacRole
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   256
                                ];
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   257
                            },
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   258
                            $this->getProvidedCHO()->all("<$olacRole>")
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   259
                        )
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   260
                    );
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   261
                },
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   262
                []
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   263
            );
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   264
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   265
        return $this->contributors;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   266
    }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   267
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   268
    /**
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   269
     * change contributors list
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   270
     */
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   271
    public function setContributors($contributors) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   272
        $delta = $this->startDelta();
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   273
        //remove old,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   274
        foreach ($this->getContributors() as $contribDef) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   275
            $value = null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   276
            if (is_null($contribDef['url'])) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   277
                if(is_null($contribDef['nameLiteral'])) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   278
                    $value = new Literal($contribDef['name']);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   279
                } else {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   280
                    $value = $contribDef['nameLiteral'];
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   281
                }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   282
            } else {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   283
                $value = new Resource($contribDef['url']);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   284
            }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   285
            $this->getProvidedCHO()->delete($contribDef['role'], $value);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   286
            $delta->getDeletedGraph()->add($this->getProvidedCHO(), $contribDef['role'], $value);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   287
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   288
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   289
        //put new
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   290
        foreach ($contributors as $newContribDef) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   291
            $value = null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   292
            if (is_null($newContribDef['url'])) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   293
                $value = new Literal($newContribDef['name'], "fr", null);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   294
            } else {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   295
                $value = new Resource($newContribDef['url']);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   296
            }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   297
            $this->getProvidedCHO()->add($newContribDef['role'], $value);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   298
            $delta->getAddedGraph()->add($this->getProvidedCHO(), $newContribDef['role'], $value);
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   299
        }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   300
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   301
        $this->contributors = null;
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   302
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   303
    }
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   304
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   305
    /**
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   306
     * change discourse type list
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   307
     */
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
    public function updateDiscourseTypes(array $discoursesTypes) {
3
2b3247d02769 Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   309
2b3247d02769 Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   310
        $this->startDelta();
2b3247d02769 Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   311
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   312
        //delete
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
        foreach($this->getDiscourseTypes() as $discourseType) {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   314
            $literalValue = new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri']);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   315
            $this->getProvidedCHO()->delete('dc11:type', $literalValue);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   316
            $this->currentDelta->getDeletedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
        }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   319
        // and re-add them
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
        foreach($discoursesTypes as $dType) {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   321
            $this->getProvidedCHO()->add('dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   322
            $this->currentDelta->getAddedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
        }
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   324
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   325
        $this->clearMemoizationCache();
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   328
    /**
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   329
     * Get subjects list
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   330
     */
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   331
    public function getSubjects() {
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   332
        if(is_null($this->subjects)) {
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   333
            $this->subjects = $this->getProvidedCHO()->all('<http://purl.org/dc/elements/1.1/subject>');
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   334
        }
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   335
        return $this->subjects;
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   336
    }
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   337
138
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   338
    /**
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   339
     * change subjecs list
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   340
     */
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   341
    public function setSubjects($subjects) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   342
        $delta = $this->startDelta();
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   343
        //remove old,
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   344
        foreach ($this->getSubjects() as $subject) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   345
            $this->getProvidedCHO()->delete('<http://purl.org/dc/elements/1.1/subject>', $subject);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   346
            $delta->getDeletedGraph()->add($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/subject', $subject);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   347
        }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   348
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   349
        //put new
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   350
        foreach ($subjects as $newSubject) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   351
            $value = null;
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   352
            if(filter_var($newSubject, FILTER_VALIDATE_URL)) {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   353
                $value = new Resource($newSubject);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   354
            }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   355
            else {
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   356
                $value = new Literal($newSubject, "fr", null);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   357
            }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   358
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   359
            $this->getProvidedCHO()->add('http://purl.org/dc/elements/1.1/subject', $value);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   360
            $delta->getAddedGraph()->add($this->getProvidedCHO(), 'http://purl.org/dc/elements/1.1/subject', $value);
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   361
        }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   362
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   363
        $this->subjects = null;
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   364
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   365
    }
3079cbf80006 add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   366
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
    public function isIsomorphic($doc) {
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   368
        return Isomorphic::isomorphic($this->graph, $doc->graph);
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
    /*
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
     * Clone document.
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
     * clone also the innerDocumenent
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
     */
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
    public function __clone() {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   377
        $this->graph = new Graph($this->graph->getUri(), $this->graph->toRdfPhp());
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   378
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   379
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   380
    public function jsonSerialize() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   381
        if(!$this->graph) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   382
            return [
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   383
                'id' => $this->getId(),
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   384
            ];
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   385
        } else {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   386
            $mediaArray = array_map(
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   387
                function($m) {
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   388
                    $f = Utils::processLiteralResourceOrString($m['format']);
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   389
                    $res = $m;
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   390
                    $res['format'] = $f;
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   391
                    return $res;},
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   392
                $this->getMediaArray()
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   393
            );
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   394
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   395
            $publishers = array_map(
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   396
                function($v) { return Utils::processLiteralResourceOrString($v); },
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   397
                $this->getPublishers()
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   398
            );
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   399
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   400
            $contributors = array_map(
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   401
                function($c) { unset($c['nameLiteral']); return $c; },
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   402
                $this->getContributors()
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   403
            );
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   404
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   405
            $subjects = array_map(
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   406
                function($s) { return Utils::processLiteralResourceOrString($s); },
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   407
                $this->getSubjects()
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   408
            );
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   409
128
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   410
            $res = [
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   411
                'id' => $this->getId(),
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   412
                'uri' => $this->getUri(),
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   413
                'title' => $this->getTitleValue(),
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   414
                'language' => $this->getLanguageValue(),
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   415
                'modified' => $this->getModifiedValue(),
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   416
                'publishers' => $publishers,
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   417
                'contributors' => $contributors,
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
   418
                'subjects' => $subjects,
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   419
                'mediaArray'=> $mediaArray
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   420
            ];
128
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   421
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   422
            if($this->language_resolved) {
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   423
                $res['language_resolved'] = $this->getLanguageResolved();
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   424
            }
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   425
bc18286e55b2 remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   426
            return $res;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   427
        }
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
}