Browse Source

Pub field is now working

Stephen Ficklin 9 years ago
parent
commit
694dd53873

+ 399 - 8
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -291,19 +291,18 @@ function tripal_publication_exists($pub_details) {
  *
  * @ingroup tripal_chado_api
  */
-function tripal_autocomplete_pub($field, $string = '') {
+function tripal_autocomplete_pub($string = '') {
   $items = array();
-
   $sql = "
-    SELECT uniquename, title
+    SELECT pub_id, title, uniquename
     FROM {pub}
-    WHERE :field like :str
+    WHERE lower(title) like lower(:str)
     ORDER by title
     LIMIT 25 OFFSET 0
   ";
-  $pubs = chado_query($sql, array(':field' => $field, ':str' => $string . '%'));
-  foreach ($pubs as $pub) {
-    $items[$pub->uniquename] = $pub->$field;
+  $pubs = chado_query($sql, array(':str' => $string . '%'));
+  while ($pub = $pubs->fetchObject()) {
+    $items[$pub->uniquename] = $pub->uniquename;
   }
 
   drupal_json_output($items);
@@ -604,4 +603,396 @@ function tripal_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db =
     return;
   }
   print "Done.\n";
-}
+}
+
+/**
+ * Launch the Tripal job to generate citations.
+ *
+ * This function will recreate citations for all publications currently
+ * loaded into Tripal.  This is useful to create a consistent format for
+ * all citations.
+ *
+ * @param $options
+ *  Options pertaining to what publications to generate citations for.
+ *  One of the following must be present:
+ *   - all: Create and replace citation for all pubs
+ *   - new: Create citation for pubs that don't already have one
+ *
+ * @ingroup tripal_pub
+ */
+function tripal_pub_create_citations($options) {
+  $skip_existing = TRUE;
+  $sql = "
+    SELECT cvterm_id
+    FROM {cvterm}
+    WHERE
+      name = 'Citation' AND
+      cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
+  ";
+  $citation_type_id = chado_query($sql)->fetchField();
+
+  // Create and replace citation for all pubs
+  if ($options == 'all') {
+    $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
+    $skip_existing = FALSE;
+  }
+  // Create citation for pubs that don't already have one
+  else if ($options == 'new') {
+    $sql = "
+      SELECT pub_id
+      FROM {pub} P
+      WHERE
+        (SELECT value
+         FROM {pubprop} PB
+         WHERE type_id = :type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL
+        AND  pub_id <> 1
+    ";
+    $skip_existing = TRUE;
+  }
+
+  $result = chado_query($sql, array(':type_id' => $citation_type_id));
+  $counter_updated = 0;
+  $counter_generated = 0;
+  while ($pub = $result->fetchObject()) {
+    $pub_arr = tripal_pub_get_publication_array($pub->pub_id, $skip_existing);
+    if ($pub_arr) {
+      $citation = tripal_pub_create_citation($pub_arr);
+      print $citation . "\n\n";
+      // Replace if citation exists. This condition is never TRUE if $skip_existing is TRUE
+      if ($pub_arr['Citation']) {
+        $sql = "
+          UPDATE {pubprop} SET value = :value
+          WHERE pub_id = :pub_id  AND type_id = :type_id AND rank = :rank
+        ";
+        chado_query($sql, array(':value' => $citation, ':pub_id' => $pub->pub_id,
+          ':type_id' => $citation_type_id, ':rank' => 0));
+        $counter_updated ++;
+        // Generate a new citation
+      } else {
+        $sql = "
+          INSERT INTO {pubprop} (pub_id, type_id, value, rank)
+          VALUES (:pub_id, :type_id, :value, :rank)
+        ";
+        chado_query($sql, array(':pub_id' => $pub->pub_id, ':type_id' => $citation_type_id,
+          ':value' => $citation, ':rank' => 0));
+        $counter_generated ++;
+      }
+    }
+  }
+  print "$counter_generated citations generated. $counter_updated citations updated.\n";
+}
+
+
+/**
+ * This function generates citations for publications.  It requires
+ * an array structure with keys being the terms in the Tripal
+ * publication ontology.  This function is intended to be used
+ * for any function that needs to generate a citation.
+ *
+ * @param $pub
+ *   An array structure containing publication details where the keys
+ *   are the publication ontology term names and values are the
+ *   corresponding details.  The pub array can contain the following
+ *   keys with corresponding values:
+ *     - Publication Type:  an array of publication types. a publication can have more than one type
+ *     - Authors: a  string containing all of the authors of a publication
+ *     - Journal Name:  a string containing the journal name
+ *     - Journal Abbreviation: a string containing the journal name abbreviation
+ *     - Series Name: a string containing the series (e.g. conference proceedings) name
+ *     - Series Abbreviation: a string containing the series name abbreviation
+ *     - Volume: the serives volume number
+ *     - Issue: the series issue number
+ *     - Pages: the page numbers for the publication
+ *     - Publication Date:  A date in the format "Year Month Day"
+ *
+ * @return
+ *   A text string containing the citation
+ *
+ * @ingroup tripal_pub
+ */
+function tripal_pub_create_citation($pub) {
+  $citation = '';
+  $pub_type = '';
+
+  // An article may have more than one publication type. For example,
+  // a publication type can be 'Journal Article' but also a 'Clinical Trial'.
+  // Therefore, we need to select the type that makes most sense for
+  // construction of the citation. Here we'll iterate through them all
+  // and select the one that matches best.
+  if (is_array($pub['Publication Type'])) {
+    foreach ($pub['Publication Type'] as $ptype) {
+      if ($ptype == 'Journal Article' ) {
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == 'Conference Proceedings'){
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == 'Review') {
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == 'Book') {
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == 'Letter') {
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == 'Book Chapter') {
+        $pub_type = $ptype;
+        break;
+      }
+      else if ($ptype == "Research Support, Non-U.S. Gov't") {
+        $pub_type = $ptype;
+        // we don't break because if the article is also a Journal Article
+        // we prefer that type
+      }
+    }
+    // If we don't have a recognized publication type, then just use the
+    // first one in the list.
+    if (!$pub_type) {
+      $pub_type = $pub['Publication Type'][0];
+    }
+  }
+  else {
+    $pub_type = $pub['Publication Type'];
+  }
+  //----------------------
+  // Journal Article
+  //----------------------
+  if ($pub_type == 'Journal Article') {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+
+    $citation .= $pub['Title'] .  '. ';
+
+    if (array_key_exists('Journal Name', $pub)) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    elseif (array_key_exists('Journal Abbreviation', $pub)) {
+      $citation .= $pub['Journal Abbreviation'] . '. ';
+    }
+    elseif (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+  //----------------------
+  // Review
+  //----------------------
+  if ($pub_type == 'Review') {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+
+    $citation .= $pub['Title'] .  '. ';
+
+    if (array_key_exists('Journal Name', $pub)) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    elseif (array_key_exists('Journal Abbreviation', $pub)) {
+      $citation .= $pub['Journal Abbreviation'] . '. ';
+    }
+    elseif (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+  //----------------------
+  // Research Support, Non-U.S. Gov't
+  //----------------------
+  elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+
+    $citation .= $pub['Title'] .  '. ';
+
+    if (array_key_exists('Journal Name', $pub)) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    $citation .= '.';
+  }
+  //----------------------
+  // Letter
+  //----------------------
+  elseif ($pub_type == 'Letter') {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+
+    $citation .= $pub['Title'] .  '. ';
+    if (array_key_exists('Journal Name', $pub)) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    elseif (array_key_exists('Journal Abbreviation', $pub)) {
+      $citation .= $pub['Journal Abbreviation'] . '. ';
+    }
+    elseif (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+  //-----------------------
+  // Conference Proceedings
+  //-----------------------
+  elseif ($pub_type == 'Conference Proceedings') {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+
+    $citation .= $pub['Title'] .  '. ';
+    if (array_key_exists('Conference Name', $pub)) {
+      $citation .= $pub['Conference Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+  //-----------------------
+  // Default
+  //-----------------------
+  else {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    $citation .= $pub['Title'] .  '. ';
+    if (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+
+  return $citation;
+}

+ 1 - 1
tripal_chado/includes/fields/cvterm.inc

@@ -61,7 +61,7 @@ function tripal_chado_cvterm_formatter(&$element, $entity_type, $entity, $field,
     'empty' => 'There are no annotations of this type',
   );
 
-  $element[$delta] = array(
+  $element[0] = array(
     '#type' => 'markup',
     '#markup' => theme_table($table),
   );

+ 33 - 43
tripal_chado/includes/fields/pub.inc

@@ -13,20 +13,27 @@
 function tripal_chado_pub_formatter(&$element, $entity_type, $entity, $field,
     $instance, $langcode, $items, $display) {
 
+  $list_items = array();
   $chado_table = $field['settings']['chado_table'];
   foreach ($items as $delta => $item) {
-    if ($chado_table . '__pub_id') {
+    if ($item[$chado_table . '__pub_id']) {
       $pub = chado_generate_var('pub', array('pub_id' => $item[$chado_table . '__pub_id']));
-      $name = $pub->name;
-      if ($pub->type_id->name != 'exact') {
-        $name .= ' (<i>' . $pub->type_id->name . '</i>)';
-      }
-      $element[$delta] = array(
-        '#type' => 'markup',
-        '#markup' => $name,
-      );
+      $list_items[$pub->pyear] = $pub->uniquename;
     }
   }
+
+  krsort($list_items, SORT_NUMERIC);
+
+  $list = array(
+    'title' => '',
+    'items' => $list_items,
+    'type' => 'ol',
+    'attributes' => array(),
+  );
+  $element[0] = array(
+    '#type' => 'markup',
+    '#markup' => theme_item_list($list),
+  );
 }
 /**
  *
@@ -66,7 +73,7 @@ function tripal_chado_pub_widget(&$widget, $form, $form_state, $field,
     $record_id = $items[$delta]['value'];
     $fkey_value = $items[$delta][$table_name . '__' . $fkey];
     $pub_id = $items[$delta][$table_name . '__pub_id'];
-    $title = $items[$delta][$table_name . '__title'];
+    $title = $items[$delta][$table_name . '--pub__uniquename'];
   }
 
   // Check $form_state['values'] to see if an AJAX call set the values.
@@ -99,17 +106,18 @@ function tripal_chado_pub_widget(&$widget, $form, $form_state, $field,
     '#default_value' => $pub_id,
   );
 
-  $widget[$table_name . '__title'] = array(
+  $widget[$table_name . '--pub__uniquename'] = array(
     '#type' => 'textfield',
-    '#title' => t('Publication Title'),
+    '#title' => t('Publication ID'),
     '#default_value' => $title,
-    '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/pub/title',
+    '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/pub',
     '#ajax' => array(
       'callback' => "tripal_chado_pub_widget_form_ajax_callback",
       'wrapper' => "$table_name-$delta",
       'effect' => 'fade',
       'method' => 'replace'
     ),
+    '#maxlength' => 100000,
   );
 }
 /**
@@ -143,46 +151,27 @@ function tripal_chado_pub_widget_validate($element, &$form_state) {
   // Get the field values.
   $fkey_value = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__' . $fkey);
   $pub_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__pub_id');
+  $uname = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--pub__uniquename');
 
-  // Make sure that if a pub is provided that a type is also
-  // provided.
-  if (!$title) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $table_name . '__title', t("Please set a pub type."));
-  }
-  // If the user provided a title then we want to set the
+  // If the user provided a uniquename then we want to set the
   // foreign key value to be the chado_record_idd
-  if ($title) {
+  if ($uname) {
 
     // Get the pub. If one with the same name and type is already present
     // then use that. Otherwise, insert a new one.
     if (!$pub_id) {
-      $pub = chado_generate_var('pub', array('name' => $syn_name, 'type_id' => $syn_type));
-      if (!$pub) {
-        $pub = chado_insert_record('pub', array(
-          'name' => $syn_name,
-          'type_id' => $syn_type,
-          'pub_sgml' => '',
-        ));
-        $pub = (object) $pub;
-      }
-
+      $pub = chado_generate_var('pub', array('uniquename' => $uname));
       // Set the pub_id and FK value
       tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
       $fkey_value = $element['#entity']->chado_record_id;
       tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
     }
 
-    if (!$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => 'null'));
-      tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
-    }
   }
   else {
     // If the $syn_name is not set, then remove the linker FK value to the base table.
     tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
     tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__pub_id');
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_internal');
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_current');
   }
 
 }
@@ -202,7 +191,7 @@ function theme_tripal_chado_pub_widget($variables) {
   $layout = "
     <div class=\"pub-widget\">
       <div class=\"pub-widget-item\">" .
-        drupal_render($element[$table_name . '__title']) . "
+        drupal_render($element[$table_name . '--pub__uniquename']) . "
       </div>
     </div>
   ";
@@ -241,14 +230,15 @@ function tripal_chado_pub_field_load($field, $entity, $base_table, $record) {
     'value' => '',
     $field_table . '__' . $fkey_lcolumn => '',
     $field_table . '__' . 'pub_id' => '',
-    $field_table . '__' . 'title' => '',
+    $field_table . '--' . 'pub__uniquename' => '',
   );
 
-  return;
-
   $linker_table = $base_table . '_pub';
-  $options = array('return_array' => 1);
-  //$record = chado_expand_var($record, 'table', $linker_table, $options);
+  $options = array(
+    'return_array' => 1,
+  );
+  $record = chado_expand_var($record, 'table', $linker_table, $options);
+
   if (count($record->$linker_table) > 0) {
     $i = 0;
     foreach ($record->$linker_table as $index => $linker) {
@@ -257,7 +247,7 @@ function tripal_chado_pub_field_load($field, $entity, $base_table, $record) {
         'value' => $linker->$pkey,
         $field_table . '__' . $fkey_lcolumn => $linker->$fkey_lcolumn->$fkey_lcolumn,
         $field_table . '__' . 'pub_id' => $pub->pub_id,
-        $field_table . '__' . 'title' => $pub->title,
+        $field_table . '--' . 'pub__uniquename' => $pub->uniquename,
       );
       $i++;
     }

+ 0 - 387
tripal_chado/includes/loaders/tripal_chado.pub_importers.inc

@@ -1680,390 +1680,3 @@ function tripal_pub_citation_form_submit(&$form_state) {
   tripal_add_job("Create citations ($options[0])", 'tripal_pub', 'tripal_pub_create_citations', $options, $user->uid);
 }
 
-/**
- * Launch the Tripal job to generate citations. Called by tripal jobs
- *
- * @param $options
- *  Options pertaining to what publications to generate citations for.
- *  One of the following must be present:
- *   - all: Create and replace citation for all pubs
- *   - new: Create citation for pubs that don't already have one
- *
- * @ingroup tripal_pub
- */
-function tripal_pub_create_citations($options) {
-  $skip_existing = TRUE;
-  $sql = "
-    SELECT cvterm_id
-    FROM {cvterm}
-    WHERE
-      name = 'Citation' AND
-      cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
-  ";
-  $citation_type_id = chado_query($sql)->fetchField();
-
-  // Create and replace citation for all pubs
-  if ($options == 'all') {
-    $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
-    $skip_existing = FALSE;
-  }
-  // Create citation for pubs that don't already have one
-  else if ($options == 'new') {
-    $sql = "
-      SELECT pub_id
-      FROM {pub} P
-      WHERE
-        (SELECT value
-         FROM {pubprop} PB
-         WHERE type_id = :type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL
-        AND  pub_id <> 1
-    ";
-    $skip_existing = TRUE;
-  }
-
-  $result = chado_query($sql, array(':type_id' => $citation_type_id));
-  $counter_updated = 0;
-  $counter_generated = 0;
-  while ($pub = $result->fetchObject()) {
-    $pub_arr = tripal_pub_get_publication_array($pub->pub_id, $skip_existing);
-    if ($pub_arr) {
-      $citation = tripal_pub_create_citation($pub_arr);
-      print $citation . "\n\n";
-      // Replace if citation exists. This condition is never TRUE if $skip_existing is TRUE
-      if ($pub_arr['Citation']) {
-        $sql = "
-          UPDATE {pubprop} SET value = :value
-          WHERE pub_id = :pub_id  AND type_id = :type_id AND rank = :rank
-        ";
-        chado_query($sql, array(':value' => $citation, ':pub_id' => $pub->pub_id,
-          ':type_id' => $citation_type_id, ':rank' => 0));
-        $counter_updated ++;
-        // Generate a new citation
-      } else {
-        $sql = "
-          INSERT INTO {pubprop} (pub_id, type_id, value, rank)
-          VALUES (:pub_id, :type_id, :value, :rank)
-        ";
-        chado_query($sql, array(':pub_id' => $pub->pub_id, ':type_id' => $citation_type_id,
-          ':value' => $citation, ':rank' => 0));
-        $counter_generated ++;
-      }
-    }
-  }
-  print "$counter_generated citations generated. $counter_updated citations updated.\n";
-}
-
-
-/**
- * This function generates citations for publications.  It requires
- * an array structure with keys being the terms in the Tripal
- * publication ontology.  This function is intended to be used
- * for any function that needs to generate a citation.
- *
- * @param $pub
- *   An array structure containing publication details where the keys
- *   are the publication ontology term names and values are the
- *   corresponding details.  The pub array can contain the following
- *   keys with corresponding values:
- *     - Publication Type:  an array of publication types. a publication can have more than one type
- *     - Authors: a  string containing all of the authors of a publication
- *     - Journal Name:  a string containing the journal name
- *     - Journal Abbreviation: a string containing the journal name abbreviation
- *     - Series Name: a string containing the series (e.g. conference proceedings) name
- *     - Series Abbreviation: a string containing the series name abbreviation
- *     - Volume: the serives volume number
- *     - Issue: the series issue number
- *     - Pages: the page numbers for the publication
- *     - Publication Date:  A date in the format "Year Month Day"
- *
- * @return
- *   A text string containing the citation
- *
- * @ingroup tripal_pub
- */
-function tripal_pub_create_citation($pub) {
-  $citation = '';
-  $pub_type = '';
-
-  // An article may have more than one publication type. For example,
-  // a publication type can be 'Journal Article' but also a 'Clinical Trial'.
-  // Therefore, we need to select the type that makes most sense for
-  // construction of the citation. Here we'll iterate through them all
-  // and select the one that matches best.
-  if (is_array($pub['Publication Type'])) {
-    foreach ($pub['Publication Type'] as $ptype) {
-      if ($ptype == 'Journal Article' ) {
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == 'Conference Proceedings'){
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == 'Review') {
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == 'Book') {
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == 'Letter') {
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == 'Book Chapter') {
-        $pub_type = $ptype;
-        break;
-      }
-      else if ($ptype == "Research Support, Non-U.S. Gov't") {
-        $pub_type = $ptype;
-        // we don't break because if the article is also a Journal Article
-        // we prefer that type
-      }
-    }
-    // If we don't have a recognized publication type, then just use the
-    // first one in the list.
-    if (!$pub_type) {
-      $pub_type = $pub['Publication Type'][0];
-    }
-  }
-  else {
-    $pub_type = $pub['Publication Type'];
-  }
-  //----------------------
-  // Journal Article
-  //----------------------
-  if ($pub_type == 'Journal Article') {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-
-    $citation .= $pub['Title'] .  '. ';
-
-    if (array_key_exists('Journal Name', $pub)) {
-      $citation .= $pub['Journal Name'] . '. ';
-    }
-    elseif (array_key_exists('Journal Abbreviation', $pub)) {
-      $citation .= $pub['Journal Abbreviation'] . '. ';
-    }
-    elseif (array_key_exists('Series Name', $pub)) {
-      $citation .= $pub['Series Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Abbreviation', $pub)) {
-      $citation .= $pub['Series Abbreviation'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
-      $citation .= '; ';
-    }
-    if (array_key_exists('Volume', $pub)) {
-      $citation .= $pub['Volume'];
-    }
-    if (array_key_exists('Issue', $pub)) {
-      $citation .= '(' . $pub['Issue'] . ')';
-    }
-    if (array_key_exists('Pages', $pub)) {
-      if (array_key_exists('Volume', $pub)) {
-        $citation .= ':';
-      }
-      $citation .= $pub['Pages'];
-    }
-    $citation .= '.';
-  }
-  //----------------------
-  // Review
-  //----------------------
-  if ($pub_type == 'Review') {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-
-    $citation .= $pub['Title'] .  '. ';
-
-    if (array_key_exists('Journal Name', $pub)) {
-      $citation .= $pub['Journal Name'] . '. ';
-    }
-    elseif (array_key_exists('Journal Abbreviation', $pub)) {
-      $citation .= $pub['Journal Abbreviation'] . '. ';
-    }
-    elseif (array_key_exists('Series Name', $pub)) {
-      $citation .= $pub['Series Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Abbreviation', $pub)) {
-      $citation .= $pub['Series Abbreviation'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
-      $citation .= '; ';
-    }
-    if (array_key_exists('Volume', $pub)) {
-      $citation .= $pub['Volume'];
-    }
-    if (array_key_exists('Issue', $pub)) {
-      $citation .= '(' . $pub['Issue'] . ')';
-    }
-    if (array_key_exists('Pages', $pub)) {
-      if (array_key_exists('Volume', $pub)) {
-        $citation .= ':';
-      }
-      $citation .= $pub['Pages'];
-    }
-    $citation .= '.';
-  }
-  //----------------------
-  // Research Support, Non-U.S. Gov't
-  //----------------------
-  elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-
-    $citation .= $pub['Title'] .  '. ';
-
-    if (array_key_exists('Journal Name', $pub)) {
-      $citation .= $pub['Journal Name'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    $citation .= '.';
-  }
-  //----------------------
-  // Letter
-  //----------------------
-  elseif ($pub_type == 'Letter') {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-
-    $citation .= $pub['Title'] .  '. ';
-    if (array_key_exists('Journal Name', $pub)) {
-      $citation .= $pub['Journal Name'] . '. ';
-    }
-    elseif (array_key_exists('Journal Abbreviation', $pub)) {
-      $citation .= $pub['Journal Abbreviation'] . '. ';
-    }
-    elseif (array_key_exists('Series Name', $pub)) {
-      $citation .= $pub['Series Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Abbreviation', $pub)) {
-      $citation .= $pub['Series Abbreviation'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
-      $citation .= '; ';
-    }
-    if (array_key_exists('Volume', $pub)) {
-      $citation .= $pub['Volume'];
-    }
-    if (array_key_exists('Issue', $pub)) {
-      $citation .= '(' . $pub['Issue'] . ')';
-    }
-    if (array_key_exists('Pages', $pub)) {
-      if (array_key_exists('Volume', $pub)) {
-        $citation .= ':';
-      }
-      $citation .= $pub['Pages'];
-    }
-    $citation .= '.';
-  }
-  //-----------------------
-  // Conference Proceedings
-  //-----------------------
-  elseif ($pub_type == 'Conference Proceedings') {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-
-    $citation .= $pub['Title'] .  '. ';
-    if (array_key_exists('Conference Name', $pub)) {
-      $citation .= $pub['Conference Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Name', $pub)) {
-      $citation .= $pub['Series Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Abbreviation', $pub)) {
-      $citation .= $pub['Series Abbreviation'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
-      $citation .= '; ';
-    }
-    if (array_key_exists('Volume', $pub)) {
-      $citation .= $pub['Volume'];
-    }
-    if (array_key_exists('Issue', $pub)) {
-      $citation .= '(' . $pub['Issue'] . ')';
-    }
-    if (array_key_exists('Pages', $pub)) {
-      if (array_key_exists('Volume', $pub)) {
-        $citation .= ':';
-      }
-      $citation .= $pub['Pages'];
-    }
-    $citation .= '.';
-  }
-  //-----------------------
-  // Default
-  //-----------------------
-  else {
-    if (array_key_exists('Authors', $pub)) {
-      $citation = $pub['Authors'] . '. ';
-    }
-    $citation .= $pub['Title'] .  '. ';
-    if (array_key_exists('Series Name', $pub)) {
-      $citation .= $pub['Series Name'] . '. ';
-    }
-    elseif (array_key_exists('Series Abbreviation', $pub)) {
-      $citation .= $pub['Series Abbreviation'] . '. ';
-    }
-    if (array_key_exists('Publication Date', $pub)) {
-      $citation .= $pub['Publication Date'];
-    }
-    elseif (array_key_exists('Year', $pub)) {
-      $citation .= $pub['Year'];
-    }
-    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
-      $citation .= '; ';
-    }
-    if (array_key_exists('Volume', $pub)) {
-      $citation .= $pub['Volume'];
-    }
-    if (array_key_exists('Issue', $pub)) {
-      $citation .= '(' . $pub['Issue'] . ')';
-    }
-    if (array_key_exists('Pages', $pub)) {
-      if (array_key_exists('Volume', $pub)) {
-        $citation .= ':';
-      }
-      $citation .= $pub['Pages'];
-    }
-    $citation .= '.';
-  }
-
-  return $citation;
-}

+ 7 - 0
tripal_chado/theme/css/tripal_chado.css

@@ -25,4 +25,11 @@
 
 .form-field-ui-field-overview-storage-logo {
   height: 10px;
+}
+
+
+#edit-feature-pub #autocomplete li {
+  white-space: normal;
+  margin: 0;
+  border-bottom: 0.5px solid #666666;
 }

+ 2 - 2
tripal_chado/tripal_chado.module

@@ -447,9 +447,9 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_CALLBACK,
   );
-  $items['admin/tripal/storage/chado/auto_name/pub/%/%'] = array(
+  $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
     'page callback' => 'tripal_autocomplete_pub',
-    'page arguments' => array(6, 7),
+    'page arguments' => array(6),
     'access arguments' => array('access content'),
     'file' => 'api/modules/tripal_chado.pub.api.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),