You are here

function _uc_file_expiration_date in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 uc_file/uc_file.module \_uc_file_expiration_date()
  2. 7.3 uc_file/uc_file.module \_uc_file_expiration_date()

Returns a date given an incrementation.

$file_limits['time_polarity'] is either '+' or '-', indicating whether to add or subtract the amount of time. $file_limits['time_granularity'] is a unit of time like 'day', 'week', or 'never'. $file_limits['time_quantity'] is an amount of the previously mentioned unit... e.g. $file_limits = array('time_polarity => '+', 'time_granularity' => 'day', 'time_quantity' => 4); would read "4 days in the future."

Parameters

$file_limits: A keyed array containing the fields time_polarity, time_quantity, and time_granularity.

Return value

A UNIX timestamp representing the amount of time the limits apply.

4 calls to _uc_file_expiration_date()
uc_file_action_order_renew in uc_file/uc_file.ca.inc
Renews an orders product files.
uc_file_add_to_cart in uc_file/uc_file.module
Implements hook_add_to_cart().
uc_file_user_form_submit in uc_file/uc_file.module
Submit handler for per-user file download administration.
uc_file_user_form_validate in uc_file/uc_file.module
Validation handler for per-user file download administration.

File

uc_file/uc_file.module, line 1228

Code

function _uc_file_expiration_date($file_limits, $timestamp) {

  // Never expires.
  if ($file_limits['time_granularity'] == 'never') {
    return NULL;
  }

  // If there's no change, return the old timestamp
  // (strtotime() would return FALSE).
  if (!$file_limits['time_quantity']) {
    return $timestamp;
  }
  if (!$timestamp) {
    $timestamp = time();
  }

  // Return the new expiration time.
  return strtotime($file_limits['time_polarity'] . $file_limits['time_quantity'] . ' ' . $file_limits['time_granularity'], $timestamp);
}