You are here

protected function RenewRole::getExpiration in Ubercart 8.4

Calculates the expiration time using a role_product object.

Parameters

$role_product: The role product object whose expiration times to calculate.

int $quantity: Used to multiply any relative expiration time, if the $role_product says to.

int $time: The current time to use as a starting point for relative expiration calculation.

Return value

int The expiration time as a Unix timestamp.

1 call to RenewRole::getExpiration()
RenewRole::doExecute in uc_role/src/Plugin/RulesAction/RenewRole.php
Renews an order's product roles.

File

uc_role/src/Plugin/RulesAction/RenewRole.php, line 109

Class

RenewRole
Provides a 'Renew role' action.

Namespace

Drupal\uc_role\Plugin\RulesAction

Code

protected function getExpiration($role_product, $quantity, $time) {

  // Override the end expiration?
  if ($role_product->end_override) {

    // Absolute times are easy...
    if ($role_product->end_time) {
      return $role_product->end_time;
    }

    // We're gonna have to calculate the relative time from $time.
    $length = $role_product->duration * ($role_product->by_quantity ? $quantity : 1);
    return _uc_role_get_expiration($length, $role_product->granularity, $time);
  }
  else {

    // Relative...
    $roles_config = \Drupal::config('uc_role.settings');
    if ($roles_config
      ->get('default_end_expiration') === 'rel') {
      $length = $roles_config
        ->get('default_length') * ($role_product->by_quantity ? $quantity : 1);
      return _uc_role_get_expiration($length, $roles_config
        ->get('default_granularity'), $time);
    }

    // Absolute...
    $end_time = $roles_config
      ->get('default_end_time');
    if ($end_time) {
      $end_time = mktime(0, 0, 0, $end_time['month'], $end_time['day'], $end_time['year']);
    }
    return $end_time;
  }
}