Commit 89966eb7 authored by Matthias Tietz's avatar Matthias Tietz
Browse files

use tisaf:uri in /narrower example

parent b11b4aad
......@@ -48,6 +48,23 @@ class RestController extends Controller
),
);
private static function addTisafUriForConcepts(Vocabulary $voc, $conceptUris, $lang)
{
foreach ($conceptUris as $key => $value) {
$concepts = $voc->getConceptInfo($key, $lang);
if (sizeof($concepts) == 1) {
$concept = $concepts[0];
// tisaf:uri, if existing (see tisafUriMigration)
$tisafUri = $concept->getTisafUri();
if (!empty($tisafUri)) {
$conceptUris[$key]["tisaf:uri"] = $tisafUri;
}
}
}
return $conceptUris;
}
/**
* Handles json encoding, adding the content type headers and optional callback function.
* @param array $data the data to be returned.
......@@ -1122,6 +1139,7 @@ class RestController extends Controller
{
$results = array();
foreach ($objects as $objuri => $vals) {
$objuri = !empty($vals["tisaf:uri"]) ? $vals["tisaf:uri"] : $objuri;
$results[] = array('uri' => $objuri, 'prefLabel' => $vals['label']);
}
......@@ -1228,24 +1246,40 @@ EOD;
}
}
// add to narrowers array.
$narrowers = array_merge($narrowers, $narrowersTwin);
$narrowers = self::addTisafUriForConcepts($vocab, $narrowers, $request->getLang());
$narrowersTwin = self::addTisafUriForConcepts($twinVocab, $narrowersTwin, $request->getLang());
// add two narrowers arrays
$narrowers = $narrowers + $narrowersTwin;
if ($narrowers === null) {
if ($narrowers === null) {
return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
}
$ret = $this->transformPropertyResults($request->getUri(), $request->getLang(), $narrowers, "narrower", "skos:narrower");
// add 2 "parents" uris
$parentUris[] = ["terminologyId" => $request->getVocab()->getId(), "conceptUri" => $request->getURI()];
$conceptTisafUri = self::getConceptTisafUri($vocab, $request->getURI(), $request->getLang());
$parentUris[] = ["uri" => $conceptTisafUri];
if(!empty($twinUri)) {
$parentUris[] = ["terminologyId" => $twinVocab->getId(), "conceptUri" => $twinUri];
$parentUris[] = ["uri" => self::getConceptTisafUri($twinVocab, $request->getURI(), $request->getLang())];
}
$ret["parentUris"] = $parentUris;
$ret["uri"] = $conceptTisafUri;
return $this->returnJson($ret);
}
private static function getConceptTisafUri(Vocabulary $voc, $uri, $lang) {
$concepts = $voc->getConceptInfo($uri, $lang);
if (sizeof($concepts) == 1) {
$concept = $concepts[0];
// tisaf:uri, if existing (see tisafUriMigration)
$tisafUri = $concept->getTisafUri();
return $tisafUri;
}
return $uri;
}
/**
* Used for querying narrower transitive relations for a concept.
* @param Request $request
......@@ -1857,7 +1891,6 @@ WHERE {
}
EOD;
$sparql = $vocab->getSparql();
$countResult = $sparql->execute($countQueryString);
// count skos:Concept
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment