You are here

function _save_contributors in Bibliography Module 6

Same name and namespace in other branches
  1. 7 includes/biblio.contributors.inc \_save_contributors()

Save contributors to the database

Parameters

$authors:

$nid:

$vid:

$update:

Return value

success of database operations

4 calls to _save_contributors()
biblio_insert_contributors in ./biblio.contributors.inc
biblio_update_6027 in ./biblio.install
biblio_update_contributors in ./biblio.contributors.inc
_move_authors in ./biblio.install

File

./biblio.contributors.inc, line 199

Code

function _save_contributors(&$contributors, $nid, $vid, $update = FALSE) {
  $md5 = _loadMD5();
  $rank = 0;
  db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', array(
    $nid,
    $vid,
  ));
  foreach ($contributors as $cat => $authors) {
    foreach ($authors as $key => $author) {
      if (!empty($author['name'])) {
        if (empty($author['lastname'])) {
          $contributors[$cat][$key] = $author = biblio_parse_author($author, $cat);
        }
        if ($update && !empty($author['cid'])) {
          $author['cid'] = null;
        }

        // null out the cid so we don't do a global change
        if (empty($author['cid']) && isset($author['md5']) && !empty($md5)) {
          $author['cid'] = array_search($author['md5'], $md5);
        }
        if (empty($author['cid'])) {
          biblio_save_contributor($author);
          if (empty($author['cid'])) {
            return false;
          }
        }
        $link_array = array(
          'nid' => $nid,
          'vid' => $vid,
          'cid' => $author['cid'],
          'rank' => $rank++,
          //((isset($author['rank']) && is_numeric($author['rank'])) ? $author['rank'] : $key),
          'auth_type' => $author['auth_type'],
          'auth_category' => $cat,
        );
        if (!drupal_write_record('biblio_contributor', $link_array)) {
          return false;
        }
      }
    }
  }
  db_query("UPDATE {biblio_contributor_data} SET aka = cid WHERE aka = 0 OR aka IS NULL");
  return true;

  // successfully saved all contributors
}