diff --git a/local/config/vufind/facets.ini b/local/config/vufind/facets.ini index ebe013d173f1e99b142856191be59598522e85cc..31a37c6a4959641e9e3a3015d3c2447c34823eed 100644 --- a/local/config/vufind/facets.ini +++ b/local/config/vufind/facets.ini @@ -116,6 +116,11 @@ dateRange[] = publishDateSort ; language files appropriately. ; ; Leave the section empty if you do not need checkbox facets. + +[SpecialFacetsDisplaySettings] +; finc: dispaly always date range values, even if no preselection is made by user +dateRangeShowAlways = false + [CheckboxFacets] ;edition:1st* = "First Edition" ; Contrived hypothetical example diff --git a/themes/finc/templates/Recommend/SideFacets/range-slider.phtml b/themes/finc/templates/Recommend/SideFacets/range-slider.phtml index 8dfd0377a5dd5e065e231cfd33dce77d3303d7d4..9c5f09756f70fe5681fe2b7cf2ed21409116ee51 100644 --- a/themes/finc/templates/Recommend/SideFacets/range-slider.phtml +++ b/themes/finc/templates/Recommend/SideFacets/range-slider.phtml @@ -1,7 +1,22 @@ <!-- finc - recommend - sidefacets - rangeslider --> <?php - /** this is a copy of the bootstrap3 version and adds an aria-label to the - * slider-container element + /** + * origin: bootstrap3 + * + * called by view helper/controller: + * + * usage: result lists facets + * + * modified for finc: + ** #22135, #22511 usability date range slider + *** calculate min/max values by results value range + *** use html min / max attributes + ** #24304 show publish date range always (default = false) + * + * configured in: facets.ini + ** [SpecialFacets] -> dateRange[] = publishDateSort + ** [Results_Settings] -> facet_limit_by_field[publishDateSort] = -1 + ** [SpecialFacetsDisplaySettings] -> dateRangeShowAlways = false */ ?> <?php @@ -11,14 +26,19 @@ * if date range filter is applied additionaly: lowest and highest record years can be within filter values */ foreach ($cluster['list'] as $facet) { - $years[] = $facet['value']; + // casting year to int to prevent years like '0000' + $years[] = (int)$facet['value']; } - $facetmin = min($years); - $facetmax = max($years); - $low = $facetmin; - $min = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $facetmin; - $high = $facetmax; - $max = !empty($this->facet['values'][1]) ? $this->facet['values'][1] : $facetmax; + // results min + $low = min($years); + // (pre)selected min + $min = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $low; + // results max + $high = max($years); + // (pre)selected max + $max = !empty($this->facet['values'][1]) ? $this->facet['values'][1] : $high; + // finc: show date (publication year) range values always, even if no preselection is made by user #24304 + $showAlways = $this->config()->get('facets')->SpecialFacetsDisplaySettings->dateRangeShowAlways ?? false; ?> <?php /* finc changes div into li for compatibility with facet list structure */ ?> <li class="facet"> @@ -42,15 +62,31 @@ <label id="from-label" for="<?=$this->escapeHtmlAttr($this->title)?>from"> <?=$this->transEsc('date_from')?>: </label> - <?php /* finc: usability date range slider #22135, #22511: change input type and value */ ?> - <input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>from" id="<?=$this->escapeHtmlAttr($this->title)?>from" value="<?=!empty($this->facet['values'][0]) ? $this->escapeHtmlAttr($low) : ''?>" <?=$extraInputAttribs?>/> + <?php /* finc: usability date range slider #22135, #22511: change input type and value + finc: show date (publication year) range values always, even if no preselection is made by user #24304 */ ?> + <input + type="number" + class="form-control" + name="<?=$this->escapeHtmlAttr($this->title)?>from" + id="<?=$this->escapeHtmlAttr($this->title)?>from" + value="<?=($showAlways || !empty($this->facet['values'][0])) ? $this->escapeHtmlAttr($low) : ''?>" + <?=$extraInputAttribs?> + /> </div> <div class="date-to"> <label id="to-label" for="<?=$this->escapeHtmlAttr($this->title)?>to"> <?=$this->transEsc('date_to')?>: </label> - <?php /* finc: usability date range slider #22135, #22511: change input type and value input */ ?> - <input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>to" id="<?=$this->escapeHtmlAttr($this->title)?>to" value="<?=!empty($this->facet['values'][1]) ? $this->escapeHtmlAttr($high) : ''?>" <?=$extraInputAttribs?>/> + <?php /* finc: usability date range slider #22135, #22511: change input type and value input + finc: show date (publication year) range values always, even if no preselection is made by user #24304 */ ?> + <input + type="number" + class="form-control" + name="<?=$this->escapeHtmlAttr($this->title)?>to" + id="<?=$this->escapeHtmlAttr($this->title)?>to" + value="<?=($showAlways || !empty($this->facet['values'][1])) ? $this->escapeHtmlAttr($high) : ''?>" + <?=$extraInputAttribs?> + /> </div> </div> <?php if ($this->facet['type'] == 'date'): ?> diff --git a/themes/finc/templates/search/advanced/ranges.phtml b/themes/finc/templates/search/advanced/ranges.phtml index 80bf13a087b9db0c207879368f13f0351d9fe939..7f7ab09225be17115968d3bd9adb08de8792a7c2 100644 --- a/themes/finc/templates/search/advanced/ranges.phtml +++ b/themes/finc/templates/search/advanced/ranges.phtml @@ -3,10 +3,14 @@ <?php $params = $this->searchParams($this->searchClassId); ?> <?php foreach ($this->ranges as $current): $escField = $this->escapeHtmlAttr($current['field']); ?> <?php /* finc: usability date range slider #22511:: calculate variables at the beginning */ + // (pre)selected min $min = !empty($current['values'][0]) ? min($current['values'][0], 1400) : 1400; $future = date('Y', time() + 31536000); + // (pre)selected max $max = !empty($current['values'][1]) ? max($future, $current['values'][1]) : $future; + // results min $low = !empty($current['values'][0]) ? $current['values'][0] : $min; + // results max $high = !empty($current['values'][1]) ? $current['values'][1] : $max; ?> <?php /* finc: usability date range slider #22511: use previously calculated min-/max-values to limit inputs */ ?>