You are here

function uc_addresses_check_access_by_ids in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.module \uc_addresses_check_access_by_ids()

Checks address access by ID's.

Parameters

string $access_type: The operation to check:

  • view
  • edit
  • delete

int $uid: ID of the address owner.

int $aid: (optional) ID of the address.

object $account: (optional) The account to check access for. Defaults to current user.

Return value

boolean TRUE if access is granted. FALSE otherwise.

1 call to uc_addresses_check_access_by_ids()
uc_addresses_views_access::access in views/uc_addresses_views_access.inc
Implements views_plugin_access#access().
1 string reference to 'uc_addresses_check_access_by_ids'
uc_addresses_views_access::get_access_callback in views/uc_addresses_views_access.inc
Implements views_plugin_access#get_access_callback().

File

./uc_addresses.module, line 471
Adds user profile address support to Ubercart.

Code

function uc_addresses_check_access_by_ids($access_type, $uid, $aid = NULL, $account = NULL) {

  // Get objects.
  if (empty($uid) && empty($aid)) {

    // Nothing to check permissions for. No access.
    return FALSE;
  }
  if (!empty($aid)) {
    if (!empty($uid)) {
      $address = UcAddressesAddressBook::get($uid)
        ->getAddressById($aid);
    }
    else {
      $address = UcAddressesAddressBook::loadAddress($aid);
      $uid = $address
        ->getUserId();
    }
  }
  if (empty($address)) {
    $address = NULL;
  }
  $address_user = user_load($uid);
  switch ($access_type) {
    case 'view':
      return UcAddressesPermissions::canViewAddress($address_user, $address, $account);
    case 'edit':
      return UcAddressesPermissions::canEditAddress($address_user, $address, $account);
    case 'delete':
      return UcAddressesPermissions::canDeleteAddress($address_user, $address, $account);
  }
  return FALSE;
}