You are here

function acl_add_nodes in ACL 7

Same name and namespace in other branches
  1. 8 acl.module \acl_add_nodes()

Provide access control to all nodes selected by a subquery, based upon an ACL id.

1 call to acl_add_nodes()
AclWebTestCase::testNodeAclAddRemoveFromNode in tests/acl.test
Includes acl_node_add_acl, acl_node_remove_acl, acl_node_clear_acls

File

./acl.module, line 114
An API module providing by-user access control lists.

Code

function acl_add_nodes($subselect, $acl_id, $view, $update, $delete, $priority = 0) {
  db_delete('acl_node')
    ->condition('acl_id', $acl_id)
    ->condition('nid', $subselect, 'IN')
    ->execute();
  $subselect
    ->addExpression($acl_id, 'acl_id');
  $subselect
    ->addExpression((int) $view, 'grant_view');
  $subselect
    ->addExpression((int) $update, 'grant_update');
  $subselect
    ->addExpression((int) $delete, 'grant_delete');
  $subselect
    ->addExpression($priority, 'priority');
  $query = db_insert('acl_node')
    ->fields(array(
    'nid',
    'acl_id',
    'grant_view',
    'grant_update',
    'grant_delete',
    'priority',
  ));
  foreach ($subselect
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC) as $record) {
    $query
      ->values($record);
  }
  $query
    ->execute();
}