You are here

function commerce_license_exists in Commerce License 7

Checks whether the user has an active license for the given product.

Parameters

$product: The product entity.

$account: The account to check for. If not given, the current user is used instead.

Return value

TRUE if an active license exists, FALSE otherwise.

File

./commerce_license.module, line 343
Provides a framework for selling access to local or remote resources.

Code

function commerce_license_exists($product, $account = NULL) {
  global $user;
  if (!$account) {
    $account = $user;
  }
  $results =& drupal_static(__FUNCTION__, array());
  $uid = $account->uid;
  $product_id = $product->product_id;
  if (empty($results[$uid]) || empty($results[$uid][$product_id])) {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'commerce_license')
      ->propertyCondition('status', COMMERCE_LICENSE_ACTIVE)
      ->propertyCondition('product_id', $product_id)
      ->propertyCondition('uid', $uid)
      ->count();
    $results[$uid][$product_id] = $query
      ->execute();
  }
  return $results[$uid][$product_id];
}