Bladeren bron

Removed interface for properties, relationships, etc. for features. and fixed bug in inserting analysis properties

spficklin 11 jaren geleden
bovenliggende
commit
a94ec98cc0

+ 16 - 8
tripal_analysis/api/tripal_analysis.api.inc

@@ -44,14 +44,16 @@ function tripal_analysis_unregister_child($modulename) {
  *    The analysis_id of the properties you would like to retrieve
  * @param $property
  *    The cvterm name of the properties to retrieve
+ * @param $cvname
+ *   The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  *
  * @return
  *    An analysis chado variable with the specified properties expanded
  *
  * @ingroup tripal_analysis_api
  */
-function tripal_analysis_get_property($analysis_id, $property) {
-  return tripal_core_get_property('analysis', $analysis_id, $property, 'tripal');
+function tripal_analysis_get_property($analysis_id, $property, $cvname = 'tripal') {
+  return tripal_core_get_property('analysis', $analysis_id, $property, $cvname);
 }
 
 /**
@@ -65,14 +67,16 @@ function tripal_analysis_get_property($analysis_id, $property) {
  *   The value of the property to insert
  * @param $update_if_present
  *   A boolean indicated whether to update the record if it's already present
+ * @param $cvname
+ *   The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  *
  * @return
  *   True of success, False otherwise
  *
  * @ingroup tripal_analysis_api
  */
-function tripal_analysis_insert_property($analysis_id, $property, $value, $update_if_present = 0) {
-    return tripal_core_insert_property('analysis', $analysis_id, $property, 'analysis_property', $value, $update_if_present);
+function tripal_analysis_insert_property($analysis_id, $property, $value, $update_if_present = 0, $cvname = 'tripal') {
+    return tripal_core_insert_property('analysis', $analysis_id, $property, $cvname, $value, $update_if_present);
 }
 
 /**
@@ -86,6 +90,8 @@ function tripal_analysis_insert_property($analysis_id, $property, $value, $updat
  *   The value of the property to update
  * @param $insert_if_missing
  *   A boolean indicated whether to insert the record if it's absent
+ * @param $cvname
+ *   The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  *
  * Note: The property will be identified using the unique combination of the $analysis_id and $property
  * and then it will be updated with the supplied value
@@ -95,8 +101,8 @@ function tripal_analysis_insert_property($analysis_id, $property, $value, $updat
  *
  * @ingroup tripal_analysis_api
  */
-function tripal_analysis_update_property($analysis_id, $property, $value, $insert_if_missing = 0) {
-  return tripal_core_update_property('analysis', $analysis_id, $property, 'tripal', $value, $insert_if_missing);
+function tripal_analysis_update_property($analysis_id, $property, $value, $insert_if_missing = 0, $cvname = 'tripal') {
+  return tripal_core_update_property('analysis', $analysis_id, $property, $cvname, $value, $insert_if_missing);
 }
 
 /**
@@ -106,6 +112,8 @@ function tripal_analysis_update_property($analysis_id, $property, $value, $inser
  *   The analysis_id of the property to delete
  * @param $property
  *   The cvterm name of the property to delete
+ * @param $cvname
+ *   The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  *
  * Note: The property will be identified using the unique combination of the $analysis_id and $property
  * and then it will be deleted
@@ -115,8 +123,8 @@ function tripal_analysis_update_property($analysis_id, $property, $value, $inser
  *
  * @ingroup tripal_analysis_api
  */
-function tripal_analysis_delete_property($analysis_id, $property) {
-  return tripal_core_delete_property('analysis', $analysis_id, $property, 'tripal');
+function tripal_analysis_delete_property($analysis_id, $property, $cvname = 'tripal') {
+  return tripal_core_delete_property('analysis', $analysis_id, $property, $cvname);
 }
 
 /**

+ 47 - 31
tripal_analysis/includes/tripal_analysis.form.inc

@@ -5,7 +5,7 @@
  *
  * @ingroup tripal_analysis
  */
-function chado_analysis_form(&$node, $form_state) {
+function chado_analysis_form(&$node, $form_state = NULL) {
   tripal_core_ahah_init_form();
   $form = array();
 
@@ -181,6 +181,25 @@ function chado_analysis_form(&$node, $form_state) {
   	$properties_select[$prop->cvterm_id] = $prop->name;
   	$properties_list[$prop->cvterm_id] = $prop;
   }
+  
+  $form['properties'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Analysis Details'),
+    '#description' => t('You may add additional 
+      properties by
+      selecting a property type from the dropdown and adding text.  You may add 
+      as many properties as desired by clicking the plus button on the right.  To 
+      remove a property, click the minus button.  If a property is not available
+      you may add it by ' . l('adding the term', 'admin/tripal/tripal_cv/cvterm/add') . '
+      to the <b>analysis_property</b> vocabulary'),
+  );
+  $form['properties']['table'] = array(
+    '#type' => 'markup',
+    '#value' =>  '',
+    '#prefix' => '<div id="tripal-analysis-edit-properties-table">',
+    '#suffix' => '</div>',
+  );
+  
   // add in the properties from the analysisprop table
   $num_properties += chado_analysis_node_form_add_analysisprop_table_props($form, $form_state, $analysis_id, $d_properties, $d_removed);
   
@@ -300,7 +319,7 @@ function tripal_analysis_validate($node, &$form) {
 function chado_analysis_node_form_add_new_empty_props(&$form, $properties_select) {
 
   // add one more blank set of property fields
-  $form['properties']['new']["new_id"] = array(
+  $form['properties']['table']['new']["new_id"] = array(
     '#type'          => 'select',
     '#options'       => $properties_select,
     '#ahah' => array(
@@ -310,14 +329,14 @@ function chado_analysis_node_form_add_new_empty_props(&$form, $properties_select
       'method'  => 'replace',          
   ),
   );
-  $form['properties']['new']["new_value"] = array(
+  $form['properties']['table']['new']["new_value"] = array(
     '#type'          => 'textarea',
     '#default_value' => '',
     '#cols'          => 5,
     '#rows'          => $rows,
     '#description'   => '<div id="tripal-analysis-new_value-desc"></div>'
     );
-    $form['properties']['new']["add"] = array(
+    $form['properties']['table']['new']["add"] = array(
     '#type'         => 'image_button',      
     '#value'        => t('Add'),
     '#src'          => drupal_get_path('theme', 'tripal') . '/images/add.png',
@@ -371,11 +390,11 @@ function chado_analysis_node_form_add_new_props(&$form, $form_state, &$d_propert
 
 
         // add the new fields
-        $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
+        $form['properties']['table']['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(
+        $form['properties']['table']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
           '#type'          => 'textarea',
           '#default_value' => $value,
           '#cols'          => 50,
@@ -383,7 +402,7 @@ function chado_analysis_node_form_add_new_props(&$form, $form_state, &$d_propert
           '#description'   => $cvterm->definition,
         );
 
-        $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
+        $form['properties']['table']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
           '#type'         => 'image_button',
           '#value'        => t('Remove'),
           '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
@@ -422,11 +441,11 @@ function chado_analysis_node_form_add_new_props(&$form, $form_state, &$d_propert
     $rows = 1;
 
     // add the new fields
-    $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
+    $form['properties']['table']['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(
+    $form['properties']['table']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
       '#type'          => 'textarea',
       '#default_value' => $new_value,
       '#cols'          => 50,
@@ -434,7 +453,7 @@ function chado_analysis_node_form_add_new_props(&$form, $form_state, &$d_propert
       '#description'   => $cvterm->definition,
     );
 
-    $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
+    $form['properties']['table']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
       '#type'         => 'image_button',
       '#value'        => t('Remove'),
       '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
@@ -467,7 +486,8 @@ function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_sta
     SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
     FROM {analysisprop} PP
       INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
-    WHERE PP.analysis_id = %d
+      INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+    WHERE PP.analysis_id = %d and CV.name = 'analysis_property'
     ORDER BY CVT.name, PP.rank
   ";
   $analysis_props = chado_query($sql, $analysis_id);
@@ -492,11 +512,11 @@ function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_sta
     $d_properties[$type_id][$rank]['definition']  = $prop->definition;
     $num_properties++;
 
-    $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
+    $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
       '#type'          => 'item',
       '#value'         => $prop->name,
     );
-    $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
+    $form['properties']['table'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
       '#type'          => 'textarea',
       '#default_value' => $prop->value,
       '#cols'          => 50,
@@ -504,7 +524,7 @@ function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_sta
       '#description'   => $prop->definition,
     );
 
-    $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
+    $form['properties']['table'][$type_id][$rank]["remove-$type_id-$rank"] = array(
       '#type'         => 'image_button',
       '#value'        => t('Remove'),
       '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
@@ -529,8 +549,8 @@ function tripal_analysis_theme_node_form_properties($form) {
 
     // first add in the properties derived from the analysisprop table
     // the array tree for these properties looks like this:
-    // $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"]
-    foreach ($form['properties'] as $type_id => $elements) {
+    // $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"]
+    foreach ($form['properties']['table'] as $type_id => $elements) {
       // there are other fields in the properties array so we only
       // want the numeric ones those are our type_id
       if (is_numeric($type_id)) {
@@ -548,8 +568,8 @@ function tripal_analysis_theme_node_form_properties($form) {
 
     // second, add in any new properties added by the user through AHAH callbacks
     // the array tree for these properties looks like this:
-    // $form['properties']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
-    foreach ($form['properties']['new'] as $type_id => $elements) {
+    // $form['properties']['table']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
+    foreach ($form['properties']['table']['new'] as $type_id => $elements) {
       if (is_numeric($type_id)) {
         foreach ($elements as $rank => $element) {
           if (is_numeric($rank)) {
@@ -565,14 +585,14 @@ function tripal_analysis_theme_node_form_properties($form) {
 
     // finally add in a set of blank field for adding a new property
     $rows[] = array(
-    drupal_render($form['properties']['new']['new_id']),
-    drupal_render($form['properties']['new']['new_value']),
-    drupal_render($form['properties']['new']['add']),
+    drupal_render($form['properties']['table']['new']['new_id']),
+    drupal_render($form['properties']['table']['new']['new_value']),
+    drupal_render($form['properties']['table']['new']['add']),
     );
   }
 
   $headers = array('Property Type','Value', '');
-  return theme('table', $headers, $rows, array('id'=> "tripal-analysis-edit-properties-table"));
+  return theme('table', $headers, $rows);
 }
 
 /*
@@ -593,11 +613,11 @@ function tripal_analysis_property_add() {
 
   // return the updated JSON
   drupal_json(
-  array(
+    array(
       'status'   => $status, 
       'data'     => $data,
       'settings' => $settings,
-  )
+    )
   );
 }
 /*
@@ -651,17 +671,13 @@ function tripal_analysis_property_get_description() {
 function theme_chado_analysis_node_form($form) {
 
   $properties_table = tripal_analysis_theme_node_form_properties($form);
-
-  $markup  = drupal_render($form['analysis_id']);
-  $markup .= drupal_render($form['title']);
-  $markup .= drupal_render($form['type_id']);
-  $markup .= drupal_render($form['description']);
-  $markup .= "<b>Include Additional Details</b><br>You may add additional properties to this analysis by scrolling to the bottom of this table, selecting a property type from the dropdown and adding text.  You may add as many properties as desired by clicking the plus button on the right.  To remove a property, click the minus button";
   $markup .= $properties_table;
 
-  $form['properties'] = array(
+  $form['properties']['table'] = array(
     '#type' => 'markup',
     '#value' =>  $markup,
+    '#prefix' => '<div id="tripal-analysis-edit-properties-table">',
+    '#suffix' => '</div>',
   );
   $form['buttons']['#weight'] = 50;
   return drupal_render($form);

+ 163 - 161
tripal_analysis/tripal_analysis.module

@@ -139,28 +139,28 @@ function chado_analysis_insert($node) {
   
   // If the analysis doesn't exist then let's create it in chado.
   if (!$analysis) {
-      // insert and then get the newly inserted analysis record
-      $values = array(
-          'name' => $node->analysisname,
-          'description' => $node->description,
-          'program' => $node->program,
-          'programversion' => $node->programversion,
-          'algorithm' => $node->algorithm,
-          'sourcename' => $node->sourcename,
-          'sourceversion' => $node->sourceversion,
-          'sourceuri' => $node->sourceuri,
-          'timeexecuted' => $timestamp
-      );
-      if (tripal_core_chado_insert('analysis', $values)) {
-        $analysis = tripal_core_chado_select('analysis', array('*'), $values);
-        $analysis_id = $analysis[0]->analysis_id;
-      }
+    // insert and then get the newly inserted analysis record
+    $values = array(
+      'name' => $node->analysisname,
+      'description' => $node->description,
+      'program' => $node->program,
+      'programversion' => $node->programversion,
+      'algorithm' => $node->algorithm,
+      'sourcename' => $node->sourcename,
+      'sourceversion' => $node->sourceversion,
+      'sourceuri' => $node->sourceuri,
+      'timeexecuted' => $timestamp
+    );
+    if (tripal_core_chado_insert('analysis', $values)) {
+      $analysis = tripal_core_chado_select('analysis', array('*'), $values);
+      $analysis_id = $analysis[0]->analysis_id;
+    }
   }
 
   // Make sure the entry for this analysis doesn't already exist in the
   // chado_analysis table if it doesn't exist then we want to add it.
   $node_check_sql = "SELECT * FROM {chado_analysis} ".
-                     "WHERE analysis_id = %d";
+                    "WHERE analysis_id = %d";
   $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
   if (!$node_check) {
     // next add the item to the drupal table
@@ -184,16 +184,16 @@ function chado_analysis_insert($node) {
     drupal_write_record('node_revisions', $record, 'nid');
   }
 
-   // add the analysis to the node object for
-   // use by other analysis modules that may be using this function
-    $node->analysis = $analysis;
-    $node->analysis_id = $analysis_id; // we need to set this for children
+  // add the analysis to the node object for
+  // use by other analysis modules that may be using this function
+  $node->analysis = $analysis;
+  $node->analysis_id = $analysis_id; // we need to set this for children
     
-    // now add the properties
-    $properties = array(); // stores all of the properties we need to add    
-    // get the list of properties for easy lookup (without doing lots of database queries
-    $properties_list = array();
-    $sql = "
+  // now add the properties
+  $properties = array(); // stores all of the properties we need to add    
+  // get the list of properties for easy lookup (without doing lots of database queries
+  $properties_list = array();
+  $sql = "
       SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
       FROM  {cvterm} CVT
         INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
@@ -201,40 +201,40 @@ function chado_analysis_insert($node) {
         CV.name = 'analysis_property' AND
         NOT CVT.is_obsolete = 1
       ORDER BY CVT.name ASC
-    ";
-    $prop_types = chado_query($sql);
-    while ($prop = db_fetch_object($prop_types)) {
-    	$properties_list[$prop->cvterm_id] = $prop->name;
-    }
+  ";
+  $prop_types = chado_query($sql);
+  while ($prop = db_fetch_object($prop_types)) {
+    $properties_list[$prop->cvterm_id] = $prop->name;
+  }
     
-    // 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] = trim($value);
-    	}
-    }
+  // 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] = trim($value);
+      }
+  }
     if ($node->new_id and $node->new_value) {
-    	$type_id = $node->new_id;
-    	$name = $properties_list[$type_id];
-    	$index = count($properties[$name]);
-    	$properties[$name][$index] = trim($node->new_value);
+      $type_id = $node->new_id;
+      $name = $properties_list[$type_id];
+      $index = count($properties[$name]);
+      $properties[$name][$index] = trim($node->new_value);
     }
     // now add in the properties
     foreach ($properties as $property => $elements) {
       foreach ($elements as $rank => $value) {
-    	  $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE);
+        $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);
-    		}
+        }
       }
     }
 }
@@ -283,113 +283,113 @@ function chado_analysis_delete($node) {
  * @ingroup tripal_analysis
  */
 function chado_analysis_update($node) {
-	global $user;
-	if ($node->revision) {
-		// TODO -- decide what to do about revisions
-	}
-	// Create a timestamp so we can insert it into the chado database
-	$time = $node->timeexecuted;
-	$month = $time['month'];
-	$day = $time['day'];
-	$year = $time['year'];
-	$timestamp = $month . '/' . $day . '/' . $year;
-
-	// get the analysis_id for this node:
-	$sql = "SELECT analysis_id ".
-			"FROM {chado_analysis} ".
-			"WHERE nid = %d";
-	$analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;
-
-	$sql = "UPDATE {analysis} ".
-			"SET name = '%s', ".
-			"    description = '%s', ".
-			"    program = '%s', ".
-			"    programversion = '%s', ".
-			"    algorithm = '%s', ".
-			"    sourcename = '%s', ".
-			"    sourceversion = '%s', ".
-			"    sourceuri = '%s', ".
-			"    timeexecuted = '%s' ".
-			"WHERE analysis_id = %d ";
-
-	chado_query($sql, $node->analysisname, $node->description, $node->program,
-	$node->programversion, $node->algorithm, $node->sourcename,
-	$node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-
-	// Create a title for the analysis node using the unique keys so when the
-	// node is saved, it will have a title
-	$record = new stdClass();
-	// If the analysis has a name, use it as the node title. If not, construct
-	// the title using program, programversion, and sourcename
-	if ($node->analysisname) {
-		$record->title = $node->analysisname;
-	}
-	else {
-		//Construct node title as "program (version)
-		$record->title = "$node->program ($node->programversion)";
-	}
-
-	$record->nid = $node->nid;
-	drupal_write_record('node', $record, 'nid');
-	drupal_write_record('node_revisions', $record, 'nid');
-
-	// now update the properties
-	$properties = array(); // stores all of the properties we need to add
-	// get the list of properties for easy lookup (without doing lots of database queries
-	$properties_list = array();
-	$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 = db_fetch_object($prop_types)) {
-		$properties_list[$prop->cvterm_id] = $prop->name;
-	}
-
-	// get the properties that should be added. Properties are in one of three forms:
-	//  1) prop_value-[type id]-[index]
-	//  2) new_value-[type id]-[index]
-	//  3) new_id, new_value
-	//  dpm($node);
-	foreach ($node as $key => $value) {
-		if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
-			$type_id = $matches[1];
-			$index = $matches[2];
-			$name = $properties_list[$type_id];
-			$properties[$name][$index] = trim($value);
-		}
-		if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
-			$type_id = $matches[1];
-			$index = $matches[2];
-			$name = $properties_list[$type_id];
-			$properties[$name][$index] = trim($value);
-		}
-	}
-	if ($node->new_id and $node->new_value) {
-		$type_id = $node->new_id;
-		$name = $properties_list[$type_id];
-		$index = count($properties[$name]);
-		$properties[$name][$index] = trim($node->new_value);
-	}
-
-	// 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));
-	foreach ($properties as $property => $elements) {
-		foreach ($elements as $rank => $value) {
-			$status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE);
-			if (!$status) {
-				drupal_set_message("Error cannot add property: '$property'", "error");
-				watchdog('t_analysis', "Error cannot add property: '%prop'",
-				array('%prop' => $property), WATCHDOG_ERROR);
-			}
-		}
-	}
+  global $user;
+  if ($node->revision) {
+    // TODO -- decide what to do about revisions
+  }
+  // Create a timestamp so we can insert it into the chado database
+  $time = $node->timeexecuted;
+  $month = $time['month'];
+  $day = $time['day'];
+  $year = $time['year'];
+  $timestamp = $month . '/' . $day . '/' . $year;
+
+  // get the analysis_id for this node:
+  $sql = "SELECT analysis_id ".
+      "FROM {chado_analysis} ".
+      "WHERE nid = %d";
+  $analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;
+
+  $sql = "UPDATE {analysis} ".
+      "SET name = '%s', ".
+      "    description = '%s', ".
+      "    program = '%s', ".
+      "    programversion = '%s', ".
+      "    algorithm = '%s', ".
+      "    sourcename = '%s', ".
+      "    sourceversion = '%s', ".
+      "    sourceuri = '%s', ".
+      "    timeexecuted = '%s' ".
+      "WHERE analysis_id = %d ";
+
+  chado_query($sql, $node->analysisname, $node->description, $node->program,
+  $node->programversion, $node->algorithm, $node->sourcename,
+  $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
+
+  // Create a title for the analysis node using the unique keys so when the
+  // node is saved, it will have a title
+  $record = new stdClass();
+  // If the analysis has a name, use it as the node title. If not, construct
+  // the title using program, programversion, and sourcename
+  if ($node->analysisname) {
+    $record->title = $node->analysisname;
+  }
+  else {
+    //Construct node title as "program (version)
+    $record->title = "$node->program ($node->programversion)";
+  }
+
+  $record->nid = $node->nid;
+  drupal_write_record('node', $record, 'nid');
+  drupal_write_record('node_revisions', $record, 'nid');
+
+  // now update the properties
+  $properties = array(); // stores all of the properties we need to add
+  // get the list of properties for easy lookup (without doing lots of database queries
+  $properties_list = array();
+  $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 = db_fetch_object($prop_types)) {
+    $properties_list[$prop->cvterm_id] = $prop->name;
+  }
+
+  // get the properties that should be added. Properties are in one of three forms:
+  //  1) prop_value-[type id]-[index]
+  //  2) new_value-[type id]-[index]
+  //  3) new_id, new_value
+  //  dpm($node);
+  foreach ($node as $key => $value) {
+    if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
+      $type_id = $matches[1];
+      $index = $matches[2];
+      $name = $properties_list[$type_id];
+      $properties[$name][$index] = trim($value);
+    }
+    if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
+      $type_id = $matches[1];
+      $index = $matches[2];
+      $name = $properties_list[$type_id];
+      $properties[$name][$index] = trim($value);
+    }
+  }
+  if ($node->new_id and $node->new_value) {
+    $type_id = $node->new_id;
+    $name = $properties_list[$type_id];
+    $index = count($properties[$name]);
+    $properties[$name][$index] = trim($node->new_value);
+  }
+
+  // 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));
+  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);
+      }
+    }
+  }
 }
 
  /**
@@ -516,7 +516,7 @@ function tripal_analysis_perm() {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_theme() {
-  return array(
+  $items = array(
     'tripal_analysis_base' => array(
        'arguments' => array('node' => NULL),
        'template' => 'tripal_analysis_base',
@@ -530,14 +530,16 @@ function tripal_analysis_theme() {
       'arguments' =>  array(NULL),  
       'path' => drupal_get_path('module', 'tripal_analysis') . '/theme', 
     ),
-  	 'tripal_analysis_properties' => array(
-  				'arguments' => array('node' => NULL)
-  	 ),
+     'tripal_analysis_properties' => array(
+     'arguments' => array('node' => NULL)
+    ),
     // Themed Forms
     'chado_analysis_node_form' => array(
       'arguments' => array('form'),
     ),
   );
+  
+  return $items;
 }
 /**
  *

+ 1 - 1
tripal_cv/includes/trees.inc

@@ -42,7 +42,7 @@ function tripal_cv_show_browser() {
  * to the function.  For example, the Tripal GO Analysis module generates
  * tree ids of the form:
  *
- *  tripal_analysis_go_cv_tree_10_2_bp
+ *  tripal_analysis_go_cv_tree_10-2_bp
  *
  * In this case the module that will manage this tree is identified as 'tripal_analysis_go' and within
  * the [unique id] portion contains the

+ 4 - 84
tripal_feature/tripal_feature.module

@@ -23,10 +23,10 @@ require_once "includes/seq_extract.inc";
 require_once "api/tripal_feature.api.inc";
 
 require_once "includes/tripal_feature-delete.inc";
-require_once "includes/tripal_feature-secondary_tables.inc";
-require_once "includes/tripal_feature-properties.inc";
-require_once "includes/tripal_feature-relationships.inc";
-require_once "includes/tripal_feature-db_references.inc";
+//require_once "includes/tripal_feature-secondary_tables.inc";
+//require_once "includes/tripal_feature-properties.inc";
+//require_once "includes/tripal_feature-relationships.inc";
+//require_once "includes/tripal_feature-db_references.inc";
 
 
 /**
@@ -223,68 +223,6 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  // Adding Secondary Properties
-
-  /**
-  $items['node/%tf_node/tf_properties'] = array(
-    'title' => t('Add Properties & Synonyms'),
-    'description' => t('Settings for Features'),
-    'page callback' => 'tripal_feature_add_ALL_property_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_feature content'),
-    'type' => MENU_CALLBACK
-  );
-
-  $items['node/%tf_node/tf_db_references'] = array(
-    'title' => t('Add Database References'),
-    'description' => t('Settings for Features'),
-    'page callback' => 'tripal_feature_add_ALL_dbreferences_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_feature content'),
-    'type' => MENU_CALLBACK
-  );
-
-  $items['node/%tf_node/tf_relationships'] = array(
-    'title' => t('Add Relationships'),
-    'description' => t('Settings for Features'),
-    'page callback' => 'tripal_feature_add_ALL_relationships_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_feature content'),
-    'type' => MENU_CALLBACK
-  );
-  */
-
-  //Edit/Deleting Secondary Properties-------------
-  $items['node/%tf_node/edit_feature_properties'] = array(
-    'title' => 'Edit Properties',
-    'description' => 'Settings for Features',
-    'page callback' => 'tripal_feature_edit_ALL_properties_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_feature content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 8,
-  );
-  /**
-  $items['node/%tf_node/tf_edit_relationships'] = array(
-    'title' => t('Edit Relationships'),
-    'description' => t('Settings for Feature'),
-    'page callback' => 'tripal_feature_edit_ALL_relationships_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_feature content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 9,
-  );
-  */
-  $items['node/%tf_node/tf_edit_db_references'] = array(
-    'title' => 'Edit References',
-    'description' => 'Settings for Feature',
-    'page callback' => 'tripal_feature_edit_ALL_dbreferences_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_feature content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 10,
-  );
-
   // the menu link for addressing any feature (by name, uniquename, synonym)
   $items['feature/%'] = array(
     'title' => 'Matched Features',
@@ -297,24 +235,6 @@ function tripal_feature_menu() {
 
   return $items;
 }
-
-/**
- * Implements Menu wildcard_load hook
- * Purpose: Allows the node ID of a chado feature to be dynamically
- *   pulled from the path. The node is loaded from this node ID
- *   and supplied to the page as an arguement
- *
- * @ingroup tripal_feature
- */
-function tf_node_load($nid) {
-  if (is_numeric($nid)) {
-    $node = node_load($nid);
-    if ($node->type == 'chado_feature') {
-      return $node;
-    }
-  }
-  return FALSE;
-}
 /**
  *  We need to let drupal know about our theme functions and their arguments.
  *  We create theme functions to allow users of the module to customize the