Skip to content
Snippets Groups Projects
Commit acc7e478 authored by Alexander Purr's avatar Alexander Purr Committed by Robert Lange
Browse files

refs #24304 [finc] show date (publication year) range values always, even if...

refs #24304 [finc] show date (publication year) range values always, even if no preselection is made by user

* adding configuration
* by default false
* cast year to int to prevent years like 0000 in view
* remove unnecessary variables, add variable comments
parent f5edf4e2
No related merge requests found
...@@ -116,6 +116,11 @@ dateRange[] = publishDateSort ...@@ -116,6 +116,11 @@ dateRange[] = publishDateSort
; language files appropriately. ; language files appropriately.
; ;
; Leave the section empty if you do not need checkbox facets. ; 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] [CheckboxFacets]
;edition:1st* = "First Edition" ; Contrived hypothetical example ;edition:1st* = "First Edition" ; Contrived hypothetical example
......
<!-- finc - recommend - sidefacets - rangeslider --> <!-- finc - recommend - sidefacets - rangeslider -->
<?php <?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 <?php
...@@ -11,14 +26,19 @@ ...@@ -11,14 +26,19 @@
* if date range filter is applied additionaly: lowest and highest record years can be within filter values * if date range filter is applied additionaly: lowest and highest record years can be within filter values
*/ */
foreach ($cluster['list'] as $facet) { foreach ($cluster['list'] as $facet) {
$years[] = $facet['value']; // casting year to int to prevent years like '0000'
$years[] = (int)$facet['value'];
} }
$facetmin = min($years); // results min
$facetmax = max($years); $low = min($years);
$low = $facetmin; // (pre)selected min
$min = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $facetmin; $min = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $low;
$high = $facetmax; // results max
$max = !empty($this->facet['values'][1]) ? $this->facet['values'][1] : $facetmax; $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 */ ?> <?php /* finc changes div into li for compatibility with facet list structure */ ?>
<li class="facet"> <li class="facet">
...@@ -42,15 +62,31 @@ ...@@ -42,15 +62,31 @@
<label id="from-label" for="<?=$this->escapeHtmlAttr($this->title)?>from"> <label id="from-label" for="<?=$this->escapeHtmlAttr($this->title)?>from">
<?=$this->transEsc('date_from')?>: <?=$this->transEsc('date_from')?>:
</label> </label>
<?php /* finc: usability date range slider #22135, #22511: change input type and value */ ?> <?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?>/> 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>
<div class="date-to"> <div class="date-to">
<label id="to-label" for="<?=$this->escapeHtmlAttr($this->title)?>to"> <label id="to-label" for="<?=$this->escapeHtmlAttr($this->title)?>to">
<?=$this->transEsc('date_to')?>: <?=$this->transEsc('date_to')?>:
</label> </label>
<?php /* finc: usability date range slider #22135, #22511: change input type and value input */ ?> <?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?>/> 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>
</div> </div>
<?php if ($this->facet['type'] == 'date'): ?> <?php if ($this->facet['type'] == 'date'): ?>
......
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
<?php $params = $this->searchParams($this->searchClassId); ?> <?php $params = $this->searchParams($this->searchClassId); ?>
<?php foreach ($this->ranges as $current): $escField = $this->escapeHtmlAttr($current['field']); ?> <?php foreach ($this->ranges as $current): $escField = $this->escapeHtmlAttr($current['field']); ?>
<?php /* finc: usability date range slider #22511:: calculate variables at the beginning */ <?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; $min = !empty($current['values'][0]) ? min($current['values'][0], 1400) : 1400;
$future = date('Y', time() + 31536000); $future = date('Y', time() + 31536000);
// (pre)selected max
$max = !empty($current['values'][1]) ? max($future, $current['values'][1]) : $future; $max = !empty($current['values'][1]) ? max($future, $current['values'][1]) : $future;
// results min
$low = !empty($current['values'][0]) ? $current['values'][0] : $min; $low = !empty($current['values'][0]) ? $current['values'][0] : $min;
// results max
$high = !empty($current['values'][1]) ? $current['values'][1] : $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 */ ?> <?php /* finc: usability date range slider #22511: use previously calculated min-/max-values to limit inputs */ ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment