You are here

function simple_access_save_group in Simple Access 5.2

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

Save group of roles into the database $roles is an associative array of roles where the keys are role ids $name is the name of the group $gid is the group id

1 call to simple_access_save_group()
simple_access_group_form_submit in ./simple_access.module

File

./simple_access.module, line 901
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 (!$edit['gid']) {
    $edit['gid'] = db_next_id('{simple_access_groups}_gid');
  }
  db_query('DELETE FROM {simple_access_roles} WHERE gid = %d', $edit['gid']);
  db_query('DELETE FROM {simple_access_groups} WHERE gid = %d', $edit['gid']);
  $success = db_query("INSERT INTO {simple_access_groups} (gid, name, weight) VALUES (%d, '%s', %d)", $edit['gid'], $edit['name'], $edit['weight']);
  if (is_array($edit['roles'])) {
    foreach ($edit['roles'] as $key => $value) {
      if ($value) {
        $success = $success && db_query('INSERT INTO {simple_access_roles} (rid, gid) VALUES (%d, %d)', $key, $edit['gid']);
      }
    }
  }
  if (!$success) {
    drupal_set_message(t('There was a problem saving to the database.'));
  }
  return $success;
}