You are here

function simple_access_save_group in Simple Access 7.2

Same name and namespace in other branches
  1. 5.2 simple_access.module \simple_access_save_group()
  2. 5 simple_access.module \simple_access_save_group()
  3. 6.2 simple_access.module \simple_access_save_group()

Save group of roles into the database.

1 call to simple_access_save_group()
simple_access_group_form_submit in ./simple_access.admin.inc
Group form submit callback.

File

./simple_access.module, line 748
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_save_group($edit) {
  if (!empty($edit['gid'])) {
    db_merge('simple_access_groups')
      ->key(array(
      'gid' => $edit['gid'],
    ))
      ->fields(array(
      'name' => $edit['name'],
      'weight' => $edit['weight'],
    ))
      ->execute();
  }
  else {
    $edit['gid'] = db_insert('simple_access_groups', array(
      'return' => Database::RETURN_INSERT_ID,
    ))
      ->fields(array(
      'name' => $edit['name'],
      'weight' => $edit['weight'],
    ))
      ->execute();
  }
  db_delete('simple_access_roles')
    ->condition('gid', $edit['gid'])
    ->execute();
  if (is_array($edit['roles'])) {
    foreach ($edit['roles'] as $key => $value) {
      if ($value) {
        db_insert('simple_access_roles')
          ->fields(array(
          'rid' => $key,
          'gid' => $edit['gid'],
        ))
          ->execute();
      }
    }
  }
}