You are here

function uc_order_query_uc_order_access_alter in Ubercart 7.3

Implements hook_query_TAG_alter().

File

uc_order/uc_order.module, line 484

Code

function uc_order_query_uc_order_access_alter(QueryAlterableInterface $query) {
  global $user;

  // Read metadata from query, if provided.
  if (!($account = $query
    ->getMetaData('account'))) {
    $account = $user;
  }

  // If account can view all orders, we don't need to alter the query.
  if (user_access('view all orders', $account)) {
    return;
  }
  if (user_access('view own orders', $account)) {

    // Only allow the user to see their own orders.
    foreach ($query
      ->getTables() as $table) {
      if ($table['table'] === 'uc_orders') {
        $query
          ->condition($table['alias'] . '.uid', $account->uid);
      }
    }
  }
  else {

    // Deny access to everything.
    $query
      ->where('1 = 0');
  }
}