server/src/app/Repositories/RdfDocumentRepository.php
author ymh <ymh.work@gmail.com>
Wed, 28 Sep 2016 17:24:02 +0200
changeset 306 3fccf43160a7
parent 277 bd4bc1db4f40
child 326 226d5b17a119
permissions -rw-r--r--
Some more changes linked to the change of api organization + some jshint error cleaning
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
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
namespace CorpusParole\Repositories;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use Config;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
use Log;
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
     7
use CorpusParole\Models\DocumentResult;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use CorpusParole\Models\Document;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
     9
use CorpusParole\Libraries\CorpusParoleException;
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    10
use CorpusParole\Libraries\Utils;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    11
use CorpusParole\Libraries\Sparql\SparqlClient;
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    12
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    13
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    14
use CorpusParole\Services\LexvoResolverInterface;
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    15
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    16
use EasyRdf\Graph;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    17
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    18
use Illuminate\Pagination\LengthAwarePaginator;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    19
use Illuminate\Pagination\Paginator;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
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
 * Implement the DocumentRepository using EasyRdf
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    23
 * TODO: certainly split the transaction management (+add, +delete +transaction ) to an external class -> for this extend the sparql client.
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 */
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
class RdfDocumentRepository implements DocumentRepository {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    27
    const BASE_DOC_QUERY
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    28
        = "SELECT".
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    29
        "    ?uri".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    30
        "    ?doc".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    31
        "    ?title".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    32
        "    ?issued".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    33
        "    ?modified".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    34
        "    ?lang".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    35
        "    (group_concat(distinct ?publisher;separator=\", \") as ?publishers) ".
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    36
        "  WHERE {".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    37
        "  GRAPH ?uri { ?doc a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.".
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    38
        "    ?doc <http://purl.org/dc/elements/1.1/title> ?title.".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    39
        "    OPTIONAL {?doc <http://purl.org/dc/elements/1.1/language> ?lang.} ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    40
        "    OPTIONAL {?doc <http://purl.org/dc/terms/issued> ?issued.} ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    41
        "    OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    42
        "    OPTIONAL {?doc <http://purl.org/dc/elements/1.1/publisher> ?publisher.} }".
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    43
        "  } ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    44
        "  GROUP BY ?uri ?doc ?title ?issued ?modified ?lang ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    45
        "  ORDER BY ?uri";
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    46
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    47
    const ADDITIONAL_DOC_QUERIES = [
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    48
        "SELECT".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    49
        "    ?uri".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    50
        "    ?doc".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    51
        "    (sample(distinct ?ext) as ?extent) ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    52
        "WHERE {".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    53
        "    GRAPH ?uri {".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    54
        "        ?s a <http://www.europeana.eu/schemas/edm/WebResource>. ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    55
        "        ?uri <http://www.europeana.eu/schemas/edm/isShownBy> ?s. ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    56
        "        ?uri <http://www.europeana.eu/schemas/edm/aggregatedCHO> ?doc. ".
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    57
        "        OPTIONAL {?s <http://purl.org/dc/terms/extent> ?ext.}".
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    58
        "    }. ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    59
        "    %s".
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    60
        "} ".
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    61
        "GROUP BY ?uri ?doc",
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    62
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    63
        "SELECT".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    64
        "    ?uri".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    65
        "    ?doc".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    66
        "    (sample(distinct str(?s)) as ?transcript_url) ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    67
        "WHERE {".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    68
        "    GRAPH ?uri {".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    69
        "        ?s a <http://www.europeana.eu/schemas/edm/WebResource>. ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    70
        "        ?uri <http://www.europeana.eu/schemas/edm/aggregatedCHO> ?doc. ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    71
        "        OPTIONAL {?s <http://purl.org/dc/elements/1.1/format> ?f.} ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    72
        "    }. ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    73
        "    FILTER(str(?f) IN ( \"application/xml\", \"application/pdf\" )). ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    74
        "    %s".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    75
        "} ".
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
    76
        "GROUP BY ?uri ?doc"
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    77
    ];
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    78
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    private $sparqlClient;
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    80
    private $lexvoResolver;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    82
    public function __construct(SparqlClient $sparqlClient, LexvoResolverInterface $lexvoResolver) {
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    83
        $this->sparqlClient = $sparqlClient;
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    84
        $this->lexvoResolver = $lexvoResolver;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    87
    public function getSparqlClient() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    88
        return $this->sparqlClient;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    89
    }
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    91
    private function getResGraph($doc) {
276
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    92
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    93
        if(empty((array)$doc)) {
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    94
            return null;
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    95
        }
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    96
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    97
        $newGraph = new Graph($doc->uri->getUri());
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    98
        $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation"));
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    99
        $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   100
        $newGraph->add($doc->doc, "rdf:type", $newGraph->resource("http://www.europeana.eu/schemas/edm/ProvidedCHO"));
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   101
        if(isset($doc->title)) {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   102
            $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/title", $doc->title);
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   103
        }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   104
        if(isset($doc->lang)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   105
            $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/language", $doc->lang);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   106
        }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   107
        if(isset($doc->issued)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   108
            $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   109
        }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   110
        if(isset($doc->modified)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   111
            $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   112
        }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   113
        if(isset($doc->publishers)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   114
            $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/publisher", $doc->publishers);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   115
        }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   116
        if(isset($doc->extent)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   117
            $newGraph->add($doc->doc, "http://purl.org/dc/terms/extent", $doc->extent);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   118
        }
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   119
        if(isset($doc->transcript_url)) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   120
            $newGraph->add($doc->doc, config('corpusparole.corpus_ontology_url').'transcript', $doc->transcript_url);
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   121
        }
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   122
        return $newGraph;
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   123
    }
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   124
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   125
    private function queryDocs($offset=null, $limit=null) {
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   126
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   127
        $resDocs = [];
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   128
        $limitsClauses = [];
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   129
        $limitsClausesStr = "";
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   130
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   131
        if(!is_null($offset)) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   132
            array_push($limitsClauses, "OFFSET $offset");
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   133
        }
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   134
        if(!is_null($limit)) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   135
            array_push($limitsClauses, "LIMIT $limit");
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   136
        }
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   137
        if(!empty($limitsClauses)) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   138
            $limitsClausesStr = "\n" . join(" ", $limitsClauses);
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   139
        }
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   140
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   141
        $docs = $this->sparqlClient->query(self::BASE_DOC_QUERY.$limitsClausesStr);
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   142
        foreach($docs as $doc) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   143
            $graph = $this->getResGraph($doc);
