Skip to content

Commit

Permalink
Clean KmlPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Nov 20, 2018
1 parent 234d289 commit df4d72c
Showing 1 changed file with 21 additions and 43 deletions.
64 changes: 21 additions & 43 deletions src/SemanticMW/ResultPrinters/KmlPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,27 @@
use SMWQueryResult;

/**
* SMWResultPrinter class for printing a query result as KML.
*
* @file SM_KMLPrinter.php
* @ingroup SemanticMaps
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class KmlPrinter extends FileExportPrinter {

/**
* Handler of the print request.
*
* @param SMWQueryResult $res
* @param $outputmode
* @param int $outputMode
*
* @return array
* @return string
*/
public function getResultText( SMWQueryResult $res, $outputmode ) {
if ( $outputmode == SMW_OUTPUT_FILE ) {
return $this->getKML( $res, $outputmode );
} else {
return $this->getKMLLink( $res, $outputmode );
public function getResultText( SMWQueryResult $res, $outputMode ) {
if ( $outputMode == SMW_OUTPUT_FILE ) {
return $this->getKML( $res, $outputMode );
}

return $this->getKMLLink( $res, $outputMode );
}

/**
* Returns the KML for the query result.
*
* @param SMWQueryResult $res
* @param integer $outputmode
*
* @return string
*/
private function getKML( SMWQueryResult $res, $outputmode ) {
$queryHandler = new QueryHandler( $res, $outputmode, $this->params['linkabsolute'] );
private function getKML( SMWQueryResult $res, int $outputMode ): string {
$queryHandler = new QueryHandler( $res, $outputMode, $this->params['linkabsolute'] );
$queryHandler->setText( $this->params['text'] );
$queryHandler->setTitle( $this->params['title'] );
$queryHandler->setSubjectSeparator( '' );
Expand All @@ -55,14 +40,9 @@ private function getKML( SMWQueryResult $res, $outputmode ) {

/**
* Returns a link (HTML) pointing to a query that returns the actual KML file.
*
* @param SMWQueryResult $res
* @param integer $outputmode
*
* @return string
*/
private function getKMLLink( SMWQueryResult $res, $outputmode ) {
$searchLabel = $this->getSearchLabel( $outputmode );
private function getKMLLink( SMWQueryResult $res, int $outputMode ): string {
$searchLabel = $this->getSearchLabel( $outputMode );
$link = $res->getQueryLink(
$searchLabel ? $searchLabel : wfMessage( 'semanticmaps-kml-link' )->inContentLanguage()->text()
);
Expand Down Expand Up @@ -93,45 +73,43 @@ private function getKMLLink( SMWQueryResult $res, $outputmode ) {
$link->setParameter( 20, 'limit' );
}

$this->isHTML = ( $outputmode == SMW_OUTPUT_HTML );
$this->isHTML = ( $outputMode == SMW_OUTPUT_HTML );

return $link->getText( $outputmode, $this->mLinker );
return $link->getText( $outputMode, $this->mLinker );
}

/**
* @see SMWResultPrinter::getParamDefinitions
*
* @param ParamDefinition[] $definitions
*
* @return array of ParamDefinition|array
* @return array
*/
public function getParamDefinitions( array $definitions ) {
global $egMapsDefaultLabel, $egMapsDefaultTitle;

$params = parent::getParamDefinitions( $definitions );

$params['text'] = [
$definitions['text'] = [
'message' => 'semanticmaps-kml-text',
'default' => $egMapsDefaultLabel,
];

$params['title'] = [
$definitions['title'] = [
'message' => 'semanticmaps-kml-title',
'default' => $egMapsDefaultTitle,
];

$params['linkabsolute'] = [
$definitions['linkabsolute'] = [
'message' => 'semanticmaps-kml-linkabsolute',
'type' => 'boolean',
'default' => true,
];

$params['pagelinktext'] = [
$definitions['pagelinktext'] = [
'message' => 'semanticmaps-kml-pagelinktext',
'default' => wfMessage( 'semanticmaps-default-kml-pagelink' )->text(),
];

return $params;
return $definitions;
}

/**
Expand Down Expand Up @@ -167,9 +145,9 @@ public final function getName() {
* @see SMWResultPrinter::handleParameters
*
* @param array $params
* @param $outputmode
* @param $outputMode
*/
protected function handleParameters( array $params, $outputmode ) {
protected function handleParameters( array $params, $outputMode ) {
$this->params = $params;
}
}

0 comments on commit df4d72c

Please sign in to comment.