Browse Source

Fixed bugs in pub module with checking for duplicates. Also updated dbxref and relationships API to clear out new fields on AJAX callback

Stephen Ficklin 11 years ago
parent
commit
9a7dbcd45a

+ 7 - 0
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -434,6 +434,13 @@ function chado_add_node_form_dbxrefs_add_button_submit(&$form, &$form_state) {
   $key = $dbxref['db_id'] . '-' . $version;
   $form_state['chado_additional_dbxrefs'][$key] = (object) $dbxref;
 
+  
+  // we don't want the new element to pick up the values from the previous element so wipe them out
+  unset($form_state['input']['dbxref_table']['new']['db']);
+  unset($form_state['input']['dbxref_table']['new']['db_name']);
+  unset($form_state['input']['dbxref_table']['new']['dbxref_version']);
+  unset($form_state['input']['dbxref_table']['new']['dbxref_accession']);
+  
   $form_state['rebuild'] = TRUE;
 }
 

+ 1 - 2
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -633,8 +633,7 @@ function chado_add_node_form_properties_add_button_submit(&$form, &$form_state)
   $key = $property['type_id'] . '-' . $property['rank'];
   $form_state['chado_properties'][$key] = (object) $property;
   
-  // we don't want the new element to pick up the values from the previous element
-  // so wipe them out
+  // we don't want the new element to pick up the values from the previous element so wipe them out
   unset($form_state['input']['property_table']['new']['type']);
   unset($form_state['input']['property_table']['new']['type_name']);
   unset($form_state['input']['property_table']['new']['definition']);

