Skip to content

Commit

Permalink
ListResultPrinter add extra information to the template output
Browse files Browse the repository at this point in the history
- Make {{{userparam}}} available to intro and outro template as well
- Make the result querystring available to a template via {{{swm-resultquerycondition}}}

When using {{{smw-resultquerycondition}}} as parameter a template
inherits the query condition from the source which enables to add
additional output information (e.g. sum, average etc.) without having a
template to carry an explicit query condition.

```
{{#ask: [[Category:Country]]
 | ?Population
 | ?GDP
 | template=Country/Table
 | introtemplate=Country/Table/Intro
 | outrotemplate=Country/Table/Outro
 | format=template
 | link=none
}}

Template:Country/Table/Outro
<includeonly>
 | Total
 | {{#ask: {{{swm-resultquerycondition|}}} |?Population |format=sum}}
 | {{#ask: {{{swm-resultquerycondition|}}} |?GDP |format=sum}}
|}
</includeonly>
```
  • Loading branch information
mwjames committed Mar 5, 2014
1 parent c110998 commit a3d6e51
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions includes/queryprinters/ListResultPrinter.php
Expand Up @@ -160,15 +160,15 @@ protected function getResultText( SMWQueryResult $queryResult, $outputmode ) {
$result .= $this->header;

if ( $this->mIntroTemplate !== '' ) {
$result .= "{{" . $this->mIntroTemplate . "}}";
$result .= "{{" . $this->mIntroTemplate . $this->addCommonTemplateParameters( $queryResult ) . "}}";
}

while ( $row = $queryResult->getNext() ) {
$result .= $this->getRowText( $row, $queryResult );
}

if ( $this->mOutroTemplate !== '' ) {
$result .= "{{" . $this->mOutroTemplate . "}}";
$result .= "{{" . $this->mOutroTemplate . $this->addCommonTemplateParameters( $queryResult ) . "}}";
}

// Make label for finding further results
Expand Down Expand Up @@ -271,7 +271,7 @@ protected function getRowText( array $row, SMWQueryResult $res ) {

if ( $this->mTemplate !== '' ) { // Build template code
$this->hasTemplates = true;
$content = $this->mTemplate . $this->getTemplateContent( $row );
$content = $this->mTemplate . $this->getTemplateContent( $row ) . $this->addCommonTemplateParameters( $res );
$result .= $this->getRowStart( $res ) . '{{' . $content . '}}';
} else { // Build simple list
$content = $this->getRowListContent( $row );
Expand Down Expand Up @@ -387,7 +387,7 @@ protected function getRowListContent( array $row ) {
* @return string
*/
protected function getTemplateContent( $row ){
$wikitext = $this->mUserParam ? "|userparam=$this->mUserParam" : '';
$wikitext = '';

foreach ( $row as $i => $field ) {
$wikitext .= '|' . ( $this->mNamedArgs ? '?' . $field->getPrintRequest()->getLabel() : $i + 1 ) . '=';
Expand All @@ -407,6 +407,11 @@ protected function getTemplateContent( $row ){
return $wikitext;
}

protected function addCommonTemplateParameters( $queryResult ) {
return ( $this->mUserParam ? "|userparam=$this->mUserParam" : '' ) .
"|swm-resultquerycondition=" . $queryResult->getQuery()->getQueryString();
}

/**
* Get text for further results link. Used only during getResultText().
*
Expand Down

0 comments on commit a3d6e51

Please sign in to comment.