You are here

function domain_content_update_nodes in Domain Access 5

Same name and namespace in other branches
  1. 6.2 domain_content/domain_content.module \domain_content_update_nodes()
  2. 7.3 domain_content/domain_content.module \domain_content_update_nodes()
  3. 7.2 domain_content/domain_content.module \domain_content_update_nodes()

FormAPI function that lets us update access rules.

File

domain_content/domain_content.module, line 356
Editorial overview module.

Code

function domain_content_update_nodes($form_id, $form_values) {

  // If our operation is flagged, then we have to manually change the
  // {node_access} table.  The rest of the process will clear the cache,
  // so this should be a safe operation.
  if ($form_values['operation'] == 'domain') {
    if ($form_values['domain_site']) {
      $domain_site = TRUE;
    }
    $domains = array();
    foreach ($form_values['domains'] as $key => $value) {

      // Cannot pass zero in checkboxes, so these are converted from -1.
      if (abs($key) > 0 && $key == $value) {
        $key == -1 ? $id = 0 : ($id = $value);
        $domains[] = $id;
      }
    }
    $editor = variable_get('domain_editors', DOMAIN_EDITOR_RULE);
    if ($editor) {
      $editors = $domains;
    }
    foreach ($form_values['nodes'] as $nid) {
      if ($nid > 0) {

        // Delete anything not selected.
        // We have to update both the {node_access} and {domain_access} tables.
        db_query("DELETE FROM {node_access} WHERE nid = %d AND realm IN ('domain_id', 'domain_site', 'domain_editor')", $nid);
        db_query("DELETE FROM {domain_access} WHERE nid = %d", $nid);
        if ($domain_site) {
          db_query("INSERT INTO {node_access} VALUES (%d, 0, 'domain_site', 1, 0, 0)", $nid);
          db_query("INSERT INTO {domain_access} VALUES (%d, 0, 'domain_site')", $nid);
        }
        if (!empty($domains)) {
          foreach ($domains as $id) {
            db_query("INSERT INTO {node_access} VALUES (%d, %d, 'domain_id', 1, 0, 0)", $nid, $id);
            db_query("INSERT INTO {domain_access} VALUES (%d, %d, 'domain_id')", $nid, $id);
          }
          if ($editor) {
            db_query("INSERT INTO {node_access} VALUES (%d, %d, 'domain_editor', 0, 1, 1)", $nid, $id);
            db_query("INSERT INTO {domain_access} VALUES (%d, %d, 'domain_editor')", $nid, $id);
          }
        }
      }
    }
  }

  // Clear the cache.
  cache_clear_all();
}