AKSW / site.ontowiki

HTML Content Publishing system on top of Linked Data
6 stars 7 forks source link

display results from multiple column sparql query #53

Closed cfrancois7 closed 8 years ago

cfrancois7 commented 8 years ago

Dear all,

What I'm searching is to display an array from a query such as {{query where="?s ?p ?o", col1="?s col2="?p"}. In other words the possibility to display several column of one Sparql query. Have you this kind of command or I have to create new "Query.php/Querylist.php" and new items?

For the moment I use two queries with orderby option to get the two column. To do that I created a new item p.phtml which generates a <div class="multicolumns2"><strong>head</strong><p>result1</p>.... It's not very clean.

white-gecko commented 8 years ago

Sorry for the delay. To implement something like this, maybe the example from aksw.org helps. For Persons, we have a list of Current Projects https://github.com/AKSW/aksw.org/blob/master/site/types/person.phtml#L35-L48

$currentProjects = $this->query(array(
    'where'    => '{'. PHP_EOL
        . '{' . PHP_EOL
        . '?resourceUri doap:maintainer ?maintainer . ' . PHP_EOL
        . 'OPTIONAL { ?maintainer ?relation ?resourceUri } ' . PHP_EOL
        . 'FILTER (?maintainer = <'.$this->resourceUri.'>) ' . PHP_EOL
        . 'FILTER (!bound(?relation) || ?relation != foaf:pastProject) ' . PHP_EOL
        . '} UNION {' . PHP_EOL
        . '<'.$this->resourceUri.'> foaf:currentProject ?resourceUri .' . PHP_EOL
        . '}' . PHP_EOL
        . '} ',
    'template' => 'li',
    'prefix'   => '<h1>Current Projects</h1>',
));

Where the individual entries are rendered using the item template li.phtml (https://github.com/AKSW/aksw.org/blob/master/site/items/li.phtml). Another example for such an item template is li-person-matrix.phtml (https://github.com/AKSW/aksw.org/blob/master/site/items/li-person-matrix.phtml).

We don't have a dedicated helper for this, but I hope this solves your problem. (If your problem is not solved, please feel free to reopen this issue.)