How can I use SPARQL within a CCK list? Is it even possible. Here is an example query that does what I'm looking for.
The following code uses the ARC2 php classes to retrieve the
results of a SPARQL query from a SPARQL endpoint, and creates a select
block. The variables in the SPARQL query are '?concept' and '?label'.
(this is a literal copy from some of my code, so there's quite a bit
of clutter. The gist should be clear though).
function getSelectBlock($sparql_query,$onChange,$name='conceptlist',
$value_fn='concept',$label_fn='label') {
// print "
".htmlentities($sparql_query)."
";
$rows = $this->store->query($sparql_query, 'rows');
if (!$this->store->getErrors()) {
print "
$name."' onchange='".$onChange."'>\n";
foreach($rows as $row) {
$label = $row[$label_fn];
$value = $row[$value_fn];
print "".$label."\n";
}
print "
";
} else {
foreach($this->store->getErrors() as $error) {
print $error."
";
}
throw new Exception("Errors! ".$this->store->getErrors());
}
}
The form that contains the select block will send only the value of
the selected option, which is the URI of the resource.
Comments
Comment #1
SamRose commentedI am working on this now myself. I may not use SPARQL, but if I do, I will update here