You are here

function Currency::isObsolete in Currency 8.3

File

src/Entity/Currency.php, line 407

Class

Currency
Defines a currency entity class.

Namespace

Drupal\currency\Entity

Code

function isObsolete($reference = NULL) {

  // Without usage information, we cannot know if the currency is obsolete.
  if (!$this
    ->getUsages()) {
    return FALSE;
  }

  // Default to the current date and time.
  if (is_null($reference)) {
    $reference = time();
  }

  // Mark the currency obsolete if all usages have an end date that comes
  // before $reference.
  $obsolete = 0;
  foreach ($this
    ->getUsages() as $usage) {
    if ($usage
      ->getEnd()) {
      $to = strtotime($usage
        ->getEnd());
      if ($to !== FALSE && $to < $reference) {
        $obsolete++;
      }
    }
  }
  return $obsolete == count($this
    ->getUsages());
}