public function FacetsDateHandler::getNextDateGap in Facets 8
Return a date gap one increment smaller than the one passed.
Parameters
string $gap: A string containing the gap, see FACETS_DATE_* constants for valid values.
string $min_gap: A string containing the minimum gap that can be returned, defaults to FACETS_DATE_SECOND. This is useful for defining the smallest increment that can be used in a date drilldown.
Return value
string A string containing the smaller date gap, NULL if there is no smaller gap. See FACETS_DATE_* constants for valid values.
File
- src/
Utility/ FacetsDateHandler.php, line 139
Class
- FacetsDateHandler
- Dates Handler service.
Namespace
Drupal\facets\UtilityCode
public function getNextDateGap($gap, $min_gap = self::FACETS_DATE_SECOND) {
// Array of numbers used to determine whether the next gap is smaller than
// the minimum gap allowed in the drilldown.
$gap_numbers = [
static::FACETS_DATE_YEAR => 6,
static::FACETS_DATE_MONTH => 5,
static::FACETS_DATE_DAY => 4,
static::FACETS_DATE_HOUR => 3,
static::FACETS_DATE_MINUTE => 2,
static::FACETS_DATE_SECOND => 1,
];
// Gets gap numbers for both the gap and minimum gap, checks if the next gap
// is within the limit set by the $min_gap parameter.
$gap_num = isset($gap_numbers[$gap]) ? $gap_numbers[$gap] : 6;
$min_num = isset($gap_numbers[$min_gap]) ? $gap_numbers[$min_gap] : 1;
return $gap_num > $min_num ? array_search($gap_num - 1, $gap_numbers) : $min_gap;
}