Explorar el Código

Added support to insert publication type

spficklin hace 12 años
padre
commit
a33277b5f7
Se han modificado 3 ficheros con 180 adiciones y 77 borrados
  1. 73 60
      tripal_pub/includes/pub_form.inc
  2. 1 0
      tripal_pub/tpub.obo
  3. 106 17
      tripal_pub/tripal_pub.module

+ 73 - 60
tripal_pub/includes/pub_form.inc

@@ -53,7 +53,8 @@ function chado_pub_form($node, $form_state) {
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type'
+    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and 
+      NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
     ORDER BY CVTS.name ASC 
   ";
   ";
   $results = chado_query($sql);
   $results = chado_query($sql);
@@ -76,7 +77,8 @@ function chado_pub_form($node, $form_state) {
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details'
+    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and 
+      NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
     ORDER BY CVTS.name ASC 
   ";
   ";
   $prop_types = chado_query($sql); 
   $prop_types = chado_query($sql); 
@@ -132,8 +134,7 @@ function chado_pub_form($node, $form_state) {
     '#description' => t('All publications must have a unique citation. Please enter the full citation for this publication. 
     '#description' => t('All publications must have a unique citation. Please enter the full citation for this publication. 
       For PubMed style citations list 
       For PubMed style citations list 
       the last name of the author followed by initials. Each author should be separated by a comma. Next comes 
       the last name of the author followed by initials. Each author should be separated by a comma. Next comes 
-      the title, followed by the series title (e.g. journal name), publication date (3 character Month, day, 4 
-      digit year), volume, issue and page numbers. You may also use HTML to provide a link in the citation.  
+      the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.  
       Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations 
       Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations 
         suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52. PubMed PMID: 23462414</pre>'),
         suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52. PubMed PMID: 23462414</pre>'),
     '#required' => TRUE,
     '#required' => TRUE,
@@ -211,60 +212,72 @@ function chado_pub_node_form_add_new_props(&$form, $form_state, $num_new, &$d_pr
   $num_properties++;
   $num_properties++;
 
 
   // we need to find the
   // we need to find the
-  foreach ($form_state['values'] as $element_name => $value) {
-    if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
-      $new_id = $matches[1];
-      $rank = $matches[2];
-      
-      // get this new_id information
-      $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
-      
-      // add it to the $d_properties array
-      $d_properties[$new_id][$rank]['name']  = $cvterm->name;
-      $d_properties[$new_id][$rank]['id']    = $new_id;
-      $d_properties[$new_id][$rank]['value'] = $value;
-      $d_properties[$new_id][$rank]['definition']  = $cvterm->definition;
-      $num_properties++; 
-    
-      // determine how many rows we need in the textarea
-      $rows = 1;
-      if (preg_match('/Abstract/', $cvterm[0]->name)) {
-        $rows = 10;
-      }
-      
-      // adjust the term description if needed
-      $description = $cvterm[0]->definition;
-      if ($cvterm[0]->name == 'Author List') {
-        $description .= ' For PubMed style citations list each author with the last name first, followed by initials. Each author should be separated by a comma.';
-        $rows = 2;
-      }
-      
-      // add the new fields
-      $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
-        '#type'          => 'item',
-        '#value'         => $cvterm[0]->name
-      );
-      $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
-        '#type'          => 'textarea',
-        '#default_value' => $value,
-        '#cols'          => 50,
-        '#rows'          => $rows,
-        '#description'   => $description,
-      );
+  if ($form_state['values']) {
+    foreach ($form_state['values'] as $element_name => $value) {
+      if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
+        $new_id = $matches[1];
+        $rank = $matches[2];
+        
+        // skip any properties that the user requested to delete through a previous
+        // AHAH callback or through the current AHAH callback
+        if($d_removed["$new_id-$rank"]) {
+          continue;
+        }
+        if($form_state['post']['remove-' . $new_id . '-' . $rank]) {
+          $d_removed["$new_id-$rank"] = 1;
+          continue;
+        }
+        
+        // get this new_id information
+        $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
+        
+        // add it to the $d_properties array
+        $d_properties[$new_id][$rank]['name']  = $cvterm->name;
+        $d_properties[$new_id][$rank]['id']    = $new_id;
+        $d_properties[$new_id][$rank]['value'] = $value;
+        $d_properties[$new_id][$rank]['definition']  = $cvterm->definition;
+        $num_properties++; 
       
       
-      $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
-        '#type'         => 'image_button',
-        '#value'        => t('Remove'),
-        '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
-        '#ahah' => array(
-          'path'    => "tripal_pub/properties/minus/$new_id/$rank",
-          'wrapper' => 'tripal-pub-edit-properties-table',
-          'event'   => 'click',
-          'method'  => 'replace',
-        ), 
-        '#attributes' => array('onClick' => 'return false;'),
-      );  
-    }           
+        // determine how many rows we need in the textarea
+        $rows = 1;
+        if (preg_match('/Abstract/', $cvterm[0]->name)) {
+          $rows = 10;
+        }
+        
+        // adjust the term description if needed
+        $description = $cvterm[0]->definition;
+        if ($cvterm[0]->name == 'Author List') {
+          $description .= ' For PubMed style citations list each author with the last name first, followed by initials. Each author should be separated by a comma.';
+          $rows = 2;
+        }
+        
+        // add the new fields
+        $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
+          '#type'          => 'item',
+          '#value'         => $cvterm[0]->name
+        );
+        $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
+          '#type'          => 'textarea',
+          '#default_value' => $value,
+          '#cols'          => 50,
+          '#rows'          => $rows,
+          '#description'   => $description,
+        );
+        
+        $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
+          '#type'         => 'image_button',
+          '#value'        => t('Remove'),
+          '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
+          '#ahah' => array(
+            'path'    => "tripal_pub/properties/minus/$new_id/$rank",
+            'wrapper' => 'tripal-pub-edit-properties-table',
+            'event'   => 'click',
+            'method'  => 'replace',
+          ), 
+          '#attributes' => array('onClick' => 'return false;'),
+        );  
+      }           
+    }
   }
   }
   
   
   
   
