You are here

function _commerce_userpoints_validate_uniqueness in Commerce userpoints 7

Check if a given key (code, symbol, ..) is not already used.

Parameters

$value: The value to be checked against.

$key: The key to check against, any key in a currency definition is allowed.

$code: The code of the current currency if we're editing one.

Return value

TRUE if the value is unique, FALSE if not.

1 call to _commerce_userpoints_validate_uniqueness()
commerce_userpoints_currencies_form_validate in ./commerce_userpoints.admin.inc
Form validate callback for adding a new currency.

File

./commerce_userpoints.admin.inc, line 129
Administration page callbacks for the commerce_userpoints module.

Code

function _commerce_userpoints_validate_uniqueness($value, $key, $code = NULL) {
  $currencies = commerce_currencies();
  foreach ($currencies as $currency) {

    // Check if the value is the same and code is empty (new currency) or not
    // the one we're comparing against.
    if ($value == $currency[$key] && (!$code || $code != $currency['code'])) {
      return FALSE;
    }
  }
  return TRUE;
}