You are here

function scald_user_actions in Scald: Media Management made easy 7

Determine the Scald Actions Bitstring for a given Atom for a given User.

The action bitstring is built based on the user permission system and does not take into account hook_scald_atom_access(). It is preferred to use scald_action_permitted().

@codingStandardsIgnoreStart

Parameters

ScaldAtom $atom: A Scald Atom.

object $account: A Drupal user account Defaults to the current $user.

Return value

mixed A Scald Actions Bitstring FALSE if the Atom is invalid

See also

scald_action_permitted

1 call to scald_user_actions()
scald_action_permitted in ./scald.module
Determines if a given User can act on a given Atom in a given way.

File

./scald.module, line 1050
The Scald Core, which handles all Scald Registries and dispatch.

Code

function scald_user_actions($atom, $account = NULL) {

  // @codingStandardsIgnoreEnd
  // Validate the function arguments.
  if (is_null($account)) {
    global $user;
    $account = $user;
  }

  // Combine the account scald_actions if they do not exists
  // May happen to UID = 1 which does not go through hook_user_load()
  if (!isset($account->scald_actions)) {
    $account->scald_actions = _scald_user_combine_actions($account);
  }

  // NOTE: Not using scald_is_fetched here because Action validation can (and
  // should) be done prior to fetching.  However, it is assumed that this $atom
  // is *at least* the result of a scald_is_registered() call.
  if (!is_object($atom) || !isset($atom->actions)) {
    return FALSE;
  }

  // The Account in question belongs to the Scald Publisher of this Atom.
  $actions_key = $atom->publisher == $account->uid ? 'own' : 'any';

  // Check for the "bypass atom access restrictions" permission for this user
  // if it is set, OR the  "Atom" and the "User Action" rather than ANDing them.
  return user_access('bypass atom access restrictions') ? $atom->actions | $account->scald_actions[$actions_key] : $atom->actions & $account->scald_actions[$actions_key];
}