You are here

protected function DateRecurDefaultRRule::_hrFormatPosList in Recurring Dates Field 8

1 call to DateRecurDefaultRRule::_hrFormatPosList()
DateRecurDefaultRRule::humanReadable in src/DateRecurDefaultRRule.php
Return a human readable and translated representation of the repeat rule.

File

src/DateRecurDefaultRRule.php, line 119

Class

DateRecurDefaultRRule

Namespace

Drupal\date_recur

Code

protected function _hrFormatPosList($list) {

  // Sort like this: 1, 2, 3, 4, 5, -1, -2, -3.
  usort($list, function ($a, $b) {
    if ($a >= 0 && $b >= 0) {
      return $a > $b;
    }
    else {
      if ($a >= 0 && $b < 0) {
        return -1;
      }
      else {
        return 1;
      }
    }
  });

  // Append a dot for positive, get a string for ultimates.
  $list = array_map(function ($i) {
    if ($i > 0) {
      return $i . '.';
    }
    elseif ($i > -3) {
      return $this
        ->getString('last_' . abs($i));
    }
    else {
      return $i;
    }
  }, $list);

  // Format as list.
  return $this
    ->_hrFormatList($list);
}