server/src/app/Repositories/RdfDocumentRepository.php
changeset 28 b0b56e0f8c7f
parent 22 a50cbd7d702f
child 122 b37fde30dd4a
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
    38             $newGraph = new Graph($doc->uri->getUri());
    38             $newGraph = new Graph($doc->uri->getUri());
    39             $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation"));
    39             $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation"));
    40             $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc);
    40             $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc);
    41             $newGraph->add($doc->doc, "rdf:type", $newGraph->resource("http://www.europeana.eu/schemas/edm/ProvidedCHO"));
    41             $newGraph->add($doc->doc, "rdf:type", $newGraph->resource("http://www.europeana.eu/schemas/edm/ProvidedCHO"));
    42             $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/title", $doc->title);
    42             $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/title", $doc->title);
       
    43             if(isset($doc->lang)) {
       
    44                 $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/language", $doc->lang);
       
    45             }
    43             if(isset($doc->issued)) {
    46             if(isset($doc->issued)) {
    44                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued);
    47                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued);
    45             }
    48             }
    46             if(isset($doc->modified)) {
    49             if(isset($doc->modified)) {
    47                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified);
    50                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified);
    53     }
    56     }
    54 
    57 
    55     public function all() {
    58     public function all() {
    56 
    59 
    57         return $this->queryDocs(
    60         return $this->queryDocs(
    58         "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified".
    61         "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified ?lang".
    59         "    WHERE {".
    62         "    WHERE {".
    60         "        GRAPH ?uri { ?doc a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.".
    63         "        GRAPH ?uri { ?doc a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.".
    61         "        ?doc <http://purl.org/dc/elements/1.1/title> ?title.".
    64         "        ?doc <http://purl.org/dc/elements/1.1/title> ?title.".
       
    65         "        OPTIONAL {?doc <http://purl.org/dc/elements/1.1/language> ?lang.} ".
    62         "        OPTIONAL {?doc <http://purl.org/dc/terms/issued> ?issued.} ".
    66         "        OPTIONAL {?doc <http://purl.org/dc/terms/issued> ?issued.} ".
    63         "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
    67         "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
    64         "    } ORDER BY ?uri"
    68         "    } ORDER BY ?uri"
    65         );
    69         );
    66     }
    70     }
    77         //TODO: return null if not found
    81         //TODO: return null if not found
    78         if($doc->isEmpty()) {
    82         if($doc->isEmpty()) {
    79             return null;
    83             return null;
    80         }
    84         }
    81 
    85 
    82         return new Document($docUri, $doc);
    86         // clone the graph to force the URI
       
    87         return new Document($docUri, new Graph($docUri, $doc->toRdfPhp()));
    83 
    88 
    84     }
    89     }
    85 
    90 
    86     /**
    91     /**
    87      * save document.
    92      * save document.
   141         $total = $this->getCount();
   146         $total = $this->getCount();
   142 
   147 
   143         $offset = max(0,($page - 1) * $perPage);
   148         $offset = max(0,($page - 1) * $perPage);
   144 
   149 
   145         $query =
   150         $query =
   146             "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified".
   151             "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified ?lang".
   147             "    WHERE {".
   152             "    WHERE {".
   148             "        GRAPH ?uri { ?doc a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.".
   153             "        GRAPH ?uri { ?doc a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.".
   149             "        ?doc <http://purl.org/dc/elements/1.1/title> ?title.".
   154             "        ?doc <http://purl.org/dc/elements/1.1/title> ?title.".
       
   155             "        OPTIONAL {?doc <http://purl.org/dc/elements/1.1/language> ?lang.} ".
   150             "        OPTIONAL {?doc <http://purl.org/dc/terms/issued> ?issued.} ".
   156             "        OPTIONAL {?doc <http://purl.org/dc/terms/issued> ?issued.} ".
   151             "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
   157             "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
   152             "    } ORDER BY ?uri OFFSET $offset LIMIT $perPage";
   158             "    } ORDER BY ?uri OFFSET $offset LIMIT $perPage";
   153 
   159 
   154         $results = $this->queryDocs($query);
   160         $results = $this->queryDocs($query);