You are here

function simple_access_node_grants in Simple Access 6.2

Same name and namespace in other branches
  1. 8.3 simple_access.module \simple_access_node_grants()
  2. 5.2 simple_access.module \simple_access_node_grants()
  3. 5 simple_access.module \simple_access_node_grants()
  4. 7.2 simple_access.module \simple_access_node_grants()

Implementation of hook_node_grants().

@TODO implement to correcly return groups in all cases.

File

./simple_access.module, line 272
This module allows administrators to make nodes viewable by specific 'access groups'. Each access group can contain any number of roles. If a node is not assigned to any access groups, it will remain viewable by all users.

Code

function simple_access_node_grants($account, $op) {
  $gids = simple_access_groups_from_roles(array_keys($account->roles));
  $grants['simple_access'] = $gids;
  if (in_array($op, array(
    'view',
    'update',
    'delete',
  )) && !empty($gids)) {
    $result = db_query('SELECT DISTINCT pid FROM {simple_access_profiles_access} WHERE sa_' . $op . ' = 1 AND gid in (' . implode(',', array_fill(0, count($gids), '%d')) . ')', $gids);
    while ($row = db_fetch_array($result)) {
      $pids[] = $row['pid'];
    }
    if (!empty($pids)) {
      $grants['simple_access_profiles'] = $pids;
    }
  }
  $grants['simple_access_author'] = array(
    $account->uid,
  );
  return $grants;
}