You are here

function _uc_roles_product_get_expiration in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_roles/uc_roles.module \_uc_roles_product_get_expiration()

Calculates the expiration time using a role_product object.

Parameters

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

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

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

1 call to _uc_roles_product_get_expiration()
uc_roles_action_order_renew in uc_roles/uc_roles.ca.inc
Renews an orders product roles.

File

uc_roles/uc_roles.module, line 1348

Code

function _uc_roles_product_get_expiration($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_roles_get_expiration($length, $role_product->granularity, $time);
  }
  else {

    // Relative...
    if (variable_get('uc_roles_default_end_expiration', 'rel') === 'rel') {
      $length = variable_get('uc_roles_default_length', NULL) * ($role_product->by_quantity ? $quantity : 1);
      return _uc_roles_get_expiration($length, variable_get('uc_roles_default_granularity', 'never'), $time);
    }

    // Absolute...
    $end_time = variable_get('uc_roles_default_end_time', NULL);
    if ($end_time) {
      $end_time = mktime(0, 0, 0, $end_time['month'], $end_time['day'], $end_time['year']);
    }
    return $end_time;
  }
}