@@ -354,7 +367,7 @@ function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_i
     $type_id = $prop->cvterm_id;
     $type_id = $prop->cvterm_id;
     $rank = count($d_properties[$type_id]);
     $rank = count($d_properties[$type_id]);
     
     
-    // skip properties that were handled above
+    // skip properties that are found in the pub table
     if($prop->name == "Volume" or $prop->name == "Volume Title" or 
     if($prop->name == "Volume" or $prop->name == "Volume Title" or 
        $prop->name == "Issue"  or $prop->name == "Pages" or
        $prop->name == "Issue"  or $prop->name == "Pages" or
        $prop->name == "Citation") {
        $prop->name == "Citation") {
@@ -363,11 +376,11 @@ function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_i
     
     
     // skip any properties that the user requested to delete through a previous
     // skip any properties that the user requested to delete through a previous
     // AHAH callback or through the current AHAH callback
     // AHAH callback or through the current AHAH callback
-    if($d_removed[$type_id . '-' . $rank]) {
+    if($d_removed["$type_id-$rank"]) {
       continue;
       continue;
     }
     }
     if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
     if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
-      $d_removed[$type_id . '-0'] = 1;
+      $d_removed["$type_id-$rank"] = 1;
       continue;
       continue;
     }
     }
     
     

+ 1 - 0
tripal_pub/tpub.obo

@@ -148,6 +148,7 @@ relationship: part_of TPUB:0000037 ! Publication Details
 id: TPUB:0000047
 id: TPUB:0000047
 name: Authors
 name: Authors
 relationship: part_of TPUB:0000037 ! Publication Details
 relationship: part_of TPUB:0000037 ! Publication Details
+is_obsolete: true
 
 
 [Term]
 [Term]
 id: TPUB:0000048
 id: TPUB:0000048

+ 106 - 17
tripal_pub/tripal_pub.module

