Hier mein Lösungsansatz, um die Grenzwerte aus der Datenbank abzurufen. Bei der SQL-Abfrage führe ich gleich noch ein Typecasting durch. Bei ganzzahligen Werten verwende ich UNSIGNED.
In der Filterkonfiguration 0 und 1 für die Grenzwerte eintragen.
Für Verbesserungen bin ich offen und dankbar.
In der Filterkonfiguration 0 und 1 für die Grenzwerte eintragen.
Für Verbesserungen bin ich offen und dankbar.
PHP-Code:
<?php
/**
* Range filter template
*/
if(!function_exists(getValues)){
function getValues($col, $cast, $table, $sorting, $limit)
{
$stmt = "SELECT CAST($col AS $cast) AS rangeValue FROM $table ORDER BY CAST($col AS $cast) $sorting LIMIT $limit";
$objResult = \Database::getInstance()->prepare($stmt)->execute();
return $objResult;
}
}
$valMin = getValues('dein_spaltenname', 'DECIMAL(10,2)', 'cc_tabelle', 'ASC', 1);
$valMax = getValues('dein_spaltenname', 'DECIMAL(10,2)', 'cc_tabelle', 'DESC', 1);
$valMinOut = floor($valMin->rangeValue / pow(10, -1)) * pow(10, -1);
$valMaxOut = ceil($valMax->rangeValue / pow(10, -1)) * pow(10, -1);
if($this->useJquery)
{
global $objPage;
if(!$objPage->hasJQuery)
{
$GLOBALS['TL_JAVASCRIPT'][] = '//code.jquery.com/jquery-1.10.2.js';
}
$GLOBALS['TL_CSS'][] = '//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css';
$GLOBALS['TL_JAVASCRIPT'][] = '//code.jquery.com/ui/1.11.2/jquery-ui.js';
}
?>
<div <?php echo $this->cssID; ?> class="widget <?php echo $this->class; ?> block">
<fieldset class="range_container">
<?php if($this->label): ?><legend><?php echo $this->label; ?></legend><?php endif; ?>
<?php if($this->useJquery): ?>
<?php //if($this->label): ?><!--<label for="<?php //echo $this->name; ?>"><?php //echo $this->label; ?></label>--><?php //endif; ?>
<input name="<?php echo $this->name; ?>" type="hidden" id="slider-input_<?php echo $this->name; ?>" value="<?php echo $this->value; ?>">
<input readonly type="text" id="slider-text_<?php echo $this->name; ?>">
<div id="slider-range_<?php echo $this->name; ?>"></div>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function()
{
var elem = jQuery('#slider-range_<?php echo $this->name; ?>');
var text = jQuery('#slider-text_<?php echo $this->name; ?>');
var input = jQuery('#slider-input_<?php echo $this->name; ?>');
elem.slider(
{
range: true,
min: <?php echo $valMinOut; ?>,
max: <?php echo $valMaxOut; ?>,
step: .1,
values: [<?php echo ($this->actMinValue != 0) ? $this->actMinValue : $valMinOut; ?>, <?php echo ($this->actMaxValue != 1) ? $this->actMaxValue : $valMaxOut; ?>],
slide: function(event,ui)
{
text.val(ui.values[0].toLocaleString('de-DE') + " - " + ui.values[1].toLocaleString('de-DE') + " <?php echo $this->description; ?>");
input.val(ui.values[0] + "," + ui.values[1]);
},
change:function(event,ui)
{
// submit form on change
<?php if($this->getFilter()->getModule()->customcatalog_filter_submit): ?>
jQuery(event.target).parents('form').submit();
<?php endif; ?>
}
});
text.val(elem.slider("values",0).toLocaleString('de-DE') + " - " + elem.slider("values",1).toLocaleString('de-DE') + " <?php echo $this->description; ?>");
input.val(elem.slider("values",0) + "," + elem.slider("values",1));
});
/* ]]> */
</script>
<?php else: ?>
<input type="range" name="<?php echo $this->name; ?>" min="<?php echo $valMin->rangeValue; ?>" max="<?php echo $valMax->rangeValue; ?>" value="<?php echo $this->value; ?>">
<?php endif; ?>
</fieldset>
<!--<?php //if($this->description): ?><div class="description"><?php //echo $this->description; ?></div><?php //endif; ?>-->
</div>