276
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   144
            if(is_null($graph)) {
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   145
                continue;
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   146
            }
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   147
            $uri = $doc->uri->getUri();
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   148
            $resDocs[$uri] = $graph;
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   149
        }
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   150
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   151
        if(count($resDocs) == 0) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   152
            return [];
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   153
        }
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   154
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   155
        $filterUris = "FILTER(?uri in (<".join(">, <" , array_keys($resDocs)).">)) ";
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   156
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   157
        foreach(self::ADDITIONAL_DOC_QUERIES as $query) {
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   158
            $docs = $this->sparqlClient->query(sprintf($query, $filterUris));
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   159
            foreach($docs as $doc) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   160
                $graph = $this->getResGraph($doc);
276
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   161
                if(is_null($graph)) {
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   162
                    continue;
ef32bf573d9c correct error in test with empty document returned by query
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   163
                }
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   164
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   165
                $uri = $doc->uri->getUri();
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   166
                if(array_key_exists($uri, $resDocs)) {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   167
                    $resDocs[$uri] = Utils::mergeGraphs($resDocs[$uri], $graph);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   168
                } else {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   169
                    $resDocs[$uri] = $graph;
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   170
                }
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 22
diff changeset
   171
            }
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
        }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   174
        return array_map(function($g) { return new DocumentResult($g->getUri(), $g); }, array_values($resDocs));
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   177
    public function all() {
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   178
        return $this->queryDocs();
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   179
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   180
306
3fccf43160a7 Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   181
    public function get($id, $short=false) {
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 28
diff changeset
   183
        if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 28
diff changeset
   184
            $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 28
diff changeset
   185
        }
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   186
        $docUri = Config::get('corpusparole.corpus_doc_id_base_uri').$id;
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
        // We want the CBD (Concise Bounded Description, cf. http://www.w3.org/Submission/CBD/)
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
        // WARNING: This seems to work in sesame for our dataset.
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
        $doc = $this->sparqlClient->query(
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   191
            "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <$docUri> { ?s ?p ?o } }"
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
        );
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   193
        //TODO: return null if not found
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   194
        if($doc->isEmpty()) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   195
            return null;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   196
        }
