You are here

function content_access_own_op in Content Access 6

Same name and namespace in other branches
  1. 8 content_access.module \content_access_own_op()
  2. 7 content_access.module \content_access_own_op()

Determines the grant for the node author and the given allowed roles of a operation.

Parameters

$any_roles: The roles with which anybody has access (not optimized!)

$own_roles: The roles with which only the author has acess (optimized!)

2 calls to content_access_own_op()
content_access_get_type_grant in ./content_access.module
Returns the default grants for a given node type.
content_access_node_access_records in ./content_access.module
Implementation of hook_node_access_records()

File

./content_access.module, line 314
Content access module file.

Code

function content_access_own_op($node, $any_roles, $own_roles) {
  static $roles = array();
  if (!isset($roles[$node->uid])) {
    $roles[$node->uid] = $node->uid ? array(
      DRUPAL_AUTHENTICATED_RID,
    ) : array(
      DRUPAL_ANONYMOUS_RID,
    );
    $result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $node->uid);
    while ($role = db_fetch_object($result)) {
      $roles[$node->uid][] = $role->rid;
    }
  }
  if (array_intersect($roles[$node->uid], $any_roles)) {

    // If there is access due to "any permissions" there is no need to at an author grant.
    return 0;
  }
  return array_intersect($roles[$node->uid], $own_roles) ? 1 : 0;
}