+ 14 - 2
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -619,9 +619,11 @@ function chado_add_node_form_relationships_add_button_submit(&$form, &$form_stat
 
   $name = (isset($form_state['node']->{$details['base_table']}->uniquename)) ? $form_state['node']->{$details['base_table']}->uniquename : 'CURRENT';
 
+
+
+  
   // get details for the new relationship
   if ($form_state['values']['relationship_table']['new']['subject_is_current']) {
-
     $relationship = array(
       'type_id' => $form_state['values']['relationship_table']['new']['type_id'],
       'type_name' => $form_state['values']['relationship_table']['new']['type_name'],
@@ -631,6 +633,9 @@ function chado_add_node_form_relationships_add_button_submit(&$form, &$form_stat
       'subject_name' => $name,
       'rank' => '0',
     );
+    // we don't want the new element to pick up the values from the previous element so wipe them out
+    unset($form_state['input']['relationship_table']['new']['object_id']);
+    unset($form_state['input']['relationship_table']['new']['object_name']);
   }
   else {
     $relationship = array(
@@ -642,11 +647,18 @@ function chado_add_node_form_relationships_add_button_submit(&$form, &$form_stat
       'subject_name' => $form_state['values']['relationship_table']['new']['subject_name'],
       'rank' => '0',
     );
+    // we don't want the new element to pick up the values from the previous element so wipe them out
+    unset($form_state['input']['relationship_table']['new']['subject_id']);
+    unset($form_state['input']['relationship_table']['new']['subject_name']);
   }
-
+  
   $key = $relationship['type_id'] . '-' . $relationship['rank'];
   $form_state['chado_relationships'][$key] = (object) $relationship;
 
+  // we don't want the new element to pick up the values from the previous element so wipe them out
+  unset($form_state['input']['relationship_table']['new']['type_id']);
+  unset($form_state['input']['relationship_table']['new']['type_name']);
+  
   $form_state['rebuild'] = TRUE;
 }
 

+ 7 - 4
tripal_pub/api/tripal_pub.api.inc

@@ -411,7 +411,8 @@ function tripal_get_publication($identifiers, $options = array()) {
  *     'Year':               The published year of the publication
  *     'Publication Type':   An array of publication types. A publication can have more than one type.
  *     'Series Name':        The series name of the publication
- *     'Journal Name':       An alternative to 'Series Name' is 'Journal Name'
+ *     'Journal Name':       An alternative to 'Series Name'
+ *     'Conference Name':    An alternative to 'Series Name'
  *     'Citation':           The publication citation (this is the value saved in the pub.uniquename field and must be unique)
  *   If this key is present it will also be checked
  *     'Publication Dbxref': A database cross reference of the form DB:ACCESSION where DB is the name
@@ -472,14 +473,16 @@ function tripal_publication_exists($pub_details) {
 
   // get the series name.  The pub.series_name field is only 255 chars so we must truncate to be safe
   $series_name = '';
-  if (array_key_exists('Series_Name', $pub_details)) {
+  if (array_key_exists('Series Name', $pub_details)) {
     $series_name = substr($pub_details['Series Name'], 0, 255);
   }
   if (array_key_exists('Journal Name', $pub_details)) {
     $series_name = substr($pub_details['Journal Name'], 0, 255);
   }
-
-
+  if (array_key_exists('Conference Name', $pub_details)) {
+    $series_name = substr($pub_details['Conference Name'], 0, 255);
+  }
+  
   // make sure the publication is unique using the prefereed import duplication check
   $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
   $pubs = array();

+ 11 - 34
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -151,12 +151,6 @@ function chado_pub_form($node, $form_state) {
     $is_obsolete  = $form_state['input']['is_obsolete'];
   }
 
-  // a drupal title can only be 255 characters, but the Chado title can be much longer.
-  // we use the publication title as the drupal title, but we'll need to truncate it.
-  $form['title'] = array(
-    '#type' => 'hidden',
-    '#value' => substr($title, 0, 255),
-  );
   $form['pubtitle'] = array(
     '#type' => 'textarea',
     '#title' => t('Publication Title'),
@@ -387,21 +381,6 @@ function chado_pub_validate($node, $form, &$form_state) {
 
     $pub_id = $node->pub_id;
 
-    // first get the original title, type and year before it was changed
-    $values = array('pub_id' => $pub_id);
-    $columns = array('title', 'pyear', 'type_id', 'series_name');
-    $options = array('statement_name' => 'sel_pub_id');
-    $pub = chado_select_record('pub', $columns, $values, $options);
-
-    // if the title, type,  year or series_name have changed then check the pub
-    // to see if it is a duplicate of another
-    if((strcmp(strtolower($pub[0]->title), strtolower($title)) == 0) and
-       (strcmp(strtolower($pub[0]->series_name), strtolower($series_name)) == 0) and
-       ($pub[0]->type_id == $type_id) and
-       ($pub[0]->pyear == $pyear)) {
-      $skip_duplicate_check = 1;
-    }
-
     // check to see if a duplicate publication already exists
     if (!$skip_duplicate_check) {
       chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm[0], $pub_id);
@@ -467,13 +446,11 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
     'Series Name' => $series_name,
     'Publication Type' => $cvterm->name,
   );
+  // TODO: need to include the Publication Dbxref in the $pub_details as well
   $pub_ids = tripal_publication_exists($pub_details);
-//  dpm($pub_ids);
-//  dpm($pub_details);
   
-  // if we found only one publication and it is our publication then 
-  // return, we're good.
-  if (count($pub_ids) == 1 and !in_array($pub_id, $pub_ids)) {
+  // if we found only one publication and it is our publication then return, we're good.
+  if (count($pub_ids) == 1 and in_array($pub_id, $pub_ids)) {
     return;
   }
   if (count($pub_ids) == 0) {
@@ -561,9 +538,9 @@ function chado_pub_node_access($node, $op, $account) {
  */
 function chado_pub_insert($node) {
 
-  $title        = trim($node->pubtitle);
-  $pyear        = trim($node->pyear);
-  $uniquename   = trim($node->uniquename);
+  $node->pubtitle     = trim($node->pubtitle);
+  $node->pyear        = trim($node->pyear);
+  $node->uniquename   = trim($node->uniquename);
   $is_obsolete  = $node->is_obsolete;
   $type_id      = $node->type_id;
 
@@ -766,11 +743,11 @@ function chado_pub_insert($node) {
  * @ingroup tripal_pub
  */
 function chado_pub_update($node) {
-  $title        = trim($node->pubtitle);
-  $pyear        = trim($node->pyear);
-  $uniquename   = trim($node->uniquename);
-  $is_obsolete  = $node->is_obsolete;
-  $type_id      = $node->type_id;
+  $node->pubtitle   = trim($node->pubtitle);
+  $node->pyear      = trim($node->pyear);
+  $node->uniquename = trim($node->uniquename);
+  $is_obsolete      = $node->is_obsolete;
+  $type_id          = $node->type_id;
 
   // we need an array suitable for the tripal_pub_create_citation() function
   // to automatically generate a citation if a uniquename doesn't already exist

+ 25 - 7
tripal_pub/includes/tripal_pub.pub_citation.inc

@@ -212,7 +212,11 @@ function tripal_pub_create_citation($pub) {
   // Journal Article
   //----------------------
   if ($pub_type == 'Journal Article') {
-    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    
+    $citation .= $pub['Title'] .  '. ';
 
     if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
@@ -253,7 +257,11 @@ function tripal_pub_create_citation($pub) {
   // Review
   //----------------------
   if ($pub_type == 'Review') {
-    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    
+    $citation .= $pub['Title'] .  '. ';
 
     if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
@@ -294,7 +302,11 @@ function tripal_pub_create_citation($pub) {
   // Research Support, Non-U.S. Gov't
   //----------------------
   elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
-    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    
+    $citation .= $pub['Title'] .  '. ';
 
     if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
@@ -311,8 +323,11 @@ function tripal_pub_create_citation($pub) {
   // Letter
   //----------------------
   elseif ($pub_type == 'Letter') {
-    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
-
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    
+    $citation .= $pub['Title'] .  '. ';
     if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
     }
@@ -364,8 +379,11 @@ function tripal_pub_create_citation($pub) {
   // Conference Proceedings
   //----------------------
   elseif ($pub_type == 'Conference Proceedings') {
-    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
-
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    
+    $citation .= $pub['Title'] .  '. ';
     if (array_key_exists('Conference Name', $pub)) {
       $citation .= $pub['Conference Name'] . '. ';
     }