Kaynağa Gözat

Updated analysis, contact, featuremap, project, pub and stock to use the new properties api

Lacey Sanderson 11 yıl önce
ebeveyn
işleme
571c4d5db3

+ 54 - 69
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -29,7 +29,7 @@ function tripal_analysis_node_info() {
     )
   );
   return $nodes;
-} 
+}
 /**
  *  When editing or creating a new node of type 'chado_analysis' we need
  *  a form.  This function creates the form that will be used for this.
@@ -38,13 +38,13 @@ function tripal_analysis_node_info() {
  */
 function chado_analysis_form($node, &$form_state) {
   $form = array();
-  
+
   // Default values can come in the following ways:
   //
   // 1) as elements of the $node object.  This occurs when editing an existing analysis
-  // 2) in the $form_state['values'] array which occurs on a failed validation or 
+  // 2) in the $form_state['values'] array which occurs on a failed validation or
   //    ajax callbacks from non submit form elements
-  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit 
+  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
   //    form elements and the form is being rebuilt
   //
   // set form field defaults
@@ -60,7 +60,7 @@ function chado_analysis_form($node, &$form_state) {
   $description    = '';
   $d_removed      = array(); // lists removed properties
   $num_new        = 0;  // the number of new rows
-  
+
   // if we are editing an existing node then the analysis is already part of the node
   if (property_exists($node, 'analysis')) {
     $analysis = $node->analysis;
@@ -77,14 +77,14 @@ function chado_analysis_form($node, &$form_state) {
     $sourceuri      = $analysis->sourceuri;
     $timeexecuted   = $analysis->timeexecuted;
     $description    = $analysis->description;
-     
+
     // set the analysis_id in the form
     $form['analysis_id'] = array(
       '#type' => 'value',
       '#value' => $analysis->analysis_id,
     );
   }
-  // if we are re constructing the form from a failed validation or ajax callback 
+  // if we are re constructing the form from a failed validation or ajax callback
   // then use the $form_state['values'] values
   if (array_key_exists('values', $form_state)) {
     $analysisname   = $form_state['values']['analysisname'];
@@ -122,7 +122,7 @@ function chado_analysis_form($node, &$form_state) {
   $form['instructions'] = array(
     '#markup' => t('<b>Note</b>: When adding any type of data it is good to associate it with
         an analysis so that site visitors can identify the source of the data including
-        necessary materials and methods.  The fields below imply that all analyses 
+        necessary materials and methods.  The fields below imply that all analyses
         are derived from some software package. But, data can also be derived via retreival
         from an external source or an analysis pipeline with multipel software components.
         In these cases, provide values for the fields below that best makes sense
@@ -214,29 +214,24 @@ function chado_analysis_form($node, &$form_state) {
        someone to recreate the analysis, including materials and methods
        for collection of the source data and performing the analysis'),
   );
-  
-  // get the analysis properties
-  $properties = array();
-  $properties[] = 'Select a Property';
-  $sql = "
-    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-    FROM  {cvterm} CVT
-      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-    WHERE
-      CV.name = 'analysis_property' AND
-      NOT CVT.is_obsolete = 1
-    ORDER BY CVT.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  
+
+
   $exclude = array();
   $include = array();
+
+
+  // Properties Form
+  // ----------------------------------
   $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the analysis_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
-  tripal_core_properties_form($form, $form_state, 'analysisprop', 'analysis_id', 'analysis_property',
-    $properties, $analysis_id, $exclude, $include, $instructions, 'Properties');
+  $details = array(
+    'property_table' => 'analysisprop',
+    'base_foreign_key' => 'analysis_id',
+    'base_key_value' => $analysis_id,
+    'cv_name' => 'analysis_property',
+    'fieldset_title' => 'Properties',
+    'additional_instructions' => $instructions
+  );
+  chado_node_properties_form($form, $form_state, $details);
 
   return $form;
 }
@@ -268,26 +263,26 @@ function tripal_analysis_validate($node, $form, &$form_state) {
   $node->sourcename = trim($node->sourcename);
   $node->sourceversion = trim($node->sourceversion);
   $node->sourceuri = trim($node->sourceuri);
- 
+
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
   }
-  
+
   // we are syncing if we do not have a node ID but we do have a analysis_id. We don't
   // need to validate during syncing so just skip it.
   if (is_null($node->nid) and property_exists($node, 'analysis_id') and $node->analysis_id != 0) {
     return;
   }
-  
+
   // Validating for an update
   if (!is_null($node->nid)) {
-   
-    // get the existing node    
-    $values = array('analysis_id' => $node->analysis_id);      
+
+    // get the existing node
+    $values = array('analysis_id' => $node->analysis_id);
     $result = tripal_core_chado_select('analysis', array('*'), $values);
     $analysis = $result[0];
-      
+
     // if the name has changed make sure it doesn't conflict with an existing name
     if ($analysis->name != $node->analysisname) {
       $values = array('name' => $node->analysisname);
@@ -295,12 +290,12 @@ function tripal_analysis_validate($node, $form, &$form_state) {
       if ($result and count($result) > 0) {
         form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
         return;
-      }  
+      }
     }
-    
+
     // if the unique constraint has changed check to make sure it doesn't conflict with an
     // existing record
-    if ($analysis->program != $node->program or $analysis->programversion != $node->programversion or 
+    if ($analysis->program != $node->program or $analysis->programversion != $node->programversion or
        $analysis->sourcename != $node->sourcename) {
       $values = array(
         'program' => $node->program,
@@ -310,18 +305,18 @@ function tripal_analysis_validate($node, $form, &$form_state) {
       $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
       if ($result and count($result) > 0) {
         if ($analysis->program != $node->program) {
-          $field = 'program';  
+          $field = 'program';
         }
         if ($analysis->programversion != $node->programversion) {
-          $field = 'programversion';  
+          $field = 'programversion';
         }
         if ($analysis->sourcename != $node->sourcename) {
-          $field = 'sourcename';  
+          $field = 'sourcename';
         }
         form_set_error($field, 'Cannot update the analysis with this program,
           program version and source name. An analysis with these values already exists.');
         return;
-      }  
+      }
     }
   }
   // Validating for an insert
@@ -337,10 +332,10 @@ function tripal_analysis_validate($node, $form, &$form_state) {
         program version and source name. An analysis with these values already exists.');
       return;
     }
-    
-    // make sure we have a unique analysis name. This is not a requirement 
+
+    // make sure we have a unique analysis name. This is not a requirement
     // for the analysis table but we use the analysis name for the Drupal node
-    // title, so it should be unique      
+    // title, so it should be unique
     $values = array('name' => $node->analysisname);
     $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
     if ($result and count($result) > 0) {
@@ -402,18 +397,13 @@ function chado_analysis_insert($node) {
     $analysis_id = $analysis['analysis_id'];
 
     // now add in the properties
-    $properties = tripal_core_properties_form_retreive($node, 'analysis_property');
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-
-        $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_analysis', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
-      }
-    }
+    $details = array(
+      'property_table' => 'analysisprop',
+      'base_table' => 'analysis',
+      'foreignkey_name' => 'analysis_id',
+      'foreignkey_value' => $analysis_id
+    );
+    chado_node_properties_form_update_properties($node, $details);
   }
   else {
     $analysis_id = $node->analysis_id;
@@ -516,18 +506,13 @@ function chado_analysis_update($node) {
 
   // now add in the properties by first removing any the analysis
   // already has and adding the ones we have
-  tripal_core_chado_delete('analysisprop', array('analysis_id' => $analysis_id));
-  $properties = tripal_core_properties_form_retreive($node, 'analysis_property');
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
-      if (!$status) {
-        drupal_set_message("Error cannot add property: '$property'", "error");
-        watchdog('t_analysis', "Error cannot add property: '%prop'",
-        array('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
+  $details = array(
+    'property_table' => 'analysisprop',
+    'base_table' => 'analysis',
+    'foreignkey_name' => 'analysis_id',
+    'foreignkey_value' => $analysis_id
+  );
+  chado_node_properties_form_update_properties($node, $details);
 }
 /**
  *  When a node is requested by the user this function is called to allow us

+ 52 - 67
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -62,16 +62,16 @@ function chado_contact_form(&$node, $form_state) {
   $type_id     = 0;
   $title       = '';
   $description = '';
-  
+
   // if we are editing an existing node then the contact is already part of the node
   if (property_exists($node, 'contact')) {
     $contact = $node->contact;
     $contact_id = $contact->contact_id;
-    
+
     // get form defaults
     $type_id     = $contact->type_id->cvterm_id;
     $title       = $contact->name;
-    
+
     // get the contact default values.  When this module was first created
     // the contact description was incorrectly stored in the $node->body field.
     // It is better to store it in the Chado tables.  However, the 'description'
@@ -93,7 +93,7 @@ function chado_contact_form(&$node, $form_state) {
       $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
       $description = $contactprop->value;
     }
-     
+
     // set the contact_id in the form
     $form['contact_id'] = array(
       '#type' => 'value',
@@ -124,14 +124,14 @@ function chado_contact_form(&$node, $form_state) {
       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} CV       ON CVTO.cv_id = CV.cv_id
-    WHERE 
-      CV.name = 'tripal_contact' AND 
+    WHERE
+      CV.name = 'tripal_contact' AND
       CVTO.name = 'Contact Type' AND
       CVTP.pathdistance = 1
-    ORDER BY CVTS.name ASC 
+    ORDER BY CVTS.name ASC
   ";
   $results = chado_query($sql);
-  $contact_types = array();
+  $contact_types = array(3723 => 'Person');
   while ($contact_type = $results->fetchObject()) {
     $contact_types[$contact_type->cvterm_id] = $contact_type->name;
     if (strcmp($contact_type->name, "Person") == 0 and !$type_id) {
@@ -145,7 +145,7 @@ function chado_contact_form(&$node, $form_state) {
     '#required' => TRUE,
     '#default_value' => $type_id,
   );
-  
+
   $form['title']= array(
     '#type'          => 'textfield',
     '#title'         => t('Contact Name'),
@@ -163,30 +163,29 @@ function chado_contact_form(&$node, $form_state) {
     '#default_value' => $description,
   );
 
-  // get the contact properties that the user can use for this form
-  $properties = array();
-  $properties[] = 'Select a Property';
-  $sql = "
-    SELECT CVTS.cvterm_id, CVTS.name
-    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} CV       ON CVTO.cv_id = CV.cv_id
-    WHERE
-      CV.name = 'tripal_contact' AND
-      NOT CVTO.name = 'Contact Type'
-    ORDER BY CVTS.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  
+  // Properties Form
+  // ----------------------------------
+  // D7 @TODO: Properties API doesn't handle using cvtermpath to get options
+  // SELECT CVTS.cvterm_id, CVTS.name
+  // 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} CV       ON CVTO.cv_id = CV.cv_id
+  // WHERE
+  //   CV.name = 'tripal_contact' AND
+  //   NOT CVTO.name = 'Contact Type'
+  // ORDER BY CVTS.name ASC
+
+  // D7 @TODO: Properties API doesn't handle Exclude
   $exclude = array('contact_description');
-  $include = array();
-  tripal_core_properties_form($form, $form_state, 'contactprop', 'contact_id', 'tripal_contact',
-    $properties, $contact_id, $exclude, $include, '', 'Properties');
-   
+  $details = array(
+    'property_table' => 'contactprop',
+    'base_foreign_key' => 'contact_id',
+    'base_key_value' => $contact_id,
+    'cv_name' => 'tripal_contact'
+  );
+  chado_node_properties_form($form, $form_state, $details);
+
   return $form;
 }
 
@@ -199,25 +198,25 @@ function chado_contact_validate($node, $form, &$form_state) {
   // remove surrounding white-space on submitted values
   $node->title          = trim($node->title);
   $node->description    = trim($node->description);
- 
+
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
   }
-  
+
   // we are syncing if we do not have a node ID but we do have a contact_id. We don't
   // need to validate during syncing so just skip it.
   if (is_null($node->nid) and property_exists($node, 'contact_id') and $node->contact_id != 0) {
     return;
   }
-  
+
   // Validating for an update
-  if (property_exists($node, 'nid')) {    
-    // get the existing node    
+  if (property_exists($node, 'nid')) {
+    // get the existing node
     $values = array('contact_id' => $node->contact_id);
     $result = tripal_core_chado_select('contact', array('*'), $values);
     $contact = $result[0];
-      
+
     // if the name has changed make sure it doesn't conflict with an existing name
     if ($contact->name != $node->title) {
       $values = array('name' => $node->title);
@@ -225,7 +224,7 @@ function chado_contact_validate($node, $form, &$form_state) {
       if ($result and count($result) > 0) {
         form_set_error('title', 'Cannot update the contact with this contact name. A contact with this name already exists.');
         return;
-      }  
+      }
     }
   }
   // Validating for an insert
@@ -329,21 +328,13 @@ function chado_contact_insert($node) {
     $contact_id = $contact['contact_id'];
 
     // now add in the properties
-    $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-
-        $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_contact', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
-      }
-    }
-
-    // add in the description as a separate property
-    tripal_contact_insert_property($contact_id, 'contact_description', $node->description, FALSE);
+    $details = array(
+      'property_table' => 'contactprop',
+      'base_table' => 'contact',
+      'foreignkey_name' => 'contact_id',
+      'foreignkey_value' => $contact_id
+    );
+    chado_node_properties_form_update_properties($node, $details);
   }
   else {
     $contact_id = $node->contact_id;
@@ -400,19 +391,13 @@ function chado_contact_update($node) {
 
   // now add in the properties by first removing any the contact
   // already has and adding the ones we have
-  tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
-  $properties = tripal_core_properties_form_retreive($node, 'tripal_contact');
-
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
-      if (!$status) {
-        drupal_set_message("Error cannot add property: '$property'", "error");
-        watchdog('t_contact', "Error cannot add property: '%prop'",
-        array('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
+  $details = array(
+    'property_table' => 'contactprop',
+    'base_table' => 'contact',
+    'foreignkey_name' => 'contact_id',
+    'foreignkey_value' => $contact_id
+  );
+  chado_node_properties_form_update_properties($node, $details);
 
   // add in the description as a separate property
   tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);

+ 17 - 5
tripal_core/api/tripal_core.properties.api.inc

@@ -40,7 +40,7 @@
     );
 
     // Finally, and add the additional form elements to the form
-    tripal_api_chado_node_properties_form($form, $form_state, $details);
+    chado_node_properties_form($form, $form_state, $details);
 
     return $form;
   }
@@ -534,7 +534,7 @@ function chado_node_properties_form(&$form, &$form_state, $details) {
   else {
     if (isset($details['cv_name'])) {
       $existing_properties = chado_query(
-        "SELECT CVT.cvterm_id, CVT.name as type_name, CVT.definition, PP.value, PP.rank
+        "SELECT PP.".$details['property_table']."_id property_id, CVT.cvterm_id as type_id, CVT.name as type_name, CVT.definition, PP.value, PP.rank
         FROM {" . $details['property_table'] . "} PP
         INNER JOIN {cvterm} CVT ON CVT.cvterm_id = PP.type_id
         INNER JOIN {cv} CV      ON CVT.cv_id     = CV.cv_id
@@ -702,6 +702,8 @@ function chado_node_properties_form(&$form, &$form_state, $details) {
     )
   );
 
+  ddl($form, 'form');
+  ddl($form_state, 'form state');
 }
 
 /**
@@ -792,6 +794,8 @@ function chado_node_properties_form_remove_button_submit(&$form, &$form_state) {
     chado_node_properties_form_create_property_formstate_array($form, $form_state);
   }
 
+  ddl($form_state, 'form state in remove');
+
   // remove the specified property from the form property table
   if(preg_match('/property_remove-([^-]+-[^-]+)/',$form_state['triggering_element']['#name'],$match)) {
     $key = $match[1];
@@ -835,7 +839,7 @@ function chado_node_properties_form_create_property_formstate_array($form, &$for
       foreach (element_children($form['properties']['property_table'][$type_id]) as $rank) {
           $element = $form['properties']['property_table'][$type_id][$rank];
           $property = array(
-            'type_id' => $element['type_id']['#value'],
+            'type_id' => $element['prop_type_id']['#value'],
             'type_name' => $element['type']['#markup'],
             'property_id' => $element['property_id']['#value'],
             'value' => $element['value']['#markup'],
@@ -931,14 +935,22 @@ function chado_node_properties_form_retreive($node) {
  *   - base_table: the name of the base table (ie: feature)
  *   - foreignkey_name: the name of the foreign key used to link to the node content (ie: feature_id)
  *   - foreignkey_value: the value of the foreign key (ie: 445, if there exists a feature where feature_id=445)
+ * @param $retrieved_properties
+ *   An array of properties from chado_node_properties_form_retreive($node). This can be used if you need
+ *   special handling for some of the properties (See FeatureMap chado_featuremap_insert for an example)
  */
-function chado_node_properties_form_update_properties($node, $details) {
+function chado_node_properties_form_update_properties($node, $details, $retrieved_properties = FALSE) {
 
   // First remove existing property links
   tripal_core_chado_delete($details['property_table'], array($details['foreignkey_name'] => $details['foreignkey_value']));
 
   // Add back in property links and insert properties as needed
-  $properties = chado_node_properties_form_retreive($node);
+  if ($retrieved_properties) {
+    $properties = $retrieved_properties;
+  }
+  else {
+    $properties = chado_node_properties_form_retreive($node);
+  }
   foreach ($properties as $type_id => $ranks) {
     foreach ($ranks as $rank => $value) {
 

+ 9 - 3
tripal_core/tripal_core.module

@@ -415,13 +415,19 @@ function tripal_core_theme($existing, $type, $theme, $path) {
       'path' => "$path/theme"
     ),
 
-    // additional dbxrefs form theme
+    // Chado Node API Themes
+    // --------------------------------
+    // Properties Node Form
+    'chado_node_properties_form_table' => array(
+      'function' => 'theme_chado_node_properties_form_table',
+      'render element' => 'element',
+    ),
+    // Additional Dbxrefs Nore Form
     'tripal_core_additional_dbxrefs_form_table' => array(
       'function' => 'theme_tripal_core_additional_dbxrefs_form_table',
       'render element' => 'element',
     ),
-
-    // relationships form theme
+    // Relationships Nore Form
     'tripal_core_relationships_form_table' => array(
       'function' => 'theme_tripal_core_relationships_form_table',
       'render element' => 'element',

+ 75 - 83
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -39,7 +39,7 @@ function tripal_featuremap_node_info() {
  */
 function chado_featuremap_form($node, &$form_state) {
   $form = array();
-  
+
   // Default values can come in the following ways:
   //
   // 1) as elements of the $node object.  This occurs when editing an existing library
@@ -53,18 +53,18 @@ function chado_featuremap_form($node, &$form_state) {
   $title = '';
   $description = '';
   $unittype_id = '';
-  
+
   // if we are editing an existing node then the featuremap is already part of the node
   if (property_exists($node, 'featuremap')) {
     $featuremap = $node->featuremap;
     $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
     $featuremap_id = $featuremap->featuremap_id;
-    
+
     // get form defaults
     $title       = $featuremap->name;
     $description = $featuremap->description;
     $unittype_id = $featuremap->unittype_id->cvterm_id;
-    
+
     // set the featuremap_id in the form
     $form['featuremap_id'] = array(
       '#type' => 'hidden',
@@ -85,7 +85,7 @@ function chado_featuremap_form($node, &$form_state) {
     $description = $form_state['input']['description'];
     $unittype_id = $form_state['input']['unittype_id'];
   }
-  
+
   $form['title']= array(
     '#type'          => 'textfield',
     '#title'         => t('Map Name'),
@@ -125,28 +125,18 @@ function chado_featuremap_form($node, &$form_state) {
     '#options'     => $units,
   );
 
-  // get the featuremap properties
-  $properties = array();
-  $properties[] = 'Select a Property';
-  $sql = "
-    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-    FROM  {cvterm} CVT
-      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-    WHERE 
-      CV.name = 'featuremap_property' AND 
-      NOT CVT.is_obsolete = 1
-    ORDER BY CVT.name ASC 
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-
-  $exclude = array();
-  $include = array();
+  // Properties Form
+  // ----------------------------------
   $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the featuremap_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
-  tripal_core_properties_form($form, $form_state, 'featuremapprop', 'featuremap_id', 'featuremap_property',
-    $properties, $featuremap_id, $exclude, $include, $instructions, 'Properties');
+  $details = array(
+    'property_table' => 'featuremapprop',
+    'base_foreign_key' => 'featuremap_id',
+    'base_key_value' => $featuremap_id,
+    'cv_name' => 'featuremap_property',
+    'fieldset_name' => 'Additional Details',
+    'additional_instructions' => $instructions
+  );
+  chado_node_properties_form($form, $form_state, $details);
 
   return $form;
 }
@@ -158,12 +148,12 @@ function chado_featuremap_form($node, &$form_state) {
 function chado_featuremap_validate($node, $form, &$form_state) {
   $node->title          = trim($node->title);
   $node->description    = trim($node->description);
-  
+
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
   }
-  
+
   // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
   // need to validate during syncing so just skip it.
   if (is_null($node->nid) and property_exists($node, 'featuremap_id') and $node->featuremap_id != 0) {
@@ -178,7 +168,7 @@ function chado_featuremap_validate($node, $form, &$form_state) {
   // for a case where the name already exists.
   if (property_exists($node, 'featuremap_id')) {
     $sql = "
-      SELECT * FROM {featuremap} 
+      SELECT * FROM {featuremap}
       WHERE name = :name AND NOT featuremap_id = :featuremap_id
     ";
     $featuremap = chado_query($sql, array(':name' => $node->title, ':featuremap_id' => $node->featuremap_id))->fetchObject();
@@ -259,12 +249,12 @@ function chado_featuremap_insert($node) {
 
   $node->title          = trim($node->title);
   $node->description    = trim($node->description);
-  
+
   // if there is an featuremap_id in the $node object then this must be a sync so
   // we can skip adding the featuremap as it is already there, although
   // we do need to proceed with the rest of the insert
   if (!property_exists($node, 'featuremap_id')) {
-    
+
     $values = array(
       'name'        => $node->title,
       'description' => $node->description,
@@ -279,33 +269,33 @@ function chado_featuremap_insert($node) {
     }
     $featuremap_id = $featuremap['featuremap_id'];
 
-    // get the properties from the form
-    $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
-    
     // now add in the properties
-    $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-        // if the property name is 'Map Dbxref' then save this as a Dbxref record not a property
-        if ($property == 'Map Dbxref') {
-          $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
-          if (!$featuremap_dbxref) {
-            drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
-            watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
-            array('%ref' => $value), WATCHDOG_ERROR);
-          }
-        }
-        // this is a property so add it 
-        else {
-          $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE, 'featuremap_property');
-          if (!$status) {
-            drupal_set_message("Error cannot add property: $property", "error");
-            watchdog('t_featuremap', "Error cannot add property: %prop",
-            array('%property' => $property), WATCHDOG_ERROR);
-          }
+    $properties = chado_node_properties_form_retreive($node);
+    // We need to deal with the 'Map Dbxref' property specially
+    $cvterm = tripal_core_chado_select(
+      'cvterm',
+      array('cvterm_id'),
+      array('name' => 'Map Dbxref', 'cv_id' => array('name' => 'featuremap_property'))
+    );
+    $map_dbxref_cvterm_id = $cvterm[0]->cvterm_id;
+    if (isset($properties[$map_dbxref_cvterm_id])) {
+      foreach ($properties[$map_dbxref_cvterm_id] as $rank => $value) {
+        $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
+        if (!$featuremap_dbxref) {
+          drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
+          watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
+          array('%ref' => $value), WATCHDOG_ERROR);
         }
       }
+      unset($properties[$map_dbxref_cvterm_id]);
     }
+    $details = array(
+      'property_table' => 'featuremapprop',
+      'base_table' => 'featuremap',
+      'foreignkey_name' => 'featuremap_id',
+      'foreignkey_value' => $featuremap_id
+    );
+    chado_node_properties_form_update_properties($node, $details, $properties);
   }
   else {
     $featuremap_id = $node->featuremap_id;
@@ -328,10 +318,10 @@ function chado_featuremap_insert($node) {
  * @ingroup tripal_featuremap
  */
 function chado_featuremap_update($node) {
-  
+
   $node->title          = trim($node->title);
   $node->description    = trim($node->description);
-  
+
   $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
 
   // update the map record
@@ -350,32 +340,34 @@ function chado_featuremap_update($node) {
     return;
   }
 
-  // get the properties from the form
-  $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
-  
-  tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      // if the property name is 'Map Dbxref' then save this as a Dbxref record not a property
-      if ($property == 'Map Dbxref') {
-        $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
-        if (!$featuremap_dbxref) {
-          drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
-          watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
-          array('%ref' => $value), WATCHDOG_ERROR);
-        }
-      }
-      // this is a property so add it
-      else {
-        $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE, 'featuremap_property');
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_featuremap', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
+  // Update the properties
+  $properties = chado_node_properties_form_retreive($node);
+  // We need to deal with the 'Map Dbxref' property specially
+  $cvterm = tripal_core_chado_select(
+    'cvterm',
+    array('cvterm_id'),
+    array('name' => 'Map Dbxref', 'cv_id' => array('name' => 'featuremap_property'))
+  );
+  $map_dbxref_cvterm_id = $cvterm[0]->cvterm_id;
+  if (isset($properties[$map_dbxref_cvterm_id])) {
+    foreach ($properties[$map_dbxref_cvterm_id] as $rank => $value) {
+      $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
+      if (!$featuremap_dbxref) {
+        drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
+        watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
+        array('%ref' => $value), WATCHDOG_ERROR);
       }
     }
+    unset($properties[$map_dbxref_cvterm_id]);
   }
+  $details = array(
+    'property_table' => 'featuremapprop',
+    'base_table' => 'featuremap',
+    'foreignkey_name' => 'featuremap_id',
+    'foreignkey_value' => $featuremap_id
+  );
+  chado_node_properties_form_update_properties($node, $details, $properties);
+
 }
 /**
  *  When a node is requested by the user this function is called to allow us
@@ -387,13 +379,13 @@ function chado_featuremap_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // get the feature details from chado
     $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
-  
+
     $values = array('featuremap_id' => $featuremap_id);
     $featuremap = tripal_core_generate_chado_var('featuremap', $values);
-  
+
     // expand the description field as it is needed by the form
     $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
-  
+
     $nodes[$nid]->featuremap = $featuremap;
   }
 
@@ -425,7 +417,7 @@ function chado_featuremap_delete(&$node) {
   chado_query("DELETE FROM {featuremapprop}    WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
   chado_query("DELETE FROM {featuremap_dbxref} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
   chado_query("DELETE FROM {featuremap}        WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
-  
+
 }
 /**
  *

+ 46 - 72
tripal_project/includes/tripal_project.chado_node.inc

@@ -55,7 +55,7 @@ function tripal_project_node_info() {
  */
 function chado_project_form(&$node, $form_state) {
   $form = array();
-  
+
   // Default values can come in the following ways:
   //
   // 1) as elements of the $node object.  This occurs when editing an existing project
@@ -68,7 +68,7 @@ function chado_project_form(&$node, $form_state) {
   $project_id = null;
   $title = '';
   $description = '';
-  
+
   // if we are editing an existing node then the project is already part of the node
   if (property_exists($node, 'project')) {
     $project = $node->project;
@@ -92,10 +92,10 @@ function chado_project_form(&$node, $form_state) {
       $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
       $description = $projectprop->value;
     }
-    
+
     $title = $project->name;
     $project_id = $project->project_id;
-    
+
     // keep track of the project id if we have.  If we do have one then
     // this is an update as opposed to an insert.
     $form['project_id'] = array(
@@ -103,7 +103,7 @@ function chado_project_form(&$node, $form_state) {
       '#value' => $project_id,
     );
   }
-  
+
   // if we are re constructing the form from a failed validation or ajax callback
   // then use the $form_state['values'] values
   if (array_key_exists('values', $form_state)) {
@@ -133,40 +133,24 @@ function chado_project_form(&$node, $form_state) {
     '#default_value' => $description,
   );
 
-  // get the project properties
-  $properties = array();
-  $properties[] = 'Select a Property';
-  $sql = "
-    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-    FROM  {cvterm} CVT
-      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-    WHERE
-      CV.name = 'project_property' AND
-      NOT CVT.is_obsolete = 1
-    ORDER BY CVT.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    // because we are using the project description property as
-    // a replacement for the project.description field and we want the 
-    // user to add a description in the field above, we remove the property
-    // from the list.
-    if (strcmp($prop->name, "Project Description")==0) {
-      continue;
-    }
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  
-  // we want to exclude the project description from being loaded as a stored property 
+  // Properties Form
+  // ----------------------------------
+  // D7 @TODO: Properties API doesn't handle exclude
+  // we want to exclude the project description from being loaded as a stored property
   // because we want to use the property to replace the project.description field as it is
-  // only 255 characters which isn't large enough. We don't want the user to set it 
-  // as a property even though it will be stored as a property. 
+  // only 255 characters which isn't large enough. We don't want the user to set it
+  // as a property even though it will be stored as a property.
   $exclude = array('Project Description');
-  $include = array();
   $instructions = t('To add properties to the drop down list, you must ' . l("add terms to the project_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
-  tripal_core_properties_form($form, $form_state, 'projectprop', 'project_id', 'project_property',
-    $properties, $project_id, $exclude, $include, $instructions, 'Properties');
-  
+  $details = array(
+    'property_table' => 'projectprop',
+    'base_foreign_key' => 'project_id',
+    'base_key_value' => $project_id,
+    'cv_name' => 'project_property',
+    'additional_instructions' => $instructions
+  );
+  chado_node_properties_form($form, $form_state, $details);
+
   return $form;
 
 }
@@ -176,21 +160,21 @@ function chado_project_form(&$node, $form_state) {
  * @ingroup tripal_project
  */
 function chado_project_validate($node, $form, &$form_state) {
-  
+
   $node->title = trim($node->title);
   $node->description = trim($node->description);
-  
+
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
   }
-  
+
   // we are syncing if we do not have a node ID but we do have a project_id. We don't
   // need to validate during syncing so just skip it.
   if (is_null($node->nid) and property_exists($node, 'project_id') and $node->project_id != 0) {
     return;
   }
-  
+
   $project = 0;
   // check to make sure the name on the project is unique
   // before we try to insert into chado.
@@ -219,7 +203,7 @@ function chado_project_insert($node) {
 
   $node->title = trim($node->title);
   $node->description = trim($node->description);
-  
+
   // if there is an project_id in the $node object then this must be a sync so
   // we can skip adding the project as it is already there, although
   // we do need to proceed with the rest of the insert
@@ -236,21 +220,16 @@ function chado_project_insert($node) {
       return;
     }
     $project_id = $project['project_id'];
-    
+
     // now add in the properties
-    $properties = tripal_core_properties_form_retreive($node, 'project_property');
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-    
-        $status = tripal_project_insert_property($project_id, $property, $value, FALSE, 'project_property');
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_project', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
-      }
-    }
-    
+    $details = array(
+      'property_table' => 'projectprop',
+      'base_table' => 'project',
+      'foreignkey_name' => 'project_id',
+      'foreignkey_value' => $project_id
+    );
+    chado_node_properties_form_update_properties($node, $details);
+
     // add in the description as a separate property
     tripal_project_insert_property($project_id, 'Project Description', $node->description, FALSE);
   }
@@ -316,7 +295,7 @@ function chado_project_delete($node) {
  * @ingroup tripal_project
  */
 function chado_project_update($node) {
-  
+
   $node->title = trim($node->title);
   $node->description = trim($node->description);
 
@@ -333,22 +312,17 @@ function chado_project_update($node) {
     watchdog('tripal_project', 'Update project: Unable to update project where values: %values',
     array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
   }
-  
+
   // now add in the properties by first removing any the project
   // already has and adding the ones we have
-  tripal_core_chado_delete('projectprop', array('project_id' => $project_id));
-  $properties = tripal_core_properties_form_retreive($node, 'project_property');
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_project_insert_property($project_id, $property, $value, FALSE, 'project_property');
-      if (!$status) {
-        drupal_set_message("Error cannot add property: '$property'", "error");
-        watchdog('t_project', "Error cannot add property: '%prop'",
-        array('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
-  
+  $details = array(
+    'property_table' => 'projectprop',
+    'base_table' => 'project',
+    'foreignkey_name' => 'project_id',
+    'foreignkey_value' => $project_id
+  );
+  chado_node_properties_form_update_properties($node, $details);
+
   // add the project description as a property
   tripal_project_update_property($project_id, 'Project Description', $node->description, 1);
 }
@@ -370,10 +344,10 @@ function chado_project_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // get the feature details from chado
     $project_id = chado_get_id_for_node('project', $node->nid);
-  
+
     $values = array('project_id' => $project_id);
     $project = tripal_core_generate_chado_var('project', $values);
-  
+
     $nodes[$nid]->project = $project;
   }
 

+ 59 - 59
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -40,13 +40,13 @@ function tripal_pub_node_info() {
 
 function chado_pub_form($node, $form_state) {
   $form = array();
-  
+
   // Default values can come in the following ways:
   //
   // 1) as elements of the $node object.  This occurs when editing an existing pub
-  // 2) in the $form_state['values'] array which occurs on a failed validation or 
+  // 2) in the $form_state['values'] array which occurs on a failed validation or
   //    ajax callbacks from non submit form elements
-  // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit 
+  // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit
   //    form elements and the form is being rebuilt
   //
   // set form field defaults
@@ -56,8 +56,8 @@ function chado_pub_form($node, $form_state) {
   $uniquename  = '';
   $type_id     = '';
   $is_obsolete = '';
-  
-  // some of the fields in the pub table should show up in the properties 
+
+  // some of the fields in the pub table should show up in the properties
   // form elements to make the form more seemless.  We will add them
   // to this array.
   $more_props = array();
@@ -69,24 +69,24 @@ function chado_pub_form($node, $form_state) {
     $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
     $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');
     $pub_id = $pub->pub_id;
-    
+
     $title       = $pub->title;
     $pyear       = $pub->pyear;
     $uniquename  = $pub->uniquename;
     $type_id     = $pub->type_id->cvterm_id;
     $is_obsolete = $pub->is_obsolete;
-    
+
     // if the obsolete value is set by the database then it is in the form of
     // 't' or 'f', we need to convert to 1 or 0
     $is_obsolete = $is_obsolete == 't' ? 1 : $is_obsolete;
     $is_obsolete = $is_obsolete == 'f' ? 0 : $is_obsolete;
-    
+
     // set the organism_id in the form
     $form['pub_id'] = array(
       '#type' => 'value',
       '#value' => $pub->pub_id,
     );
-    
+
     // get fields from the pub table and convert them to properties. We will add these to the $more_props
     // array which gets passed in to the tripal_core_properties_form() API call further down
     if ($pub->volumetitle) {
@@ -149,7 +149,7 @@ function chado_pub_form($node, $form_state) {
     $type_id      = $form_state['input']['type_id'];
     $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(
@@ -186,7 +186,7 @@ function chado_pub_form($node, $form_state) {
       $type_id = $pub_type->cvterm_id;
     }
   }
-  
+
   $form['type_id'] = array(
     '#type' => 'select',
     '#title' => t('Publication Type'),
@@ -206,12 +206,12 @@ function chado_pub_form($node, $form_state) {
     '#type' => 'textarea',
     '#title' => t('Citation'),
     '#default_value' => $uniquename,
-    '#description' => t('All publications must have a unique citation. 
-      <b>Please enter the full citation for this publication or leave blank and one will be generated 
-      automatically if possible</b>.  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 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 
+    '#description' => t('All publications must have a unique citation.
+      <b>Please enter the full citation for this publication or leave blank and one will be generated
+      automatically if possible</b>.  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 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
         suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
   );
   $form['is_obsolete'] = array(
@@ -219,8 +219,20 @@ function chado_pub_form($node, $form_state) {
     '#title' => t('Is Obsolete? (Check for Yes)'),
     '#default_value' => $is_obsolete,
   );
- 
+
+  // Properties Form
+  // ----------------------------------
+  // D7 @TODO: Properties API doesn't handle exclude
+  $exclude = array("Citation");
+  $details = array(
+    'property_table' => 'pubprop',
+    'base_foreign_key' => 'pub_id',
+    'base_key_value' => $pub_id,
+    'cv_name' => 'tripal_pub'
+  );
+  chado_node_properties_form($form, $form_state, $details);
   // get publication properties list
+  /**
   $properties_select = array();
   $properties_select[] = 'Select a Property';
   $sql = "
@@ -242,14 +254,15 @@ function chado_pub_form($node, $form_state) {
       $properties[$prop->cvterm_id] = $prop->name;
     }
   }
-  
+
   // add in the properties fields. The 'Citation' term is special because it serves
   // both as a property and as the uniquename for the publiation table so we exclude it
   // as it shouldn't be selected as a property
-  $exclude = array("Citation"); 
+  $exclude = array("Citation");
   $instructions = '';
   tripal_core_properties_form($form, $form_state, 'pubprop', 'pub_id', 'tripal_pub',
     $properties, $pub_id, $exclude, $more_props, $instructions, 'Properties');
+  */
 
   return $form;
 
@@ -264,7 +277,7 @@ function chado_pub_validate($node, $form, &$form_state) {
   $pyear        = trim($node->pyear);
   $uniquename   = trim($node->uniquename);
   $is_obsolete  = $node->is_obsolete;
-  $type_id      = $node->type_id;  
+  $type_id      = $node->type_id;
 
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
@@ -276,9 +289,9 @@ function chado_pub_validate($node, $form, &$form_state) {
   if (is_null($node->nid) and property_exists($node, 'pub_id') and $node->pub_id != 0) {
     return;
   }
-  
+
   $pub = array();
-  
+
   // make sure the year is four digits
   if(!preg_match('/^\d{4}$/', $pyear)){
     form_set_error('pyear', t('The publication year should be a 4 digit year.'));
@@ -293,7 +306,7 @@ function chado_pub_validate($node, $form, &$form_state) {
     $message = t('Invalid publication type.');
     form_set_error('type_id', $message);
     return;
-  }  
+  }
 
   // get the media name looking at the properties
   $series_name = '';
@@ -312,7 +325,7 @@ function chado_pub_validate($node, $form, &$form_state) {
       $pub[$prop_type->name] = $value;
     }
     // if this is a new property (added by this submit of the form)
-    elseif ($element == 'new_id') {       
+    elseif ($element == 'new_id') {
       $prop_type = tripal_cv_get_cvterm_by_id($value);
       if($prop_type->name == 'Conference Name' or $prop_type->name == 'Journal Name') {
         $series_name = $node->new_value;
@@ -343,10 +356,10 @@ function chado_pub_validate($node, $form, &$form_state) {
   }
 
   // Validating for an update
-  if (!is_null($node->nid)) { 
-    
+  if (!is_null($node->nid)) {
+
     $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');
@@ -364,7 +377,7 @@ function chado_pub_validate($node, $form, &$form_state) {
 
     // check to see if a duplicate publication already exists
     if (!$skip_duplicate_check) {
-      chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id); 
+      chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id);
     }
     chado_pub_validate_check_uniquename($uniquename, $pub_id);
   }
@@ -375,11 +388,11 @@ function chado_pub_validate($node, $form, &$form_state) {
   }
 }
 /**
- * 
+ *
  * @param unknown $uniquename
  */
 function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
-  
+
   $results = tripal_pub_get_pub_by_uniquename($uniquename);
   // make sure we don't capture our pub_id in the list (remove it)
   foreach ($results as $index => $found_pub_id) {
@@ -393,10 +406,10 @@ function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
   }
 }
 /**
- * 
+ *
  */
 function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
-  
+
   // 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');
   switch ($import_dups_check) {
@@ -415,7 +428,7 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
       break;
     case 'title_year_type':
       $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, $cvterm[0]->name, $pyear, NULL);
-  
+
       // make sure we don't capture our pub_id in the list (remove it)
       foreach ($results as $index => $found_pub_id) {
         if($found_pub_id == $pub_id){
@@ -429,7 +442,7 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
       break;
     case 'title_year_media':
       $results = tripal_pub_get_pubs_by_title_type_pyear_series($title, NULL, $pyear, $series_name);
-  
+
       // make sure we don't capture our pub_id in the list (remove it)
       foreach ($results as $index => $found_pub_id) {
         if($found_pub_id == $pub_id){
@@ -529,7 +542,7 @@ function chado_pub_insert($node) {
     $cross_refs = array(); // stores any cross references for this publication
 
     // get the properties from the form
-    $properties = tripal_core_properties_form_retreive($node, 'tripal_pub');
+    $properties = chado_node_properties_form_retreive($node);
 
     // get the list of properties for easy lookup (without doing lots of database queries
     $properties_list = array();
@@ -642,17 +655,8 @@ function chado_pub_insert($node) {
     $pub_id = $pub['pub_id'];
 
     // 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);
-        }
-      }
-    }
+    // Only adds in those not used in the pub record
+    chado_node_properties_form_update_properties($node, $details, $properties);
 
     // add in any database cross-references
     foreach ($cross_refs as $index => $ref) {
@@ -712,7 +716,7 @@ function chado_pub_update($node) {
   $cross_refs = array(); // stores any cross references for this publication
 
   // get the properties from the form
-  $properties = tripal_core_properties_form_retreive($node, 'tripal_pub');
+  $properties = chado_node_properties_form_retreive($node);
 
   // get the list of properties for easy lookup (without doing lots of database queries
   $properties_list = array();
@@ -829,17 +833,13 @@ function chado_pub_update($node) {
 
   // now add in the properties by first removing any the publication
   // already has and adding the ones we have
-  tripal_core_chado_delete('pubprop', array('pub_id' => $pub_id));
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_pub_insert_property($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('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
+  $details = array(
+    'property_table' => 'pubprop',
+    'base_table' => 'pub',
+    'foreignkey_name' => 'pub_id',
+    'foreignkey_value' => $pub_id
+  );
+  chado_node_properties_form_update_properties($node, $details, $$properties);
 
   // add in any database cross-references after first removing
   tripal_core_chado_delete('pub_dbxref', array('pub_id' => $pub_id));

+ 3 - 3
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -298,7 +298,7 @@ function chado_stock_form($node, $form_state) {
     'base_key_value' => $stock_id,
     'cv_id' => variable_get('chado_stock_prop_types_cv', FALSE)
   );
-  tripal_api_chado_node_properties_form($form, $form_state, $details);
+  chado_node_properties_form($form, $form_state, $details);
 
   // ADDITIONAL DBXREFS FORM
   //---------------------------------------------
@@ -550,7 +550,7 @@ function chado_stock_insert($node) {
         'foreignkey_name' => 'stock_id',
         'foreignkey_value' => $stock_id
       );
-      tripal_api_chado_node_properties_form_update_properties($node, $details);
+      chado_node_properties_form_update_properties($node, $details);
 
     }
 
@@ -725,7 +725,7 @@ function chado_stock_update($node) {
       'foreignkey_name' => 'stock_id',
       'foreignkey_value' => $node->stock_id
     );
-    tripal_api_chado_node_properties_form_update_properties($node, $details);
+    chado_node_properties_form_update_properties($node, $details);
 
   }