@@ -257,26 +257,114 @@ function chado_pub_insert($node) {
     $pub['pub_id'] = $node->pub_id;
     $pub['pub_id'] = $node->pub_id;
   }
   }
   else {
   else {
-    $values =  array(
-      'title' => $node->title,
-      'volumetitle' => $node->volumetitle,
-      'volume' => $node->volume,
+    // get the list of properties for easy lookup (without doing lots of database queries
+    $properties_list = array();
+    $sql = "
+      SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
+      FROM {cvtermpath} CVTP
+        INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+        INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+        INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
+      WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and 
+        NOT CVTS.is_obsolete = 1
+      ORDER BY CVTS.name ASC 
+    ";
+    $prop_types = chado_query($sql); 
+    $properties = array();
+    while ($prop = db_fetch_object($prop_types)) {
+      $properties_list[$prop->cvterm_id] = $prop->name;
+      // The 'Citation' term is special because it serves
+      // both as a property and as the uniquename for the
+      // pub and we want it stored in both the pub table and the pubprop table
+      if ($prop->name == 'Citation') {
+        $properties[$prop->name][0] = $node->uniquename;   
+      }
+    }    
+    
+    // get the properties that should be added. Properties are in one of two forms: 
+    //  1) prop_value-[type id]-[index]
+    //  2) new_value-[type id]-[index]
+    //  3) new_id, new_value  
+    foreach ($node as $name => $value) {
+      if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
+        $type_id = $matches[1];
+        $index = $matches[2];
+        $name = $properties_list[$type_id];
+        $properties[$name][$index] = $value;
+      }      
+    }
+    if ($node->new_id and $node->new_value) {
+      $type_id = $node->new_id;
+      $index = count($properties[$name]);
+      $name = $properties_list[$type_id];
+      $properties[$name][$index] = $node->new_value;    
+    } 
+    
+    // iterate through all of the properties and remove those that really are
+    // part of the pub table fields
+    foreach ($properties as $name => $element) {
+      $value = $element[0];
+      if ($name == "Volume") {
+        $volume = $value;
+        unset($properties[$name]);
+      } 
+      elseif ($name == "Volume Title") {
+        $volumetitle = $value;
+        unset($properties[$name]);
+      }
+      elseif ($name == "Issue") {
+        $issue = $value;
+        unset($properties[$name]);
+      }
+      elseif ($name == "Pages") {
+        $pages = $value;
+        unset($properties[$name]);
+      }
+      elseif ($name == "Publisher") {
+        $publisher = $value;
+        unset($properties[$name]);
+      }
+      elseif ($name == "Journal Country" or $name == "Published Location") {
+        $pubplace = $value;
+        unset($properties[$name]);
+      }
+    }
+    
+    // insert the pub record
+    $values = array(
+      'title'       => $node->title,
       'series_name' => $node->series_name,
       'series_name' => $node->series_name,
-      'issue' => $node->issue,
-      'pyear' => $node->pyear,
-      'pages' => $node->pages,
-      'miniref' => $node->miniref,
-      'type_id' => $node->type_id,
-      'is_obsolete' => $node->is_obsolete,
-      'publisher' => $node->publisher,
-      'pubplace' => $node->pubplace,
-      'uniquename' => $node->uniquename,
-      'type_id' => $node->type_id
+      'type_id'     => $node->type_id,
+      'pyear'       => $node->pyear,
+      'is_obsolete' => $node->is_obsolete ? 'true' : 'false', 
+      'uniquename'  => $node->uniquename,
+      'volumetitle' => $volumetitle,
+      'volume'      => $volume,    
+      'issue'       => $issue,    
+      'pages'       => $pages,
+      'miniref'     => $miniref,        
+      'publisher'   => $publisher,
+      'pubplace'    => $pubplace,
     );
     );
     $pub = tripal_core_chado_insert('pub', $values);
     $pub = tripal_core_chado_insert('pub', $values);
+    if (!$pub) {
+      drupal_set_message("Error inserting publication", "error");
+      watchdog('tripal_pub', "Error inserting publication", array(), WATCHDOG_ERROR);
+      return;
+    }
     
     
-
-  }
+    // now add in the properties 
+    foreach ($properties as $property => $elements) {
+      foreach ($elements as $rank => $value) {      
+        $status = tripal_pub_insert_property($pub['pub_id'], $property, $value, FALSE);
+        if (!$status) {
+          drupal_set_message("Error cannot add property: $property", "error");
+          watchdog('tripal_pub', "Error cannot add property: %prop", 
+            array('%property' => $property), WATCHDOG_ERROR);
+        }
+      } 
+    }
+  } // if ($node->pub_id) {} else 
 
 
   if ($pub) {   
   if ($pub) {   
     // make sure the entry for this feature doesn't already exist in the chado_pub table
     // make sure the entry for this feature doesn't already exist in the chado_pub table
@@ -326,7 +414,8 @@ function chado_pub_update($node) {
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
       INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details'
+    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details'  and 
+      NOT CVTS.is_obsolete = 1    
     ORDER BY CVTS.name ASC 
     ORDER BY CVTS.name ASC 
   ";
   ";
   $prop_types = chado_query($sql); 
   $prop_types = chado_query($sql);