You are here

function simple_access_node_grants in Simple Access 7.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. 6.2 simple_access.module \simple_access_node_grants()

Implements hook_node_grants().

@TODO implement to correcly return groups in all cases.

File

./simple_access.module, line 346
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));
  if (!empty($gids)) {
    $grants['simple_access'] = array_keys($gids);
  }
  if (in_array($op, array(
    'view',
    'update',
    'delete',
  )) && !empty($gids)) {
    $pids = db_select('simple_access_profiles_access', 'p')
      ->fields('p', array(
      'pid',
    ))
      ->condition('sa_' . $op, '1')
      ->condition('gid', $gids, 'IN')
      ->distinct()
      ->execute()
      ->fetchAllAssoc('pid', PDO::FETCH_ASSOC);
    if (!empty($pids)) {
      $grants['simple_access_profiles'] = $pids;
    }
  }
  $grants['simple_access_author'] = array(
    $account->uid,
  );
  return $grants;
}