You are here

private function SmartDateRule::makeRanges in Smart Date 3.2.x

Same name and namespace in other branches
  1. 3.1.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::makeRanges()
  2. 3.3.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::makeRanges()
  3. 3.4.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::makeRanges()

Helper function to convert an array into ranges.

Parameters

array $array: The array to convert.

int $offset: The offset to use for comoparison.

Return value

array An array of ranges.

1 call to SmartDateRule::makeRanges()
SmartDateRule::getTextRule in modules/smart_date_recur/src/Entity/SmartDateRule.php
Use the transformer to get text output of the rule.

File

modules/smart_date_recur/src/Entity/SmartDateRule.php, line 560

Class

SmartDateRule
Defines the Smart date rule entity.

Namespace

Drupal\smart_date_recur\Entity

Code

private function makeRanges(array $array, $offset = 1) {
  $ranges = [];
  if (!$array || count($array) == 1) {
    return $array;
  }
  $start_item = array_shift($array);
  $range = [
    $start_item,
  ];
  foreach ($array as $value) {
    if ($value == $start_item + $offset) {

      // Add to the current range.
      $range[] = $value;
    }
    else {

      // Start a new range.
      $ranges[] = $range;
      $range = [
        $value,
      ];
    }
    $start_item = $value;
  }

  // Add the final range.
  $ranges[] = $range;
  return $ranges;
}