169
8fddc113095e Correct proble on geo info merging + add geo resource
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   197
        //print($doc->dump());
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents: 22
diff changeset
   199
        // clone the graph to force the URI
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   200
        $DocumentKlass = $short?DocumentResult::class:Document::class;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
   201
        return new $DocumentKlass($docUri, new Graph($docUri, $doc->toRdfPhp()));
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
    }
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   205
    /**
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   206
     * save document.
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   207
     * @return boolean true if a transaction was started, false otherwise
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   208
     * @throws CorpusParoleException if one of the operation could not be performed
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   209
     */
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   210
    public function save(Document $doc) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   211
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   212
        $transactionStarted = $this->sparqlClient->startTransaction();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   213
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   214
        try {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   215
            foreach($doc->getDeltaList() as $delta) {
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 276
diff changeset
   216
                $this->sparqlClient->deleteWhere($delta->getDeleteWhere(), $delta->getUri());
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   217
                $this->sparqlClient->delete($delta->getDeletedGraph());
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   218
                $this->sparqlClient->add($delta->getAddedGraph());
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   219
            }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   220
            if($transactionStarted) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   221
                $transactionStarted = false;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   222
                return $this->sparqlClient->commit();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   223
            }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   224
            else  {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   225
                return false;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   226
            }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   227
        }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   228
        catch(CorpusParoleException $e) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   229
            if($transactionStarted) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   230
                $this->sparqlClient->rollback();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   231
            }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   232
            throw $e;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   233
        }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   234
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   235
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   236
    public function getCount() {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   237
        $res = $this->sparqlClient->query("SELECT (COUNT (DISTINCT ?g) as ?count) WHERE { GRAPH ?g { ?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO> } }");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   238
        assert(!is_null($res) && $res->count()==1);
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   239
        return $res[0]->count->getValue();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   240
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   241
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   242
    //SELECT ?g WHERE { GRAPH ?g { ?s ?p ?o } }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   243
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   244
    /**
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   245
     * Paginate all document as a paginator.
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   246
     *
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   247
     * @param  int  $perPage
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   248
     * @param  string  $pageName
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   249
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   250
     */
22
a50cbd7d702f small change in pagination and add missing .env template
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   251
    public function paginateAll($perPage = 15, $pageName = 'page', $page = null)
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   252
    {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   253
        assert(is_numeric($perPage));
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   254
22
a50cbd7d702f small change in pagination and add missing .env template
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   255
        if(is_null($page)) {
a50cbd7d702f small change in pagination and add missing .env template
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   256
            $page = Paginator::resolveCurrentPage($pageName);
a50cbd7d702f small change in pagination and add missing .env template
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   257
        }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   258
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   259
        assert(is_null($page) || is_numeric($page));
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   260
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   261
        $total = $this->getCount();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   262
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   263
        $offset = max(0,($page - 1) * $perPage);
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   264
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   265
        $results = $this->queryDocs($offset, $perPage);
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   266
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   267
        return new LengthAwarePaginator($results, $total, $perPage, $page, [
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   268
            'path' => Paginator::resolveCurrentPath(),
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   269
            'pageName' => $pageName,
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   270
        ]);
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   271
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
   272
125
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   273
    /**
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   274
     * Resolve lexvo id for all documents in the list
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   275
     * this allow to optimise the call of lexvo repository
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   276
     * @param $docList Array: a list (Array) of document to resolve
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   277
     */
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   278
    public function resolveLexvo(Array $docList) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   279
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   280
        $languageIds = [];
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   281
        #get the list pf language needing resolving
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   282
        foreach ($docList as $doc) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   283
            if($doc->getLanguageValue() && is_null($doc->getLanguageResolved())) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   284
                $languageIds[$doc->getLanguageValue()] = true;
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   285
            }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   286
        }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   287
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   288
        # call LexvoResolver
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   289
        $langNames = $this->lexvoResolver->getNames(array_keys($languageIds));
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   290
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   291
        foreach ($docList as $doc) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   292
            if($doc->getLanguageValue() && is_null($doc->getLanguageResolved())) {
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   293
                $doc->setLanguageResolved($langNames[$doc->getLanguageValue()]);
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   294
            }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   295
        }
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   296
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   297
        return $docList;
e550b10fe3ca add language resolver on api data
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   298
    }
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
}