function tripal_pub_add_authors

2.x tripal_pub.pub_importers.inc tripal_pub_add_authors($pub_id, $authors, $do_contact)
3.x tripal_chado.pub_importers.inc tripal_pub_add_authors($pub_id, $authors, $do_contact)
1.x tripal_pub.api.inc tripal_pub_add_authors($pub_id, $authors, $do_contact)

Add one or more authors to a publication

Parameters

$pub_id: The publication ID of the pub in Chado.

$authors: An array of authors. Each author should have a set of keys/value pairs describing the author.

$do_contact: Optional. Set to TRUE if a contact entry should be added to the Chado contact table for authors of the publication.

1 call to tripal_pub_add_authors()
tripal_pub_add_publication in tripal_chado/includes/loaders/tripal_chado.pub_importers.inc
Adds a new publication to the Chado, along with all properties and database cross-references. If the publication does not already exist in Chado then it is added. If it does exist nothing is done. If the $update parameter is TRUE then theā€¦

File

tripal_chado/includes/loaders/tripal_chado.pub_importers.inc, line 1207
Management of importers

Code

function tripal_pub_add_authors($pub_id, $authors, $do_contact) {
  $rank = 0;

  // First remove any of the existing pubauthor entires.
  $sql = "DELETE FROM {pubauthor} WHERE pub_id = :pub_id";
  chado_query($sql, array(':pub_id' => $pub_id));

  // Iterate through the authors and add them to the pubauthors and contact
  // tables of chado, then link them through the custom pubauthors_contact
  // table.
  foreach ($authors as $author) {
    // Skip invalid author entires.
    if (isset($author['valid']) AND $author['valid'] == 'N') {
      continue;
    }
    // remove the 'valid' property as we don't have a CV term for it
    unset($author['valid']);

    $values = array(
      'pub_id' => $pub_id,
      'rank' => $rank,
    );

    // construct the contact.name field using the author information
    $name = '';
    $type = 'Person';
    if (isset($author['Given Name'])) {
      $name .= $author['Given Name'];
      $values['givennames'] = $author['Given Name'];
    }
    if (isset($author['Surname'])) {
      $name .= ' ' . $author['Surname'];
      $values['surname'] = substr($author['Surname'], 0, 100);
    }
    if (isset($author['Suffix'])) {
      $name .= ' ' . $author['Suffix'];
      $values['suffix'] = $author['Suffix'];
    }
    if (isset($author['Collective'])) {
      $name = $author['Collective'];
      $type = 'Collective';
      if (!isset($author['Surname'])) {
        $values['surname'] = substr($author['Collective'], 0, 100);
      }
    }
    $name = trim($name);

    // add an entry to the pubauthors table
    $options = array('statement_name' => 'ins_pubauthor_idrasugisu');
    $pubauthor = chado_insert_record('pubauthor', $values, $options);

    // if the user wants us to create a contact for each author then do it.
    if ($do_contact) {
      // Add the contact
      $contact = chado_insert_contact(array(
        'name' => $name,
        'description' => '',
        'type_name' => $type,
        'properties' => $author
      ));

      // if we have succesfully added the contact and the pubauthor entries then we want to
      // link them together
      if ($contact and $pubauthor) {

        // link the pubauthor entry to the contact
        $values = array(
          'pubauthor_id' => $pubauthor['pubauthor_id'],
          'contact_id' => $contact['contact_id'],
        );
        $options = array('statement_name' => 'ins_pubauthorcontact_puco');
        $pubauthor_contact = chado_insert_record('pubauthor_contact', $values, $options);
        if (!$pubauthor_contact) {
          tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot link pub authro and contact.", array());
        }
      }
    }
    $rank++;
  }
}