use detailsPermaLink function on main website as well

This commit is contained in:
Sarah Hoffmann
2020-02-09 16:05:22 +01:00
parent 57ae3d03a1
commit c36fd72f99
4 changed files with 46 additions and 8 deletions

View File

@@ -33,20 +33,39 @@ function wikipediaLink($aFeature)
return '';
}
function detailsLink($aFeature, $sTitle = false)
function detailsLink($aFeature, $sTitle = false, $sExtraProperties = false)
{
if (!$aFeature['place_id']) return '';
return '<a href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
$sHtml = '<a ';
if ($sExtraProperties) {
$sHtml .= $sExtraProperties.' ';
}
$sHtml .= 'href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
return $sHtml;
}
function detailsPermaLink($aFeature, $sRefText = false)
function detailsPermaLink($aFeature, $sRefText = false, $sExtraProperties = false)
{
$sOSMType = formatOSMType($aFeature['osm_type'], false);
if ($sOSMType) {
$sLabel = $sRefText ? $sRefText : $sOSMType.' '.$aFeature['osm_id'];
return '<a href="details.php?osmtype='.$aFeature['osm_type'].'&osmid='.$aFeature['osm_id'].'&class='.$aFeature['class'].'">'.$sLabel.'</a>';
$sHtml = '<a ';
if ($sExtraProperties) {
$sHtml .= $sExtraProperties.' ';
}
$sHtml .= 'href="details.php?osmtype='.$aFeature['osm_type']
.'&osmid='.$aFeature['osm_id'].'&class='.$aFeature['class'].'">';
if ($sRefText) {
$sHtml .= $sRefText.'</a>';
} else {
$sHtml .= $sOSMType.' '.$aFeature['osm_id'].'</a>';
}
return $sHtml;
}
return detailsLink($aFeature, $sRefText);
return detailsLink($aFeature, $sRefText, $sExtraProperties);
}

View File

@@ -85,7 +85,7 @@
else
echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['type'])).')</span>';
echo '<p>'.$aResult['lat'].','.$aResult['lon'].'</p>';
echo ' <a class="btn btn-default btn-xs details" href="details.php?osmtype='.$aResult['osm_type'].'&osmid='.$aResult['osm_id'].'&class='.$aResult['class'].'">details</a>';
echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"');
echo '</div>';
?>
</div>

View File

@@ -53,7 +53,7 @@
echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['class'])).')</span>';
else
echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['type'])).')</span>';
echo ' <a class="btn btn-default btn-xs details" href="details.php?osmtype='.$aResult['osm_type'].'&osmid='.$aResult['osm_id'].'&class='.$aResult['class'].'">details</a>';
echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"');
echo '</div>';
$i = $i+1;
}

View File

@@ -51,6 +51,25 @@ class OutputTest extends \PHPUnit\Framework\TestCase
);
}
public function testDetailsPermaLinkWithExtraPropertiesNode()
{
$aFeature = array('osm_type' => 'N', 'osm_id'=> 2, 'class' => 'amenity');
$this->assertSame(
detailsPermaLink($aFeature, 'something', 'class="xtype"'),
'<a class="xtype" href="details.php?osmtype=N&osmid=2&class=amenity">something</a>'
);
}
public function testDetailsPermaLinkWithExtraPropertiesTiger()
{
$aFeature = array('osm_type' => 'T', 'osm_id'=> 5, 'place_id' => 46);
$this->assertSame(
detailsPermaLink($aFeature, 'something', 'class="xtype"'),
'<a class="xtype" href="details.php?place_id=46">something</a>'
);
}