Переглянути джерело

Tripal Feature adheres to Drupal coding standards

Pubudu Basnayaka 13 роки тому
батько
коміт
867e323815

+ 66 - 63
tripal_feature/tripal_feature-db_references.inc

@@ -1,14 +1,14 @@
 <?php
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
 function tripal_feature_add_ALL_dbreferences_page($node) {
   $output = '';
 
-  $output .= tripal_feature_implement_add_chado_properties_progress('db_references').'<br>';
+  $output .= tripal_feature_implement_add_chado_properties_progress('db_references') . '<br>';
   $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br>';
   $output .= '<br><b>Current Database References</b><br>';
   $output .= list_dbreferences_for_node($node->db_references);
@@ -87,23 +87,23 @@ function tripal_feature_add_ONE_dbreference_form_validate($form, &$form_state) {
 
    // Check database is valid db_id in chado
    $previous_db = tripal_db_set_active('chado');
-   $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM db WHERE db_id=%d",$db_id));
-   tripal_db_set_active($previous_db);    	
+   $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $db_id));
+   tripal_db_set_active($previous_db);
    if ($tmp_obj->count != 1) {
-      form_set_error('database', 'The database you selected is not valid. Please choose another one.'); 
+      form_set_error('database', 'The database you selected is not valid. Please choose another one.');
    }
 
    // Check Accession is unique for database
    $previous_db = tripal_db_set_active('chado');
-   $sql = "SELECT count(*) as count FROM dbxref WHERE accession='%s' and db_id = %d";
-   $tmp_obj = db_fetch_object(db_query($sql,$accession,$db_id));
+   $sql = "SELECT count(*) as count FROM {dbxref} WHERE accession='%s' and db_id = %d";
+   $tmp_obj = db_fetch_object(db_query($sql, $accession, $db_id));
    tripal_db_set_active($previous_db);
 
    if ($tmp_obj->count > 0) {
-      form_set_error('accession', 'This accession has already been assigned to another feature in the selected database.'); 
+      form_set_error('accession', 'This accession has already been assigned to another feature in the selected database.');
    }
 
-} 
+}
 
 /**
  *
@@ -120,23 +120,24 @@ function tripal_feature_add_ONE_dbreference_form_submit($form, &$form_state) {
 
    // create dbxref
    $previous_db = tripal_db_set_active('chado');
-   $isql =  "INSERT INTO dbxref (db_id, accession, description) VALUES (%d, '%s', '%s')";
-   db_query($isql,$db_id,$accession,$description);
+   $isql =  "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')";
+   db_query($isql, $db_id, $accession, $description);
    tripal_db_set_active($previous_db);
 
    //create feature_dbxref
-   $dbxref = tripal_db_get_dbxref( array('db_id'=>array('type'=>'INT','value'=>$form_state['values']['db_id']), 
- 											'accession'=>array('type'=>'STRING','exact'=>TRUE,'value'=>$form_state['values']['accession']) ) );
-
-	if (!empty($dbxref->dbxref_id)) {
-		$previous_db = tripal_db_set_active('chado');
-      $isql = "INSERT INTO feature_dbxref (feature_id, dbxref_id) VALUES (%d, %d)";
- 	   db_query($isql,$feature_id,$dbxref->dbxref_id);
-		tripal_db_set_active($previous_db);
-    	drupal_set_message('Successfully Added Database Reference');
-      drupal_goto('node/'.$nid);
-   } else {
- 	   drupal_set_message('Database reference NOT successfully created...','error');
+   $dbxref = tripal_db_get_dbxref( array('db_id' => array('type' => 'INT', 'value' => $form_state['values']['db_id']),
+                       'accession' => array('type' => 'STRING', 'exact' => TRUE, 'value' => $form_state['values']['accession']) ) );
+
+  if (!empty($dbxref->dbxref_id)) {
+    $previous_db = tripal_db_set_active('chado');
+      $isql = "INSERT INTO {feature_dbxref} (feature_id, dbxref_id) VALUES (%d, %d)";
+      db_query($isql, $feature_id, $dbxref->dbxref_id);
+    tripal_db_set_active($previous_db);
+      drupal_set_message('Successfully Added Database Reference');
+      drupal_goto('node/' . $nid);
+   }
+   else {
+      drupal_set_message('Database reference NOT successfully created...', 'error');
    } //end of if dbxref was created successfully
 
 }
@@ -159,12 +160,12 @@ function tripal_feature_edit_ALL_dbreferences_page($node) {
   return $output;
 }
 
-/**                                           
- * Implements Hook_form()                      
+/**
+ * Implements Hook_form()
  * Handles adding of DB References to Features
  *
  * @ingroup tripal_feature
- */                                        
+ */
 function tripal_feature_edit_ALL_db_references_form($form_state, $node) {
   $form = array();
 
@@ -176,7 +177,7 @@ function tripal_feature_edit_ALL_db_references_form($form_state, $node) {
   $i=0;
 
   $feature = $node->feature;
-  $references = tripal_feature_load_references ($feature->feature_id);
+  $references = tripal_feature_load_references($feature->feature_id);
 
   // pre populate the database options
   $db_options = tripal_db_get_db_options();
@@ -188,7 +189,7 @@ function tripal_feature_edit_ALL_db_references_form($form_state, $node) {
        $i++;
        $form["num-$i"] = array(
          '#type' => 'fieldset',
-         '#title' => t("Database Reference")." $i"
+         '#title' => t("Database Reference") . " $i"
        );
 
        $form["num-$i"]["accession-$i"] = array(
@@ -199,11 +200,11 @@ function tripal_feature_edit_ALL_db_references_form($form_state, $node) {
          '#default_value' => $ref->accession
        );
 
-       $form["num-$i"]["db_id-$i"] = array( 
-         '#type' => 'select', 
+       $form["num-$i"]["db_id-$i"] = array(
+         '#type' => 'select',
          '#title' => t('Database'),
          '#options' => $db_options,
-         '#required' => TRUE, 
+         '#required' => TRUE,
          '#default_value' => $ref->db_id
        );
 
@@ -246,29 +247,30 @@ function tripal_feature_edit_ALL_db_references_form_submit($form, &$form_state)
   $button = $form_state['clicked_button']['#name'];
   $nid = $form_state['values']['nid'];
 
-  if (strcmp($action,'Update All References')==0) {
+  if (strcmp($action, 'Update All References')==0) {
      for ($i=1; $i<=$num_refs; $i++) {
-		 $dbxref_id = $form_state['values']["dbxref_id-$i"]; 
-		 $db_id = $form_state['values']["db_id-$i"];
-		 $accession = $form_state['values']["accession-$i"];
-       tripal_feature_update_db_reference($dbxref_id,$db_id,$accession);
+     $dbxref_id = $form_state['values']["dbxref_id-$i"];
+     $db_id = $form_state['values']["db_id-$i"];
+     $accession = $form_state['values']["accession-$i"];
+       tripal_feature_update_db_reference($dbxref_id, $db_id, $accession);
      }
      drupal_set_message("Updated all Database References");
-     drupal_goto('node/'.$nid);
-  } 
-  elseif (strcmp($action,'Delete')==0){
-     if(preg_match('/delete-(\d+)/', $button, $matches) ) {
+     drupal_goto('node/' . $nid);
+  }
+  elseif (strcmp($action, 'Delete')==0) {
+     if (preg_match('/delete-(\d+)/', $button, $matches) ) {
         $i = $matches[1];
-	     $dbxref_id = $form_state['values']["dbxref_id-$i"]; 
+       $dbxref_id = $form_state['values']["dbxref_id-$i"];
         tripal_feature_delete_db_reference($dbxref_id);
         drupal_set_message("Deleted Database Reference");
-        drupal_goto('node/'.$nid);
-     } else {
-        drupal_set_message("Could not remove database reference: ",'error');
+        drupal_goto('node/' . $nid);
+     }
+     else {
+        drupal_set_message("Could not remove database reference: ", 'error');
      }
-  } 
+  }
   else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 
 }
@@ -281,8 +283,8 @@ function tripal_feature_edit_ALL_db_references_form_submit($form, &$form_state)
 function tripal_feature_update_db_reference($dbxref_id, $db_id, $accession) {
 
   $previous_db = tripal_db_set_active('chado');
-  $sql =  "UPDATE dbxref SET db_id=%d, accession='%s' WHERE dbxref_id=%d";
-  db_query($sql,$db_id,$accession,$dbxref_id);
+  $sql =  "UPDATE {dbxref} SET db_id=%d, accession='%s' WHERE dbxref_id=%d";
+  db_query($sql, $db_id, $accession, $dbxref_id);
   tripal_db_set_active($previous_db);
 
 }
@@ -296,12 +298,12 @@ function tripal_feature_delete_db_reference($dbxref_id) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "DELETE FROM dbxref WHERE dbxref_id=%d",
+    "DELETE FROM {dbxref} WHERE dbxref_id=%d",
     $dbxref_id
   );
 
   db_query(
-    "DELETE FROM feature_dbxref WHERE dbxref_id=%d",
+    "DELETE FROM {feature_dbxref} WHERE dbxref_id=%d",
     $dbxref_id
   );
   tripal_db_set_active($previous_db);
@@ -313,21 +315,21 @@ function tripal_feature_delete_db_reference($dbxref_id) {
  *
  * @ingroup tripal_feature
  */
-function theme_tripal_feature_edit_ALL_db_references_form ($form) {
+function theme_tripal_feature_edit_ALL_db_references_form($form) {
   $output = '';
 
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
-  	     .'is a unique identifier for this feature in the specified database.</p>';
+         .'is a unique identifier for this feature in the specified database.</p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Database</th><th>Accession</th><th></th></tr>';
 
   for ($i=1; $i<=$form['num_db_references']['#value']; $i++) {
-    $output .= '<tr><td>'.drupal_render($form["num-$i"]).'</td><td>'
-    	       .drupal_render($form["database-$i"]).'</td><td>'
-	       .drupal_render($form["accession-$i"]).'</td><td>'
-	       .drupal_render($form["submit-$i"]).'</td></tr>';
+    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
+             . drupal_render($form["database-$i"]) . '</td><td>'
+         . drupal_render($form["accession-$i"]) . '</td><td>'
+         . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
   $output .= '</table><br>';
@@ -338,7 +340,7 @@ function theme_tripal_feature_edit_ALL_db_references_form ($form) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
@@ -349,14 +351,15 @@ function list_dbreferences_for_node($db_references) {
     $output .= '<tr><th>Database</th><th>Accession</th></tr>';
 
     foreach ($db_references as $db) {
-        $output .= '<tr><td>'.$db->db_name.'</td><td>'.$db->accession.'</td></tr>';
-    } // end of foreach db reference 
+        $output .= '<tr><td>' . $db->db_name . '</td><td>' . $db->accession . '</td></tr>';
+    } // end of foreach db reference
 
-    $output .= '</table>'; 
+    $output .= '</table>';
 
-  } else {
+  }
+  else {
     $output = 'No Database References Added to the Current Feature';
-  }              
+  }
 
   return $output;
-}     
+}

+ 41 - 42
tripal_feature/tripal_feature-delete.inc

@@ -1,7 +1,7 @@
 <?php
 
 
-function tripal_feature_delete_form (){
+function tripal_feature_delete_form() {
    // get the list of organisms
    $sql = "SELECT * FROM {organism} ORDER BY genus, species";
    $previous_db = tripal_db_set_active('chado');  // use chado database
@@ -9,34 +9,34 @@ function tripal_feature_delete_form (){
    tripal_db_set_active($previous_db);  // now use drupal database
    $organisms = array();
    $organisms[''] = '';
-   while($organism = db_fetch_object($org_rset)){
+   while ($organism = db_fetch_object($org_rset)) {
       $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
    }
    $form['desc'] = array(
       '#type' => 'markup',
-      '#value' => t("Use one or more of the following fields to identify sets of features to be deleted."), 
+      '#value' => t("Use one or more of the following fields to identify sets of features to be deleted."),
    );
 
    $form['feature_names']= array(
       '#type' => 'textarea',
       '#title' => t('Feature Names'),
-      '#description' => t('Please provide a list of feature names or unique names, 
+      '#description' => t('Please provide a list of feature names or unique names,
          separated by spaces or by new lines to be delete. If you specify feature names then
          all other options below will be ignored (except the unique checkbox).'),
    );
-	$form['is_unique'] = array(
+  $form['is_unique'] = array(
       '#title' => t('Names are Unique Names'),
       '#type' => 'checkbox',
-      '#description' => t('Select this checbox if the names listed in the feature 
+      '#description' => t('Select this checbox if the names listed in the feature
         names box above are the unique name of the feature rather than the human readable names.'),
-	);
+  );
    $form['seq_type']= array(
       '#type' => 'textfield',
       '#title' => t('Sequence Type'),
       '#description' => t('Please enter the Sequence Ontology term that describes the features to be deleted. Use in conjunction with an organism or anaylysis.'),
    );
 
-   $form['organism_id'] = array (
+   $form['organism_id'] = array(
      '#title'       => t('Organism'),
      '#type'        => t('select'),
      '#description' => t("Choose the organism for which features will be deleted."),
@@ -51,7 +51,7 @@ function tripal_feature_delete_form (){
    tripal_db_set_active($previous_db);  // now use drupal database
    $analyses = array();
    $analyses[''] = '';
-   while($analysis = db_fetch_object($org_rset)){
+   while ($analysis = db_fetch_object($org_rset)) {
       $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
    }
 //  TODO: ADD THIS BACK IN LATER
@@ -70,32 +70,32 @@ function tripal_feature_delete_form (){
    return $form;
 }
 
-function tripal_feature_delete_form_validate ($form, &$form_state){
+function tripal_feature_delete_form_validate($form, &$form_state) {
    $organism_id   = $form_state['values']['organism_id'];
    $seq_type      = trim($form_state['values']['seq_type']);
    $analysis_id   = $form_state['values']['analysis_id'];
    $is_unique     = $form_state['values']['is_unique'];
    $feature_names = $form_state['values']['feature_names'];
 
-   if (!$organism_id and !$anaysis_id and !$seq_type and !$feature_names){
-      form_set_error('feature_names',t("Please select at least one option"));
+   if (!$organism_id and !$anaysis_id and !$seq_type and !$feature_names) {
+      form_set_error('feature_names', t("Please select at least one option"));
    }
 
    // check to make sure the types exists
-   if($seq_type){
+   if ($seq_type) {
       $cvtermsql = "SELECT CVT.cvterm_id
                     FROM {cvterm} CVT
                        INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
                        LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
                     WHERE cv.name = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
-      $cvterm = db_fetch_object(db_query($cvtermsql,'sequence',$seq_type,$seq_type));
-      if(!$cvterm){
-         form_set_error('seq_type',t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
+      $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $seq_type, $seq_type));
+      if (!$cvterm) {
+         form_set_error('seq_type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
       }
    }
 }
 
-function tripal_feature_delete_form_submit ($form, &$form_state){
+function tripal_feature_delete_form_submit($form, &$form_state) {
    global $user;
 
    $organism_id   = $form_state['values']['organism_id'];
@@ -104,47 +104,47 @@ function tripal_feature_delete_form_submit ($form, &$form_state){
    $is_unique     = $form_state['values']['is_unique'];
    $feature_names = $form_state['values']['feature_names'];
 
-   $args = array($organism_id,$analysis_id,$seq_type,$is_unique,$feature_names);
+   $args = array($organism_id, $analysis_id, $seq_type, $is_unique, $feature_names);
 
-   tripal_add_job("Delete features",'tripal_feature',
-      'tripal_feature_delete_features',$args,$user->uid);
+   tripal_add_job("Delete features", 'tripal_feature',
+      'tripal_feature_delete_features', $args, $user->uid);
 }
 
 
-function tripal_feature_delete_features($organism_id,$analysis_id,$seq_type,
-   $is_unique,$feature_names,$job = NULL)
-{
+function tripal_feature_delete_features($organism_id, $analysis_id, $seq_type,
+   $is_unique, $feature_names, $job = NULL) {
 
    global $user;
-   $match = array();   
+   $match = array();
 
    // if feature names have been provided then handle that separately
-   if($feature_names){
-      $names = preg_split('/\s+/',$feature_names);
-      if(sizeof($names) == 1){
+   if ($feature_names) {
+      $names = preg_split('/\s+/', $feature_names);
+      if (sizeof($names) == 1) {
          $names = $names[0];
       }
-      if($is_unique){
+      if ($is_unique) {
          $match['uniquename'] = $names;
-      } else {
+      }
+      else {
          $match['name'] = $names;
       }
-      $num_deletes = tripal_core_chado_select('feature',array('count(*) as cnt'),$match);
-      print "Deleting ".$num_deletes[0]->cnt ." features\n"; 
-      tripal_core_chado_delete('feature',$match);
+      $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
+      print "Deleting " . $num_deletes[0]->cnt . " features\n";
+      tripal_core_chado_delete('feature', $match);
    }
 
    // if the user has provided an analysis_id then handle that separately
-   elseif($analysis_id){
+   elseif ($analysis_id) {
       tripal_feature_delete_by_analysis();
    }
    else {
 
 
-      if($organism_id){
+      if ($organism_id) {
          $match['organism_id'] = $organism_id;
       }
-      if($seq_type){
+      if ($seq_type) {
          $match['type_id'] = array(
             'name' => $seq_type,
             'cv_id' => array(
@@ -152,18 +152,17 @@ function tripal_feature_delete_features($organism_id,$analysis_id,$seq_type,
             ),
          );
       }
-      $num_deletes = tripal_core_chado_select('feature',array('count(*) as cnt'),$match);
-      print "Deleting ".$num_deletes[0]->cnt ." features\n"; 
-      tripal_core_chado_delete('feature',$match);
+      $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
+      print "Deleting " . $num_deletes[0]->cnt . " features\n";
+      tripal_core_chado_delete('feature', $match);
    }
 
    print "Removing orphaned feature pages\n";
-   tripal_features_cleanup(array(),$user->uid);
+   tripal_features_cleanup(array(), $user->uid);
 }
 
-function tripal_feature_delete_by_analysis($organism_id,$analysis_id,$seq_type,
-   $is_unique,$feature_names,$job = NULL)
-{
+function tripal_feature_delete_by_analysis($organism_id, $analysis_id, $seq_type,
+   $is_unique, $feature_names, $job = NULL) {
 
 }
 

+ 68 - 64
tripal_feature/tripal_feature-properties.inc

@@ -10,12 +10,12 @@ function tripal_feature_edit_ALL_properties_page($node) {
 
   // get the list of properties for this feature
   $values  = array('feature_id' => $node->feature->feature_id);
-  $options = array('order_by' => array('type_id' => 'ASC','rank'=>'ASC'));
-  $properties = tripal_core_generate_chado_var('featureprop',$values,$options);
-  $properties = tripal_core_expand_chado_vars($properties,'field','featureprop.value');
-  
+  $options = array('order_by' => array('type_id' => 'ASC', 'rank' => 'ASC'));
+  $properties = tripal_core_generate_chado_var('featureprop', $values, $options);
+  $properties = tripal_core_expand_chado_vars($properties, 'field', 'featureprop.value');
+
   $expand_add = (sizeof($properties)) ? FALSE : TRUE;
-  
+
   // add the appopriate form sections
   $output .= drupal_get_form('tripal_feature_add_ONE_property_form', $node, $expand_add);
   $output .= drupal_get_form('tripal_feature_edit_ALL_properties_form', $node, $properties);
@@ -25,7 +25,7 @@ function tripal_feature_edit_ALL_properties_page($node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
@@ -38,35 +38,35 @@ function tripal_feature_add_ONE_property_form($form_state, $node, $expand) {
     '#title' => t('Add Property'),
     '#collapsible' => TRUE,
     '#collapsed' => ($expand) ? FALSE : TRUE,
-  ); 
+  );
 
   $form['prop_nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
-  
+
   $form['add_properties']['feature_id'] = array(
     '#type' => 'value',
     '#value' => $feature_id,
     '#required' => TRUE
   );
-  
+
   // right now this defaults to the 'feature_property' CV
   // but in the future it should be more flexible
   $form['cv_name'] = array(
     '#type' => 'hidden',
     '#value' => 'feature_property'
   );
-	
+
   // get the list of property types
   $prop_type_options = array();
-  $columns = array('cvterm_id','name');
+  $columns = array('cvterm_id', 'name');
   $values = array(
     'cv_id' => array(
       'name' => $form['cv_name']['#value'],
     )
   );
-  $results = tripal_core_chado_select('cvterm',$columns,$values);
+  $results = tripal_core_chado_select('cvterm', $columns, $values);
   foreach ($results as $r) {
     $prop_type_options[$r->name] = $r->name;
   }
@@ -83,7 +83,7 @@ function tripal_feature_add_ONE_property_form($form_state, $node, $expand) {
   );
 
   $form['add_properties']['submit-add'] = array(
-    '#type' => 'submit',         
+    '#type' => 'submit',
     '#value' => t('Add Property')
   );
 
@@ -91,7 +91,7 @@ function tripal_feature_add_ONE_property_form($form_state, $node, $expand) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
@@ -99,34 +99,35 @@ function tripal_feature_add_ONE_property_form_validate($form, &$form_state) {
 
    // Only Require if Adding Property
    if ($form_state['clicked_button']['#value'] == t('Add Property') ) {
-   
+
       // Check that there is a feature
       if ( $form_state['values']['feature_id'] <= 0 ) {
          form_set_error('feature_id', 'There is no associated feature.');
       }
-		
+
       // Check that Selected a type
       if ( !$form_state['values']['property']) {
          form_set_error('property', 'Please select a type of property.');
-      } 
-   } 
+      }
+   }
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_add_ONE_property_form_submit($form, &$form_state) {	
+function tripal_feature_add_ONE_property_form_submit($form, &$form_state) {
    $feature_id = $form_state['values']['feature_id'];
    $property = $form_state['values']['property'];
-   $value = $form_state['values']['prop_value'];       
-   $cv_name = $form_state['values']['cv_name'];       
-       
-   $succes = tripal_feature_insert_property($feature_id,$property,$value,0,$cv_name);
-   if($succes){
+   $value = $form_state['values']['prop_value'];
+   $cv_name = $form_state['values']['cv_name'];
+
+   $succes = tripal_feature_insert_property($feature_id, $property, $value, 0, $cv_name);
+   if ($succes) {
       drupal_set_message("Successfully Added Property: $property => $value");
-   } else {
+   }
+   else {
       drupal_set_message("Failed to Add Property: $property => $value");
    }
 }
@@ -136,114 +137,114 @@ function tripal_feature_add_ONE_property_form_submit($form, &$form_state) {
  * Handles adding of Properties for features
  *
  * @ingroup tripal_feature
- */ 
+ */
 function tripal_feature_edit_ALL_properties_form($form_state, $node, $properties) {
   $form = array();
   $feature_id = $node->feature->feature_id;
-  
+
   $form['nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
-  
+
   $form['add_properties']['feature_id'] = array(
     '#type' => 'value',
     '#value' => $feature_id,
     '#required' => TRUE
   );
-    
+
   // right now this defaults to the 'feature_property' CV
   // but in the future it should be more flexible
   $form['cv_name'] = array(
     '#type' => 'hidden',
     '#value' => 'feature_property'
   );
-  
+
   if (sizeof($properties)) {
-    
+
     // build the select box options for the property name
     $prop_type_options = array();
-    $columns = array('cvterm_id','name');
+    $columns = array('cvterm_id', 'name');
     $values = array(
        'cv_id' => array(
           'name' => $form['cv_name']['#value']
        )
     );
-    $results = tripal_core_chado_select('cvterm',$columns, $values);
+    $results = tripal_core_chado_select('cvterm', $columns, $values);
     foreach ($results as $r) {
       $prop_type_options[$r->name] = $r->name;
     }
-    
-    // iterate through all of the properties and create a set of form elements 
+
+    // iterate through all of the properties and create a set of form elements
     foreach ($properties as $i => $property) {
        $form["num-$i"] = array(
           '#type' => 'fieldset',
           '#value' => "Property $i"
-       );      
+       );
        $form["num-$i"]["id-$i"] = array(
           '#type' => 'hidden',
           '#value' => $property->featureprop_id
-       );      
-       $default = array_search($property->type, $prop_type_options);  
+       );
+       $default = array_search($property->type, $prop_type_options);
        $form["num-$i"]["type-$i"] = array(
           '#type' => 'select',
           '#options' => $prop_type_options,
           '#default_value' => $property->type_id->name
-       );     
+       );
        $form["num-$i"]["value-$i"] = array(
           '#type' => 'textfield',
           '#default_value' => $property->value
-       );      
+       );
        $form["num-$i"]["delete-$i"] = array(
           '#type' => 'submit',
           '#value' => t("Delete"),
          '#name' => "delete-$i",
        );
     } //end of foreach property
-  
+
     $form['num_properties'] = array(
       '#type' => 'hidden',
       '#value' => $i
     );
-  
+
     $form["submit-edits"] = array(
       '#type' => 'submit',
       '#value' => t('Update All Properties')
     );
   }
-  
+
   return $form;
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
 function tripal_feature_edit_ALL_properties_form_submit($form, &$form_state) {
 
-  $cv_name = $form_state['values']['cv_name'];  
+  $cv_name = $form_state['values']['cv_name'];
   $feature_id = $form_state['values']["feature_id"];
   $all_good = 1;
 
   // if the update button was clicked then do the update
   if ($form_state['clicked_button']['#value'] == t('Update All Properties') ) {
-     // iterate through each of the properties and set each one               
+     // iterate through each of the properties and set each one
      for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
        $featureprop_id = $form_state['values']["id-$i"];
        $property = $form_state['values']["type-$i"];
        $value = $form_state['values']["value-$i"];
-       $success = tripal_feature_update_property_by_id($featureprop_id,$property,$value,$cv_name);       
-       if(!$success){
+       $success = tripal_feature_update_property_by_id($featureprop_id, $property, $value, $cv_name);
+       if (!$success) {
           drupal_set_message("Failed to Update Property: $property => $value");
           $all_good = 0;
        }
      }
-     if($all_good){
+     if ($all_good) {
         drupal_set_message("Updated all Properties");
      }
-     drupal_goto('node/'.$form_state['values']['nid']);
-  } 
+     drupal_goto('node/' . $form_state['values']['nid']);
+  }
   // if the delete button was clicked then remove the property
   elseif (preg_match('/delete-(\d+)/', $form_state['clicked_button']['#name'], $matches) ) {
      $i = $matches[1];
@@ -251,33 +252,35 @@ function tripal_feature_edit_ALL_properties_form_submit($form, &$form_state) {
      $property = $form_state['values']["type-$i"];
      $value = $form_state['values']["value-$i"];
      $success = tripal_feature_delete_property_by_id($featureprop_id);
-     if($success){
+     if ($success) {
         drupal_set_message("Deleted Property");
-     } else {
+     }
+     else {
         drupal_set_message("Unable to Delete Property");
      }
-  } else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+  }
+  else {
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 }
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
-function theme_tripal_feature_edit_ALL_properties_form ($form) {
+function theme_tripal_feature_edit_ALL_properties_form($form) {
   $output = '';
-  
+
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing properties for this feature, one property per line. The type refers to the type of '
-  	     .'property and the value is the value for that property. </p>';
+         .'property and the value is the value for that property. </p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Type</th><th>Value</th><th></th></tr>';
 
   for ($i=0; $i<=$form['num_properties']['#value']; $i++) {
     if (isset($form["num-$i"])) {
-      $output .= '<tr><td>'.($i+1).'</td><td>'.drupal_render($form["num-$i"]["type-$i"]).'</td><td>'.drupal_render($form["num-$i"]["value-$i"]).'</td><td>'.drupal_render($form["num-$i"]["delete-$i"]).'</td></tr>';
+      $output .= '<tr><td>' . ($i+1) . '</td><td>' . drupal_render($form["num-$i"]["type-$i"]) . '</td><td>' . drupal_render($form["num-$i"]["value-$i"]) . '</td><td>' . drupal_render($form["num-$i"]["delete-$i"]) . '</td></tr>';
       unset($form["num-$i"]);
     }
   }
@@ -290,7 +293,7 @@ function theme_tripal_feature_edit_ALL_properties_form ($form) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_feature
  */
@@ -303,13 +306,14 @@ function tripal_feature_list_properties_for_node($properties) {
 
     if (!empty($properties) ) {
       foreach ($properties as $p) {
-        $output .= '<tr><td>'.$p->type.'</td><td>'.$p->value.'</td></tr>';
+        $output .= '<tr><td>' . $p->type . '</td><td>' . $p->value . '</td></tr>';
       } // end of foreach property
     }
 
     $output .= '</table>';
 
-  } else {
+  }
+  else {
     $output = 'No properties exist for the current feature';
   }
 

+ 147 - 126
tripal_feature/tripal_feature-relationships.inc

@@ -9,8 +9,8 @@
 function tripal_feature_add_ALL_relationships_page($node) {
   $output = '';
 
-  $output .= tripal_feature_implement_add_chado_properties_progress('relationships').'<br>';
-  $output .= '<b>All Relationships should include the CURRENT Individual ('.$node->uniquename.')</b><br>';
+  $output .= tripal_feature_implement_add_chado_properties_progress('relationships') . '<br>';
+  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->uniquename . ')</b><br>';
   $output .= '<br><b>Current Relationships</b><br>';
   $output .= list_relationships_for_node($node->uniquename, $node->subject_relationships, $node->object_relationships);
   $output .= '<br><br>';
@@ -33,9 +33,9 @@ function tripal_feature_add_ONE_relationship_form($form_state, $node) {
   $_SESSION['organism'] = $organism_id; //needed for autocomplete enter feature to work
 
   $form['rel_nid'] = array(
-    '#type' => 'hidden', 
+    '#type' => 'hidden',
     '#value' => $node->nid
-  ); 
+  );
 
   $form['add_relationships'] = array(
     '#type' => 'fieldset',
@@ -88,7 +88,7 @@ function tripal_feature_add_ONE_relationship_form($form_state, $node) {
 
   );
 
-  $form['add_relationships']['r_feature_uniquename'] = array( 
+  $form['add_relationships']['r_feature_uniquename'] = array(
     '#type' => 'value',
     '#value' => $node->uniquename,
     '#required' => TRUE
@@ -109,49 +109,56 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
   if ($form_state['clicked_button']['#value'] == t('Add a Relationship') ) {
 
     // check valid feature selected for subject
-    $criteria = array('unknown' => array('value'=> $form_state['values']['subject_id'], 
-      																		'columns'=>array('name','uniquename','accession','synonym') ));
-    $subject_results = get_chado_stocks($criteria,'ANY',$_SESSION['organism']);
+    $criteria = array('unknown' => array('value' => $form_state['values']['subject_id'],
+                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
+    $subject_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
     if (sizeof($subject_results) > 1) {
       $links= array();
-      for ($i=0; $i<sizeof($subject_results); $i++) { $links[] = l($i+1, "node/".$subject_results[$i]->nid); }
-      $message = "Too many stocks match '".$form_state['values']['subject_id']."'! "
-      	       	 . " Please refine your input to match ONLY ONE stock. <br>"
-		 . "To aid in this process, here are the stocks that match your initial input: "
-		 .join(', ',$links);
+      for ($i=0; $i<sizeof($subject_results); $i++) {
+      $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
+      $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
+                  . " Please refine your input to match ONLY ONE stock. <br>"
+     . "To aid in this process, here are the stocks that match your initial input: "
+     . join(', ', $links);
       form_set_error('subject_id', $message);
-    } elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-    } elseif (sizeof($subject_results) == 1) {
+    }
+    elseif (sizeof($subject_results) < 1) {
+      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+    }
+    elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock_id;
     }
 
     // check valid stock selected for object
-    $criteria = array('unknown' => array('value'=> $form_state['values']['object_id'], 
-      																		'columns'=>array('name','uniquename','accession','synonym') ));
-    $object_results = get_chado_stocks($criteria,'ANY',$_SESSION['organism']);
+    $criteria = array('unknown' => array('value' => $form_state['values']['object_id'],
+                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
+    $object_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
     if (sizeof($object_results) > 1) {
       $links= array();
-      for ($i=0; $i<sizeof($object_results); $i++) { $links[] = l($i+1, "node/".$object_results[$i]->nid); } 
-      $message = "Too many stocks match '".$form_state['values']['object_id']."'! "
+      for ($i=0; $i<sizeof($object_results); $i++) {
+      $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
+      $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
                  . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
       form_set_error('object_id', $message);
-    } elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));                                                                         
-    } elseif (sizeof($object_results) == 1) {
+    }
+    elseif (sizeof($object_results) < 1) {
+      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+    }
+    elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock_id;
     }
 
     // check valid type selected
     if ($form_state['values']['type_id'] == 0) {
       form_set_error('type_id', 'Please select a type of relationship.');
-    } else {
-    	$previous_db = tripal_db_set_active('chado');
-    	$tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM cvterm WHERE cvterm_id=%d",$form_state['values']['type_id']));
-    	tripal_db_set_active($previous_db);
-    	
+    }
+    else {
+      $previous_db = tripal_db_set_active('chado');
+      $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['type_id']));
+      tripal_db_set_active($previous_db);
+
       if ($tmp_obj->count != 1) {
         form_set_error('type_id', 'The type you selected is not valid. Please choose another one.');
       }
@@ -160,7 +167,7 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
     // check either subject or object is the current stock
     if ( $subject_results[0]->nid != $form_state['values']['rel_nid'] ) {
       if ( $object_results[0]->nid != $form_state['values']['rel_nid'] ) {
-        form_set_error('subject_id', 'Either Subject or Object must be the current stock ('.$form_state['values']['r_stock_uniquename'].').');
+        form_set_error('subject_id', 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
       }
     }
   } //end of require validation if adding relationship
@@ -176,7 +183,7 @@ function tripal_feature_add_ONE_relationship_form_submit($form, &$form_state) {
   if ($form_state['values']['subject_id'] > 0) {
     $previous_db = db_set_active('chado');
     db_query(
-      "INSERT INTO stock_relationship (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
+      "INSERT INTO {stock_relationship} (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
       $form_state['values']['subject_id'],
       $form_state['values']['type_id'],
       $form_state['values']['object_id'],
@@ -189,14 +196,14 @@ function tripal_feature_add_ONE_relationship_form_submit($form, &$form_state) {
 
 }
 
-/** 
+/**
  *
  *
  * @ingroup tripal_feature
  */
 function tripal_feature_edit_ALL_relationships_page($node) {
   $output = '';
-	
+
   $output .= drupal_get_form('tripal_feature_edit_ALL_relationships_form', $node);
   $output .= '<br>';
   $output .= drupal_get_form('tripal_feature_add_ONE_relationship_form', $node);
@@ -205,13 +212,13 @@ function tripal_feature_edit_ALL_relationships_page($node) {
 
   return $output;
 }
-                                                      
-/**                                                 
- * Implements Hook_form()                             
- * Handles adding of Properties & Synonyms to Stocks  
+
+/**
+ * Implements Hook_form()
+ * Handles adding of Properties & Synonyms to Stocks
  *
  * @ingroup tripal_feature
- */                                                   
+ */
 function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
   $form = array();
 
@@ -219,7 +226,7 @@ function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
     '#type' => 'hidden',
     '#value' => $node->nid
   );
-  
+
   $form['r_feature_uniquename'] = array(
     '#type' => 'hidden',
     '#value' => $node->uniquename
@@ -228,9 +235,9 @@ function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
   $i=0;
 
   $feature = $node->feature;
-  $orelationships = tripal_feature_load_relationships ($feature->feature_id,'as_object');
-  $srelationships = tripal_feature_load_relationships ($feature->feature_id,'as_subject');
-  $relationships = array_merge($orelationships,$srelationships);
+  $orelationships = tripal_feature_load_relationships($feature->feature_id, 'as_object');
+  $srelationships = tripal_feature_load_relationships($feature->feature_id, 'as_subject');
+  $relationships = array_merge($orelationships, $srelationships);
 
   if (sizeof($relationships) != 0) {
      foreach ($relationships as $r) {
@@ -247,45 +254,47 @@ function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
        );
 
        //Enter relationship specific fields
-       if ( !empty($r->subject_id) ) { 
+       if ( !empty($r->subject_id) ) {
          $default = $r->subject_uniquename;
-         $description = l($r->subject_name, 'node/'.$r->subject_nid); 
-       } else { 
-          $default = $node->uniquename; 
-          $description = "Current Feature"; 
+         $description = l($r->subject_name, 'node/' . $r->subject_nid);
+       }
+       else {
+          $default = $node->uniquename;
+          $description = "Current Feature";
        }
-       $description .= " (".$r->subject_type.")";
+       $description .= " (" . $r->subject_type . ")";
        $form["num-$i"]["subject_id-$i"] = array(
-         '#type' => 'textfield',      
-         //'#title' => t('Subject'), 
+         '#type' => 'textfield',
+         //'#title' => t('Subject'),
          '#required'   => TRUE,
          '#size' => 30,
          '#default_value' => $default,
          '#description' => $description,
-       ); 
+       );
 
        $cv = tripal_cv_get_cv_by_name('relationship');
        $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
-       ksort($type_options);          
-       $form["num-$i"]["type_id-$i"] = array(  
-         '#type' => 'select',    
-         //'#title' => t('Type of Relationship'), 
+       ksort($type_options);
+       $form["num-$i"]["type_id-$i"] = array(
+         '#type' => 'select',
+         //'#title' => t('Type of Relationship'),
          '#options' => $type_options,
          '#required' => TRUE,
          '#default_value' => $r->relationship_type_id
        );
 
-       if (!empty($r->object_id) ) { 
+       if (!empty($r->object_id) ) {
          $default = $r->object_uniquename;
-         $description = l($r->object_name, 'node/'.$r->object_nid);
-       } else { 
-         $default = $node->uniquename; 
-         $description = 'Current Feature'; 
+         $description = l($r->object_name, 'node/' . $r->object_nid);
+       }
+       else {
+         $default = $node->uniquename;
+         $description = 'Current Feature';
        }
-       $description .= " (".$r->object_type.")";
+       $description .= " (" . $r->object_type . ")";
        $form["num-$i"]["object_id-$i"] = array(
-         '#type' => 'textfield',          
-         //'#title' => t('Object'),      
+         '#type' => 'textfield',
+         //'#title' => t('Object'),
          '#required'   => TRUE,
          '#size' => 30,
          '#default_value' => $default,
@@ -308,12 +317,13 @@ function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
        '#type' => 'submit',
        '#value' => t('Update All Relationships')
      );
-  } else {
+  }
+  else {
      $form["info"] = array(
        '#type' => 'markup',
        '#value' => t('No relationships currently exist for this feature.')
      );
-  } 
+  }
 
 
 
@@ -331,52 +341,59 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
   if ($form_state['clicked_button']['#value'] == t('Update All Relationships') ) {
 
     for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
-      
+
       // check valid stock selected for subject
-      $criteria = array('unknown' => array('value'=>$form_state['values']["subject_id-$i"], 
-      																		'columns'=>array('name','uniquename','accession','synonym') ));
-      $subject_results = get_chado_stocks($criteria,'ANY',$_SESSION['organism']);
+      $criteria = array('unknown' => array('value' => $form_state['values']["subject_id-$i"],
+                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
+      $subject_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
       if (sizeof($subject_results) > 1) {
         $links= array();
-        for ($j=0; $j<sizeof($subject_results); $j++) { $links[] = l($j+1, "node/".$subject_results[$j]->nid); }
-        $message = "Too many stocks match '".$form_state['values']["subject_id-$i"]."'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>" 
+        for ($j=0; $j<sizeof($subject_results); $j++) {
+        $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
+        $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
+                 . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
         form_set_error("subject_id-$i", $message);
-      } elseif (sizeof($subject_results) < 1) { 
-        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-      } elseif (sizeof($subject_results) == 1) {
+      }
+      elseif (sizeof($subject_results) < 1) {
+        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      }
+      elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
-      } 
+      }
 
       // check valid stock selected for object
-      $criteria = array('unknown' => array('value'=> $form_state['values']["object_id-$i"], 
-      																		'columns'=>array('name','uniquename','accession','synonym') ));
-      $object_results = get_chado_stocks($criteria,'ANY',$_SESSION['organism']);
+      $criteria = array('unknown' => array('value' => $form_state['values']["object_id-$i"],
+                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
+      $object_results = get_chado_stocks($criteria, 'ANY' , $_SESSION['organism']);
       if (sizeof($object_results) > 1) {
         $links= array();
-        for ($j=0; $j<sizeof($object_results); $j++) { $links[] = l($j+1, "node/".$object_results[$j]->nid); }
-        $message = "Too many stocks match '".$form_state['values']["object_id-$i"]."'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>" 
+        for ($j=0; $j<sizeof($object_results); $j++) {
+        $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
+        $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
+                 . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
         form_set_error("object_id-$i", $message);
-      } elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-      } elseif (sizeof($object_results) == 1) {
+      }
+      elseif (sizeof($object_results) < 1) {
+        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      }
+      elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock_id;
-      } 
+      }
 
       // check valid type selected
       if ($form_state['values']["type_id-$i"] == 0) {
         form_set_error('type_id', 'Please select a type of relationship.');
-      } else {
-    		$previous_db = tripal_db_set_active('chado');
-    		$tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM cvterm WHERE cvterm_id=%d",$form_state['values']["type_id-$i"]));
-    		tripal_db_set_active($previous_db);
-    	
-      	if ($tmp_obj->count != 1) {
+      }
+      else {
+        $previous_db = tripal_db_set_active('chado');
+        $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d" , $form_state['values']["type_id-$i"]));
+        tripal_db_set_active($previous_db);
+
+        if ($tmp_obj->count != 1) {
           form_set_error("type_id-$i", 'The type you selected is not valid. Please choose another one.');
         }
       }
@@ -384,7 +401,7 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
       // check either subject or object is the current stock
       if ( $subject_results[0]->nid != $form_state['values']['nid'] ) {
         if ( $object_results[0]->nid != $form_state['values']['nid'] ) {
-          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock ('.$form_state['values']['r_stock_uniquename'].').');
+          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
         }
       }
 
@@ -406,25 +423,28 @@ function tripal_feature_edit_ALL_relationships_form_submit($form, &$form_state)
 
        //process stock textfields
        tripal_feature_update_relationship(
-				$form_state['values']["id-$i"], 
-				$form_state['values']["subject_id-$i"],
-				$form_state['values']["type_id-$i"], 
-				$form_state['values']["object_id-$i"]
-			);
+        $form_state['values']["id-$i"],
+        $form_state['values']["subject_id-$i"],
+        $form_state['values']["type_id-$i"],
+        $form_state['values']["object_id-$i"]
+      );
      }
      drupal_set_message("Updated all Relationships");
-     drupal_goto('node/'.$form_state['values']['nid']);
+     drupal_goto('node/' . $form_state['values']['nid']);
 
-  } elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
+  }
+  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
      $i = $matches[1];
      tripal_feature_delete_relationship($form_state['values']["id-$i"]);
      drupal_set_message("Deleted Relationship");
 
-  } elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
-    drupal_goto('node/'.$form_state['values']['nid']);
-  } else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
+    drupal_goto('node/' . $form_state['values']['nid']);
+  }
+  else {
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 
 }
@@ -434,13 +454,13 @@ function tripal_feature_edit_ALL_relationships_form_submit($form, &$form_state)
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_update_relationship ($stock_relationship_id, $subject_id, $cvterm_id, $object_id) {
+function tripal_feature_update_relationship($stock_relationship_id, $subject_id, $cvterm_id, $object_id) {
 
   $previous_db = db_set_active('chado');
   db_query(
-    "UPDATE stock_relationship SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
+    "UPDATE {stock_relationship} SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
     $subject_id,
-    $cvterm_id, 
+    $cvterm_id,
     $object_id,
     $stock_relationship_id
   );
@@ -453,11 +473,11 @@ function tripal_feature_update_relationship ($stock_relationship_id, $subject_id
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_delete_relationship ($stock_relationship_id) {
+function tripal_feature_delete_relationship($stock_relationship_id) {
 
   $previous_db = db_set_active('chado');
   db_query(
-    "DELETE FROM stock_relationship WHERE stock_relationship_id=%d",
+    "DELETE FROM {stock_relationship} WHERE stock_relationship_id=%d",
     $stock_relationship_id
   );
   db_set_active($previous_db);
@@ -469,23 +489,23 @@ function tripal_feature_delete_relationship ($stock_relationship_id) {
  *
  * @ingroup tripal_feature
  */
-function theme_tripal_feature_edit_ALL_relationships_form ($form) {
+function theme_tripal_feature_edit_ALL_relationships_form($form) {
   $output = '';
-  
+
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating '
-  	    .'the subject and object of the relationship can contain the uniquename, name, database '
-	    .'reference or synonym of a stock of the same organism.</p>';
+        .'the subject and object of the relationship can contain the uniquename, name, database '
+      .'reference or synonym of a stock of the same organism.</p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Subject</th><th>Type</th><th>Object</th><th></th></tr>';
 
-  for ($i=1; $i<=$form['num_relationships']['#value']; $i++) {
-    $output .= '<tr><td>'.drupal_render($form["num-$i"]).'</td>'.
-      	      '<td>'.drupal_render($form["subject_id-$i"]).'</td>'.
-	            '<td>'.drupal_render($form["type_id-$i"]).'</td>'.
-     	         '<td>'.drupal_render($form["object_id-$i"]).'</td>'.
-	            '<td>'.drupal_render($form["submit-$i"]).'</td></tr>';
+  for ($i=1; $i <= $form['num_relationships']['#value']; $i++) {
+    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td>' .
+              '<td>' . drupal_render($form["subject_id-$i"]) . '</td>' .
+              '<td>' . drupal_render($form["type_id-$i"]) . '</td>' .
+                '<td>' . drupal_render($form["object_id-$i"]) . '</td>' .
+              '<td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
   $output .= '</table><br>';
@@ -508,19 +528,20 @@ function tripal_feature_list_relationships_for_node($feature_name, $subject_rela
 
     if (!empty($subject_relationships) ) {
       foreach ($subject_relationships as $s) {
-        $output .= '<tr><td>'.$s->subject_name.'</td><td>'.$s->relationship_type.'</td><td>'.$feature_name.'</td></tr>';
+        $output .= '<tr><td>' . $s->subject_name . '</td><td>' . $s->relationship_type . '</td><td>' . $feature_name . '</td></tr>';
       }
     }
 
     if (!empty($object_relationships) ) {
       foreach ($object_relationships as $o) {
-        $output .= '<tr><td>'.$feature_name.'</td><td>'.$o->relationship_type.'</td><td>'.$o->object_name.'</td></tr>';
+        $output .= '<tr><td>' . $feature_name . '</td><td>' . $o->relationship_type . '</td><td>' . $o->object_name . '</td></tr>';
       } // end of foreach property
     }
 
     $output .= '</table>';
-  } else {
-    $output = 'No Relationships For the Current Feature'; 
+  }
+  else {
+    $output = 'No Relationships For the Current Feature';
   }
 
   return $output;

+ 34 - 25
tripal_feature/tripal_feature-secondary_tables.inc

@@ -1,5 +1,4 @@
 <?php
-// $Id$
 
 /**
  *
@@ -14,9 +13,9 @@ function tripal_feature_implement_back_to_feature_button($form_state, $nid) {
     '#value' => $nid
   );
 
-  $form["submit-back"] = array( 
+  $form["submit-back"] = array(
     '#type' => 'submit',
-    '#value' => t('Back to Stock') 
+    '#value' => t('Back to Stock')
   );
 
   return $form;
@@ -28,7 +27,7 @@ function tripal_feature_implement_back_to_feature_button($form_state, $nid) {
  * @ingroup tripal_feature
  */
 function tripal_feature_implement_back_to_feature_button_submit($form, $form_state) {
-  drupal_goto('node/'.$form_state['values']['nid']);
+  drupal_goto('node/' . $form_state['values']['nid']);
 }
 
 /**
@@ -38,24 +37,28 @@ function tripal_feature_implement_back_to_feature_button_submit($form, $form_sta
  */
 function tripal_feature_implement_add_chado_properties_progress($current) {
 
-    $value = '<div class="form_progress"><div class="form_progress-text">'; 
+    $value = '<div class="form_progress"><div class="form_progress-text">';
 
-    if ($current == 'main') { $value .= '<span id="form-step-current">Create Basic Feature</span>'; } 
+    if ($current == 'main') {
+    $value .= '<span id="form-step-current">Create Basic Feature</span>'; }
     else { $value .= '<span id="form-step">Create Basic Stock</span>'; }
 
     $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'properties') { $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
+    if ($current == 'properties') {
+    $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
     else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }
 
-    $value .= '<span id="form-segway">  >>  </span>';                       
+    $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'db_references') { $value .= '<span id="form-step-current">Add Database References</span>'; }
+    if ($current == 'db_references') {
+    $value .= '<span id="form-step-current">Add Database References</span>'; }
     else { $value .= '<span id="form-step">Add Database References</span>'; }
 
-    $value .= '<span id="form-segway">  >>  </span>';         
+    $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'relationships') { $value .= '<span id="form-step-current">Add Relationships</span>'; }
+    if ($current == 'relationships') {
+    $value .= '<span id="form-step-current">Add Relationships</span>'; }
     else { $value .= '<span id="form-step">Add Relationships</span>'; }
 
     $value .= '</div></div>';
@@ -85,7 +88,8 @@ function tripal_feature_implement_add_chado_properties_navigate($form_state, $st
     'relationships' => 'node/%node/relationships'
   );
   $steps_value = array();
-  foreach ($steps as $k => $v) { $steps_value[] = $k.';'.$v; }
+  foreach ($steps as $k => $v) {
+  $steps_value[] = $k . ';' . $v; }
   $form['steps'] = array(
     '#type' => 'hidden',
     '#value' => implode('::', $steps_value)
@@ -114,7 +118,7 @@ function tripal_feature_implement_add_chado_properties_navigate($form_state, $st
   }
 
   if ($step != $form['last_step']['#value']) {
-    $form['submit-next'] = array( 
+    $form['submit-next'] = array(
       '#type' => 'submit',
       '#value' => t('Next Step')
     );
@@ -122,7 +126,7 @@ function tripal_feature_implement_add_chado_properties_navigate($form_state, $st
 
   if ($step == $form['last_step']['#value']) {
     $form['submit-finish'] = array(
-      '#type' => 'submit', 
+      '#type' => 'submit',
       '#value' => t('Finish')
     );
   }
@@ -137,7 +141,7 @@ function tripal_feature_implement_add_chado_properties_navigate($form_state, $st
  */
 function tripal_feature_implement_add_chado_properties_navigate_submit($form, $form_state) {
 
-  $raw_steps = preg_split('/::/', $form_state['values']['steps']); 
+  $raw_steps = preg_split('/::/', $form_state['values']['steps']);
 
   $steps = array();
   $current_index = 'EMPTY';
@@ -146,7 +150,7 @@ function tripal_feature_implement_add_chado_properties_navigate_submit($form, $f
   foreach ($raw_steps as $raw_step) {
     $step = preg_split('/;/', $raw_step);
     $steps[$i] = $step;
-    
+
     if ($step[0] == $form_state['values']['current_step']) {
       $current_index = $i;
     }
@@ -154,16 +158,19 @@ function tripal_feature_implement_add_chado_properties_navigate_submit($form, $f
     $i++;
   }
   $num_steps = $i;
-  
-  if (strcmp($current_index,'EMPTY') == 0) {
+
+  if (strcmp($current_index, 'EMPTY') == 0) {
     // No Matching Step
-    drupal_set_message('Could not determine next step -'.$form_state['values']['current_step'].', please contact the administrator', 'error');
-  } elseif ($current_index == 0) {
+    drupal_set_message('Could not determine next step -' . $form_state['values']['current_step'] . ', please contact the administrator', 'error');
+  }
+  elseif ($current_index == 0) {
     $next_goto = $steps[$current_index+1][1];
-  } elseif ($current_index == ($num_steps-1)) {
+  }
+  elseif ($current_index == ($num_steps-1)) {
     $prev_goto = $steps[$current_index-1][1];
     $next_goto = 'node/%node';
-  } else {
+  }
+  else {
     $prev_goto = $steps[$current_index-1][1];
     $next_goto = $steps[$current_index+1][1];
   }
@@ -172,10 +179,12 @@ function tripal_feature_implement_add_chado_properties_navigate_submit($form, $f
     //replace %node
     $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
     $_REQUEST['destination'] = $prev_goto;
-  } elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
     $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
     $_REQUEST['destination'] = $next_goto;
-  } elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
     $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
     $_REQUEST['destination'] = $next_goto;
   }
@@ -213,7 +222,7 @@ function tripal_feature_is_obsolete_form_submit($form, &$form_state) {
 
   $previous_db = db_set_active('chado');
   db_query(
-    "UPDATE stock SET is_obsolete='t' WHERE stock_id=%d",
+    "UPDATE {stock} SET is_obsolete='t' WHERE stock_id=%d",
     $form_state['values']['make_obsolete_stock_id']
   );
   db_set_active($previous_db);

+ 184 - 180
tripal_feature/tripal_feature.admin.inc

@@ -3,7 +3,7 @@
 /**
  * Purpose: Provide Guidance to new Tripal Admin
  *
- * @return 
+ * @return
  *   HTML Formatted text
  *
  * @ingroup tripal_feature
@@ -12,31 +12,31 @@ function tripal_feature_module_description_page() {
 
   $text .= '<h3>Tripal Feature Administrative Tools Quick Links:</h3>';
   $text .= "<ul>
-             <li><a href=\"".url("admin/tripal/tripal_feature/configuration") . "\">Feature Configuration</a></li>
-             <li><a href=\"".url("admin/tripal/tripal_feature/fasta_loader"). "\">Import a multi-FASTA file</a></li>
-             <li><a href=\"".url("admin/tripal/tripal_feature/gff3_load"). "\">Import a GFF3 file</a></li>
-             <li><a href=\"".url("admin/tripal/tripal_feature/sync") . "\">Sync Features</a></li>
-             <li><a href=\"".url("admin/tripal/tripal_feature/delete") . "\">Delete Features</a></li>
+             <li><a href=\"" . url("admin/tripal/tripal_feature/configuration") . "\">Feature Configuration</a></li>
+             <li><a href=\"" . url("admin/tripal/tripal_feature/fasta_loader") . "\">Import a multi-FASTA file</a></li>
+             <li><a href=\"" . url("admin/tripal/tripal_feature/gff3_load") . "\">Import a GFF3 file</a></li>
+             <li><a href=\"" . url("admin/tripal/tripal_feature/sync") . "\">Sync Features</a></li>
+             <li><a href=\"" . url("admin/tripal/tripal_feature/delete") . "\">Delete Features</a></li>
            </ul>";
-#             <li><a href=\"".url("admin/tripal/tripal_feature/aggregate"). "\">Feature Relationship Aggegators</a></li> 
+#             <li><a href=\"".url("admin/tripal/tripal_feature/aggregate"). "\">Feature Relationship Aggegators</a></li>
 
   $text .= '<h3>Module Description:</h3>';
   $text .= '<p>This module provides an interface for the Chado feature module which stores information
             related to genomic features.  This module provides support for bulk loading of data in
-            FASTA or GFF format, visualization of "feature" pages, editing and updating.  
+            FASTA or GFF format, visualization of "feature" pages, editing and updating.
             </p>';
 
   $text .= '<h3>Setup Instructions:</h3>';
   $text .= '<p>After installation of the feature module.  The following tasks should be performed
             <ol>
-              <li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for 
-               controlling access to feature content and functions. These permissions include viewing, 
+              <li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for
+               controlling access to feature content and functions. These permissions include viewing,
                creating, editing or administering of
-               feature content. The default is that only the original site administrator has these 
-               permissions.  You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users, 
-               <a href="'.url('admin/user/user').'">assign users to roles</a> and
-               <a href="'.url('admin/user/permissions').'">assign permissions</a> for the feature content to 
-               those roles.  For a simple setup, allow anonymous users access to view organism content and 
+               feature content. The default is that only the original site administrator has these
+               permissions.  You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
+               <a href="' . url('admin/user/user') . '">assign users to roles</a> and
+               <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the feature content to
+               those roles.  For a simple setup, allow anonymous users access to view organism content and
                allow the site administrator all other permissions.</p></li>
 
                <li><p><b>Themeing</b>:  Before content from Chado can be visualized the Tripal base theme must
@@ -46,8 +46,8 @@ function tripal_feature_module_description_page() {
 
                <li><p><b>Loading of Ontologies</b>:  If you
                used Tripal to create the Chado database, then you must load ontologies before proceeding.  Visit the
-               page to <a href="'.url('admin/tripal/tripal_cv/obo_loader').'">load ontologies</a> and load at 
-               least the following ontologies:  
+               page to <a href="' . url('admin/tripal/tripal_cv/obo_loader') . '">load ontologies</a> and load at
+               least the following ontologies:
                <ul>
                   <li>Chado Feature Properties</li>
                   <li>Relationship Ontology</li>
@@ -55,80 +55,80 @@ function tripal_feature_module_description_page() {
                   <li>Gene Ontology (if loading GO terms for features)</li>
                </ul></p></li>
 
-               <li><p><b>Create Organisms</b>:  Before adding feature data you must already have the 
-               organisms loaded in the database.  See the 
-               <a href="'.url('admin/tripal/tripal_organism').'">Tripal Organism Admin page</a> for 
+               <li><p><b>Create Organisms</b>:  Before adding feature data you must already have the
+               organisms loaded in the database.  See the
+               <a href="' . url('admin/tripal/tripal_organism') . '">Tripal Organism Admin page</a> for
                instructions for adding and Syncing organisms.</p></li>
 
                <li><p><b>Create Analysis</b>:  Tripal requires that feature data loaded using the Tripal loaders
                be associated with an analyis.  This provides a grouping for the feature data and can be used
                later to visualize data pipelines.  Before loading feature data through the FASTA or GFF loaders
-               you will need to <a href="'.url('node/add').'">create an analysis</a> for the data.</p></li>
+               you will need to <a href="' . url('node/add') . '">create an analysis</a> for the data.</p></li>
 
-               <li><p><b>Create Referring Database Entries</b>:  If you would like to associate your feature data with an 
-               external reference database, check to ensure that the <a href="'.url('admin/tripal/tripal_db/edit_db').'">
-               database record already exists</a>.  If not you should <a href="'.url('admin/tripal/tripal_db/add_db').'">add a new database record</a> before importing
+               <li><p><b>Create Referring Database Entries</b>:  If you would like to associate your feature data with an
+               external reference database, check to ensure that the <a href="' . url('admin/tripal/tripal_db/edit_db') . '">
+               database record already exists</a>.  If not you should <a href="' . url('admin/tripal/tripal_db/add_db') . '">add a new database record</a> before importing
                feature data.</p></li>
 
-               <li><p><b>Data Import</b>:  if you do not already have an existing Chado database with preloaded data 
+               <li><p><b>Data Import</b>:  if you do not already have an existing Chado database with preloaded data
                then you will want
-               to import data.  You can do so using the Chado perl scripts that come with the normal 
-               <a href="http://gmod.org/wiki/Chado">distribution of Chado</a> or you can use the <a href="'.url('admin/tripal/tripal_feature/fasta_loader').'">FASTA loader</a> and 
-               <a href="'.url('admin/tripal/tripal_feature/gff3_load').'">GFF loader</a> provided here.  If you
+               to import data.  You can do so using the Chado perl scripts that come with the normal
+               <a href="http://gmod.org/wiki/Chado">distribution of Chado</a> or you can use the <a href="' . url('admin/tripal/tripal_feature/fasta_loader') . '">FASTA loader</a> and
+               <a href="' . url('admin/tripal/tripal_feature/gff3_load') . '">GFF loader</a> provided here.  If you
                created the Chado database using Tripal then you\'ll most likely want to use the Tripal loaders.  If your data
-               is not condusive for loading with these loaders you may have to write your own loaders. 
+               is not condusive for loading with these loaders you may have to write your own loaders.
                </p></li>
 
                <li><p><b>Sync Features</b>:  After data is loaded you need to sync features.  This process is what
                creates the pages for viewing online.  Not all features need be synced.  For instance, if you
                have loaded whole genome sequence with fully defined gene models with several features to define
                a gene and its products (e.g. gene, mRNA, CDS, 5\'UTR, 3\'UTR, etc) you probably only want to create
-               pages for genes or genes and mRNA.  You probably do not want a page for a 5\'UTR.  
-               Using the <a href="'.url('admin/tripal/tripal_feature/configuration/sync').'">Feature Sync page</a> 
+               pages for genes or genes and mRNA.  You probably do not want a page for a 5\'UTR.
+               Using the <a href="' . url('admin/tripal/tripal_feature/configuration/sync') . '">Feature Sync page</a>
                you can sync (or create pages) for the desired feature types. </p></li>
 
-               <li><p><b>Set Feature URL</b>:  It is often convenient to have a simple URL for each feature page. 
+               <li><p><b>Set Feature URL</b>:  It is often convenient to have a simple URL for each feature page.
                For example, http://www.mygenomesite.org/[feature], where [feature] is a unique identifier for a feature page.
-               With this, people can easily include links to feature pages of interest. Use the 
-               <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a> 
+               With this, people can easily include links to feature pages of interest. Use the
+               <a href="' . url('admin/tripal/tripal_feature/configuration') . '">Feature Configuration page</a>
                to specify whether to use the feature name, unique name or internal ID as the [feature] portion of the
                URL.  Select the one that will guarantee a unique identifier for feature pages.</p></li>
 
                <li><p><b>Indexing</b>:  Once all data has been loaded (including analysis data--e.g. blast, interpro, etc.)
-               you can index all feature pages for searching if you want to ues the Drupal default search mechanism. 
-               Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a> 
+               you can index all feature pages for searching if you want to ues the Drupal default search mechanism.
+               Use the <a href="' . url('admin/tripal/tripal_feature/configuration') . '">Feature Configuration page</a>
                to either Index (for the first time) or "Reindex" (after adding new data)
                the feature pages for searching.  Once the site is 100% indexed the pages will be searchable using Drupal\'s
-               full text searching.  You can find the percent indexed for the entire site by visiting the 
-               <a href="'.url('admin/settings/search').'">Search settings page</a>. Indexing
+               full text searching.  You can find the percent indexed for the entire site by visiting the
+               <a href="' . url('admin/settings/search') . '">Search settings page</a>. Indexing
                can take quite a while if you have a lot of data</p></li>
 
-               <li><p><b>Set Taxonomy</b>:  Drupal provides a mechanism for categorizing content to allow 
-               for advanced searching.  Drupal calls this "Taxonomy", but is essentially categorizing the pages.  
-               You can categorize feature pages by their type (e.g. gene, mRNA, contig, EST, etc.) and by the 
-               organism to which they belong.  This allows for filtering of search results by organism and feature type. 
-               Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a> to
+               <li><p><b>Set Taxonomy</b>:  Drupal provides a mechanism for categorizing content to allow
+               for advanced searching.  Drupal calls this "Taxonomy", but is essentially categorizing the pages.
+               You can categorize feature pages by their type (e.g. gene, mRNA, contig, EST, etc.) and by the
+               organism to which they belong.  This allows for filtering of search results by organism and feature type.
+               Use the <a href="' . url('admin/tripal/tripal_feature/configuration') . '">Feature Configuration page</a> to
                set the Taxonomy.</p></li>
             </ol>
             </p>';
-  
-  
+
+
   $text .= '<h3>Features of this Module:</h3>';
-  $text .= '<p>Aside from data loading and feature page setup (as described in the Setup section above), 
+  $text .= '<p>Aside from data loading and feature page setup (as described in the Setup section above),
             The Tripal feature module also provides the following functionality
             <ul>
-              <li><p><b>Feature Browser:</b>  The feature browser is a tabular list of features with links to their 
-               feature pages which appears on the organism 
+              <li><p><b>Feature Browser:</b>  The feature browser is a tabular list of features with links to their
+               feature pages which appears on the organism
                page.  It was created to provide a mechanism to allow site visitors to quickly
                accesss feature pages when they do not know what to search for.  For sites with large numbers of features, this
-               method for finding a specific pages is inadequate, but may still be included to aid new site 
-               visitors.    This browser can be toggled on or off using the 
-               <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>
- 
+               method for finding a specific pages is inadequate, but may still be included to aid new site
+               visitors.    This browser can be toggled on or off using the
+               <a href="' . url('admin/tripal/tripal_feature/configuration') . '">Feature Configuration page</a></p></li>
+
               <li><p><b>Feature Summary Report:</b>  The feature summary report is a pie chart that indicates the types and quantities
-              of feature types (Sequence Ontology terms) that are loaded in the database. It appears on the organism 
-              page.  The summary can be toggled on or off using the 
-              <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>             
+              of feature types (Sequence Ontology terms) that are loaded in the database. It appears on the organism
+              page.  The summary can be toggled on or off using the
+              <a href="' . url('admin/tripal/tripal_feature/configuration') . '">Feature Configuration page</a></p></li>
 
               <li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
               a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
@@ -136,56 +136,56 @@ function tripal_feature_module_description_page() {
               and create custom lists without PHP programming or customization of Tripal source code.  Views can also
               be created to filter content that has not yet been synced with Druapl in order to protect access to non
               published data (only works if Chado was installed using Tripal).  You can see a list of available pre-existing
-              Views <a href="'.url('admin/build/views/').'">here</a>, as well as create your own. </p></li>
+              Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>
 
-              <li><p><b>Basic Feature Lookup View</b>: This module provides a basic <a href="'.url('features').'">feature search 
+              <li><p><b>Basic Feature Lookup View</b>: This module provides a basic <a href="' . url('features') . '">feature search
               tool</a> for finding or listing features in Chado. It does not require indexing for Drupal searching but relies
-              on Drupal Views.  <a href="http://drupal.org/project/views">Drupal Views</a> must be installed. </p></li>              
+              on Drupal Views.  <a href="http://drupal.org/project/views">Drupal Views</a> must be installed. </p></li>
 
-              <li><p><b>Delete Features</b>: This module provides a <a href="'.url('admin/tripal/tripal_feature/delete').'">Delete Feature page</a>
+              <li><p><b>Delete Features</b>: This module provides a <a href="' . url('admin/tripal/tripal_feature/delete') . '">Delete Feature page</a>
               for bulk deltions of features. You may delete features using a list of feature names, or for a specific organism
-              or for a specific feature type.</p></li>              
+              or for a specific feature type.</p></li>
 
             </ul>
             </p>';
 
    $text .= '<h3>Page Customizations</h3>';
-   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal. 
+   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
              Below is a description of several methods.  These methods may be used in conjunction with one another to
-             provide fine-grained control. 
+             provide fine-grained control.
              <ul>
 
-             <li><p><b>Integration with Drupal Panels</b>:  <a href="http://drupal.org/project/views">Drupal Panels</a> 
-              allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming.  Tripal comes with pre-set layouts for feature pages.  However, 
+             <li><p><b>Integration with Drupal Panels</b>:  <a href="http://drupal.org/project/views">Drupal Panels</a>
+              allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming.  Tripal comes with pre-set layouts for feature pages.  However,
               Panels become useful if you prefer a layout that is different from the pre-set layouts.  Chado content
-              is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the 
+              is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
               Panel\'s GUI.</p></li>
 
-             <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the 
+             <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
              <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
              to any page without need to edit template files or knowing PHP.  You must first download and install CCK.
              With CCK, the site administartor can create a new field to appear on the page.  For example, currently,
-             the Chado publication module is not yet supported by Tripal.  Therefore, the site administrator can add a text 
+             the Chado publication module is not yet supported by Tripal.  Therefore, the site administrator can add a text
              field to the feature pages.  This content is not stored in Chado, but will appear on the feature page.  A field
              added by CCK will also appear in the form when editing a feature to allow users to manually enter the appropriate
              text.  If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
-             indicate that it is not to be shown (using the CCK interface), then manually add the new content type 
+             indicate that it is not to be shown (using the CCK interface), then manually add the new content type
              where desired by editing the templates (as described below).  If using Panels, the CCK field can be added to the
              location desired using the Panels interface.</p></li>
 
              <li><p><b>Drupal Node Templates</b>:  The Tripal packages comes with a "theme_tripal" directory that contains the
              themeing for Chado content.    The feature module has a template file for feature "nodes" (Tripal feature pages).  This file
              is named "node-chado_feature.tpl.php", and provides javascript, HTML and PHP code for display of the feature
-             pages.  You can edit this file to control which types of information (or which feature "blocks") are displayed for features. Be sure to 
+             pages.  You can edit this file to control which types of information (or which feature "blocks") are displayed for features. Be sure to
              copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
              future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
              for instructions on how to access variables and other Chado content within the template file.</p></li>
 
              <li><p><b>Feature "Block" Templates</b>:  In the "theme_tripal" directory is a subdirectory named "tripal_feature".
              Inside this directory is a set of templates that control distinct types of information for features.  For example,
-             there is a "base" template for displaying of data directly from the Chado feature table, and a "references" 
+             there is a "base" template for displaying of data directly from the Chado feature table, and a "references"
              template for showing external site references for a feature (data from the feature_dbxref table).  These templates are used both by Drupal blocks
-             for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template 
+             for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
              provides (also desribed above).  You can customize this template as you desire.  Be sure to copy the
              template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
              future Tripal updates may overwrite your customizations.  See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
@@ -194,9 +194,9 @@ function tripal_feature_module_description_page() {
 
              <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
              will see a "Resources" sidebar on each page.  The links that appear on the sidebar are automatically generated
-             using Javascript for all of the feature "Blocks" that appear on the page. If you want to add additional links 
-             (e.g. a dynamic link to GBrowse for the feature) and you want that link to appear in the 
-             "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the 
+             using Javascript for all of the feature "Blocks" that appear on the page. If you want to add additional links
+             (e.g. a dynamic link to GBrowse for the feature) and you want that link to appear in the
+             "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
              section at the bottom of the template file where the resources section is found.</p></li>
 
              </ul>
@@ -210,16 +210,16 @@ function tripal_feature_module_description_page() {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_admin () {
+function tripal_feature_admin() {
 
    // before proceeding check to see if we have any
    // currently processing jobs. If so, we don't want
    // to give the opportunity to sync libraries
    $active_jobs = FALSE;
-   if(tripal_get_module_active_jobs('tripal_feature')){
+   if (tripal_get_module_active_jobs('tripal_feature')) {
       $active_jobs = TRUE;
    }
-   if(!$active_jobs){
+   if (!$active_jobs) {
 
       get_tripal_feature_admin_form_url_set($form);
 
@@ -229,7 +229,7 @@ function tripal_feature_admin () {
          '#collapsible' => 1,
          '#collapsed' => 1 ,
       );
-      $allowedoptions1  = array (
+      $allowedoptions1  = array(
         'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
         'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
       );
@@ -237,7 +237,7 @@ function tripal_feature_admin () {
 
       $form['browser']['browser_desc'] = array(
          '#type'        => 'markup',
-         '#value' => 'A feature browser can be added to an organism page to allow users to quickly '. 
+         '#value' => 'A feature browser can be added to an organism page to allow users to quickly '.
             'access a feature.  This will most likely not be the ideal mechanism for accessing feature '.
             'information, especially for large sites, but it will alow users exploring the site (such '.
             'as students) to better understand the data types available on the site.',
@@ -246,9 +246,9 @@ function tripal_feature_admin () {
       $form['browser']['feature_types'] = array(
          '#title'       => t('Feature Types'),
          '#type'        => 'textarea',
-         '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that ".
+         '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
                              "will be shown in the feature browser."),
-         '#default_value' => variable_get('chado_browser_feature_types','gene contig'),
+         '#default_value' => variable_get('chado_browser_feature_types', 'gene contig'),
       );
 
 
@@ -256,9 +256,9 @@ function tripal_feature_admin () {
          '#title' => 'Feature Browser on Organism Page',
          '#type' => 'radios',
          '#options' => $allowedoptions1,
-         '#default_value'=>variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
+         '#default_value' => variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
       );
-      
+
       $form['browser']['browse_features_library'] = array(
          '#title' => 'Feature Browser on Library Page',
          '#type' => 'radios',
@@ -266,7 +266,7 @@ function tripal_feature_admin () {
           'show_feature_browser' => "Show the feature browse on the library page. The browser loads when page loads. This may be slow for large sites.",
           'hide_feature_browser' => "Hide the feature browser on the library page. Disables the feature browser completely.",
          ),
-         '#default_value'=>variable_get('tripal_library_feature_browse_setting', 'show_feature_browser'),
+         '#default_value' => variable_get('tripal_library_feature_browse_setting', 'show_feature_browser'),
       );
 
       $form['browser']['browse_features_analysis'] = array(
@@ -276,9 +276,9 @@ function tripal_feature_admin () {
           'show_feature_browser' => "Show the feature browse on the analysis page. The browser loads when page loads. This may be slow for large sites.",
           'hide_feature_browser' => "Hide the feature browser on the analysis page. Disables the feature browser completely.",
          ),
-         '#default_value'=>variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser'),
+         '#default_value' => variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser'),
       );
-      
+
       $form['browser']['set_browse_button'] = array(
          '#type' => 'submit',
          '#value' => t('Set Browser'),
@@ -305,7 +305,7 @@ function tripal_feature_admin () {
          '#title'       => t('Feature Types'),
          '#type'        => 'textarea',
          '#description' => t("Enter the Sequence Ontology (SO) terms for the allowed feature types when creating or editing features."),
-         '#default_value' => variable_get('chado_edit_feature_types','gene contig EST mRNA'),
+         '#default_value' => variable_get('chado_edit_feature_types', 'gene contig EST mRNA'),
       );
 
       $form['feature_edit']['set_feature_types'] = array(
@@ -328,7 +328,7 @@ function tripal_feature_admin () {
             'type and quantity of features available for the organism.',
          '#type' => 'radios',
          '#options' => $allowedoptions2,
-         '#default_value'=>variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
+         '#default_value' => variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
       );
       $form['summary']['feature_mapping'] = array(
          '#title' => 'Map feature types',
@@ -339,7 +339,7 @@ function tripal_feature_admin () {
             'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
          '#type' => 'textarea',
          '#rows' => 15,
-         '#default_value'=>variable_get('tripal_feature_summary_report_mapping', ''),
+         '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
       );
       $form['summary']['set_summary_button'] = array(
          '#type' => 'submit',
@@ -350,7 +350,8 @@ function tripal_feature_admin () {
       get_tripal_feature_admin_form_taxonomy_set($form);
       get_tripal_feature_admin_form_reindex_set($form);
       get_tripal_feature_admin_form_cleanup_set($form);
-   } else {
+   }
+   else {
       $form['notice'] = array(
          '#type' => 'fieldset',
          '#title' => t('Feature Management Temporarily Unavailable')
@@ -375,51 +376,51 @@ function tripal_feature_admin_validate($form, &$form_state) {
    global $user;  // we need access to the user info
    $job_args = array();
 
-   variable_set('chado_browser_feature_types',$form_state['values']['feature_types']);
+   variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
 
    // if the user wants to sync up the chado features then
    // add the job to the management queue
-   switch ($form_state['values']['op']){
+   switch ($form_state['values']['op']) {
 
       case  t('Sync all Features') :
-         tripal_add_job('Sync all features','tripal_feature',
-            'tripal_feature_sync_features',$job_args,$user->uid);
+         tripal_add_job('Sync all features', 'tripal_feature',
+            'tripal_feature_sync_features', $job_args, $user->uid);
          break;
 
       case t('Set/Reset Taxonomy for all feature nodes') :
-         tripal_add_job('Set all feature taxonomy','tripal_feature',
-            'tripal_features_set_taxonomy',$job_args,$user->uid);
+         tripal_add_job('Set all feature taxonomy', 'tripal_feature',
+            'tripal_features_set_taxonomy', $job_args, $user->uid);
          break;
 
       case t('Reindex all feature nodes') :
-         tripal_add_job('Reindex all features','tripal_feature',
-            'tripal_features_reindex',$job_args,$user->uid);
+         tripal_add_job('Reindex all features', 'tripal_feature',
+            'tripal_features_reindex', $job_args, $user->uid);
          break;
 
       case t('Clean up orphaned features') :
-         tripal_add_job('Cleanup orphaned features','tripal_feature',
-            'tripal_features_cleanup',$job_args,$user->uid);
+         tripal_add_job('Cleanup orphaned features', 'tripal_feature',
+            'tripal_features_cleanup', $job_args, $user->uid);
          break;
 
       case t('Set Browser') :
-         variable_set('tripal_feature_browse_setting',$form_state['values']['browse_features']);
+         variable_set('tripal_feature_browse_setting', $form_state['values']['browse_features']);
          variable_set('tripal_library_feature_browse_setting', $form_state['values']['browse_features_library']);
          variable_set('tripal_analysis_feature_browse_setting', $form_state['values']['browse_features_analysis']);
          break;
 
       case t('Set Feature Types') :
-         variable_set('tripal_feature_type_setting',$form_state['values']['feature_edit_types']);
+         variable_set('tripal_feature_type_setting', $form_state['values']['feature_edit_types']);
          break;
 
       case t('Set Summary') :
-         variable_set('tripal_feature_summary_setting',$form_state['values']['feature_summary']);
-         variable_set('tripal_feature_summary_report_mapping',$form_state['values']['feature_mapping']);
+         variable_set('tripal_feature_summary_setting', $form_state['values']['feature_summary']);
+         variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
          break;
 
       case t('Set Feature URLs') :
-         variable_set('chado_feature_url',$form_state['values']['feature_url']);
-         tripal_add_job('Set Feature URLs','tripal_feature',
-            'tripal_feature_set_urls',$job_args,$user->uid);
+         variable_set('chado_feature_url', $form_state['values']['feature_url']);
+         tripal_add_job('Set Feature URLs', 'tripal_feature',
+            'tripal_feature_set_urls', $job_args, $user->uid);
          break;
    }
 }
@@ -488,7 +489,7 @@ function get_tripal_feature_admin_form_reindex_set(&$form) {
  *
  * @ingroup tripal_feature
  */
-function get_tripal_feature_admin_form_taxonomy_set (&$form) {
+function get_tripal_feature_admin_form_taxonomy_set(&$form) {
 
 
    $form['taxonomy'] = array(
@@ -505,13 +506,13 @@ function get_tripal_feature_admin_form_taxonomy_set (&$form) {
           "filtering during searching."),
        '#weight' => 1,
    );
-   $tax_options = array (
+   $tax_options = array(
       'organism' => t('Organism name'),
       'feature_type'  => t('Feature Type (e.g. EST, mRNA, etc.)'),
       'analysis' => t('Analysis Name'),
       'library'  => t('Library Name'),
    );
-   $form['taxonomy']['tax_classes'] = array (
+   $form['taxonomy']['tax_classes'] = array(
      '#title'       => t('Available Taxonomic Classes'),
      '#type'        => t('checkboxes'),
      '#description' => t("Please select the class of terms to assign to ".
@@ -521,7 +522,7 @@ function get_tripal_feature_admin_form_taxonomy_set (&$form) {
      '#suffix'      => '</div>',
      '#options'     => $tax_options,
      '#weight'      => 2,
-     '#default_value' => variable_get('tax_classes',''),
+     '#default_value' => variable_get('tax_classes', ''),
    );
    $form['taxonomy']['button'] = array(
       '#type' => 'submit',
@@ -531,13 +532,13 @@ function get_tripal_feature_admin_form_taxonomy_set (&$form) {
 
 }
 
-function get_tripal_feature_admin_form_url_set (&$form) {
+function get_tripal_feature_admin_form_url_set(&$form) {
 
    $form['url'] = array(
       '#type' => 'fieldset',
       '#title' => t('Feature URL Path')
    );
-   $form['url']['desc'] = array (
+   $form['url']['desc'] = array(
       '#type'        => 'markup',
       '#value' => t('Each synced feature will have a unique URL which consists of '.
                           'the site domain followed by a unique identifer: for '.
@@ -557,19 +558,19 @@ function get_tripal_feature_admin_form_url_set (&$form) {
                           'It only need be unique among the synced dataset.'),
       '#required'    => FALSE,
       '#options'     => array('internal ID' => 'internal ID (Chado feature_id)',
-                              'feature unique name' => 'feature unique name', 
+                              'feature unique name' => 'feature unique name',
                               'feature name' => 'feature name'),
-      '#default_value' => variable_get('chado_feature_url','internal ID'),
+      '#default_value' => variable_get('chado_feature_url', 'internal ID'),
    );
 
-   $form['url']['chado_feature_accession_prefix'] = array (
+   $form['url']['chado_feature_accession_prefix'] = array(
       '#title'       => t('ID Prefix'),
       '#type'        => t('textfield'),
       '#description' => t("If you choose an Internal ID above you must also enter an ID prefix.".
                           "this prefix will be prepended to the internal ID number (e.g. ID38294). ".
                           "if you chose to use the feature name or unique name then this prfix is not used"),
       '#required'    => TRUE,
-      '#default_value' => variable_get('chado_feature_accession_prefix','ID'),
+      '#default_value' => variable_get('chado_feature_accession_prefix', 'ID'),
    );
 
    $form['url']['button'] = array(
@@ -583,9 +584,9 @@ function get_tripal_feature_admin_form_url_set (&$form) {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_page(){
+function tripal_feature_aggregator_page() {
    $add_url = url("admin/tripal/tripal_feature/aggregate/new");
-   $output = "<a href=\"$add_url\">Add a new aggregator</a>"; 
+   $output = "<a href=\"$add_url\">Add a new aggregator</a>";
    $output .= drupal_get_form('tripal_feature_aggregator_select_form');
    $output .= '<div id="db-edit-div">Please select an aggregator base type to view or edit</div>';
    return $output;
@@ -596,23 +597,23 @@ function tripal_feature_aggregator_page(){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_select_form(){
+function tripal_feature_aggregator_select_form() {
+
+  // get a list of base terms from chado for user to choose
+  $sql = "SELECT DISTINCT type_id FROM {tripal_feature_relagg} ORDER BY type_id ";
+  $results = db_query($sql);
 
-	// get a list of base terms from chado for user to choose
-	$sql = "SELECT DISTINCT type_id FROM {tripal_feature_relagg} ORDER BY type_id ";
-	$results = db_query ($sql);
-   
    $sql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d";
    $previous_db = tripal_db_set_active('chado');
-	$types = array();
+  $types = array();
    $types[] = '';
-   while($base = db_fetch_object($results)){
-      $term = db_fetch_object(db_query($sql,$base->type_id));
-		$types[$base->type_id] = $term->name;
+   while ($base = db_fetch_object($results)) {
+      $term = db_fetch_object(db_query($sql, $base->type_id));
+    $types[$base->type_id] = $term->name;
    }
    tripal_db_set_active($previous_db);
 
-	$form['type_id'] = array(
+  $form['type_id'] = array(
       '#title' => t('Aggregator Base Type'),
       '#type' => 'select',
       '#options' => $types,
@@ -623,7 +624,7 @@ function tripal_feature_aggregator_select_form(){
          'event' => 'change',
          'method' => 'replace',
       ),
-	);
+  );
 
    return $form;
 }
@@ -633,28 +634,29 @@ function tripal_feature_aggregator_select_form(){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_form(&$form_state = NULL,$type_id = NULL){
+function tripal_feature_aggregator_form(&$form_state = NULL, $type_id = NULL) {
 
    // get this requested database
-   if($type_id){
+   if ($type_id) {
       $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
       $tsql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d ";
 
       // get the default list of terms
-      $results = db_query($sql,$type_id);
-      while($type = db_fetch_object($results)){
+      $results = db_query($sql, $type_id);
+      while ($type = db_fetch_object($results)) {
          $previous_db = tripal_db_set_active('chado');
-         $term = db_fetch_object(db_query($tsql,$type->rel_type_id));
+         $term = db_fetch_object(db_query($tsql, $type->rel_type_id));
          tripal_db_set_active($previous_db);
          $default_others .= $term->name . " ";
       }
-      $default_base = $base->name;     
+      $default_base = $base->name;
       $action = 'Update';
       $form['type_id'] = array(
          '#type' => 'hidden',
          '#value' => $type_id
       );
-   } else {
+   }
+   else {
       $action = 'Add';
       $form['base']= array(
          '#type'          => 'textfield',
@@ -674,22 +676,23 @@ function tripal_feature_aggregator_form(&$form_state = NULL,$type_id = NULL){
       '#required'      => TRUE,
       '#weight'        => 2
    );
- 
-   if(strcmp($action,'Update')==0){
-      $form['update'] = array (
+
+   if (strcmp($action, 'Update')==0) {
+      $form['update'] = array(
         '#type'         => 'submit',
         '#value'        => t('Update'),
         '#weight'       => 5,
         '#executes_submit_callback' => TRUE,
       );
-      $form['delete'] = array (
+      $form['delete'] = array(
         '#type'         => 'submit',
         '#value'        => t('Delete'),
         '#weight'       => 6,
         '#executes_submit_callback' => TRUE,
       );
-   } else {
-      $form['add'] = array (
+   }
+   else {
+      $form['add'] = array(
         '#type'         => 'submit',
         '#value'        => t('Add'),
         '#weight'       => 5,
@@ -707,49 +710,49 @@ function tripal_feature_aggregator_form(&$form_state = NULL,$type_id = NULL){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_form_validate($form, &$form_state){
+function tripal_feature_aggregator_form_validate($form, &$form_state) {
    $type_id  = $form_state['values']['type_id'];
    $base     = $form_state['values']['base'];
    $others   = $form_state['values']['others'];
    $op      =  $form_state['values']['op'];
 
    // split apart the feature types to be aggregated
-   $types = preg_split('/\s+/',$others);
+   $types = preg_split('/\s+/', $others);
 
    // the SQL for finding the term
    $tsql = "
-      SELECT * 
-      FROM {cvterm} CVT 
-         INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id 
+      SELECT *
+      FROM {cvterm} CVT
+         INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
       WHERE CVT.name = '%s' and CV.name = 'sequence'";
 
 
    // make sure the base type exists
-   if($base){
+   if ($base) {
       $previous_db = tripal_db_set_active('chado');
-      $term = db_fetch_object(db_query($tsql,$base));
+      $term = db_fetch_object(db_query($tsql, $base));
       tripal_db_set_active($previous_db);
-      if(!$term){
-         form_set_error('base',t('The specified base type is not a valid SO term'));
+      if (!$term) {
+         form_set_error('base', t('The specified base type is not a valid SO term'));
       }
 
       // make sure this type doesn't already in the table
       $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
-      $agg = db_fetch_object(db_query($sql,$term->cvterm_id));
-      if($agg){
-         form_set_error('base',t('The specified base type is already used as a base type for another aggregator and cannot be readded.'));
-      }      
+      $agg = db_fetch_object(db_query($sql, $term->cvterm_id));
+      if ($agg) {
+         form_set_error('base', t('The specified base type is already used as a base type for another aggregator and cannot be readded.'));
+      }
    }
 
    // iterate through each type to be aggregated and make sure they are valid
-   foreach($types as $type){
+   foreach ($types as $type) {
       $previous_db = tripal_db_set_active('chado');
-      $term = db_fetch_object(db_query($tsql,$type));
+      $term = db_fetch_object(db_query($tsql, $type));
       tripal_db_set_active($previous_db);
-      if(!$term){
-         form_set_error('others',t('The specified type ') . $type . t(' is not a valid SO term'));
+      if (!$term) {
+         form_set_error('others', t('The specified type ') . $type . t(' is not a valid SO term'));
       }
-   }   
+   }
 }
 
 /**
@@ -757,7 +760,7 @@ function tripal_feature_aggregator_form_validate($form, &$form_state){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_form_submit($form, &$form_state){
+function tripal_feature_aggregator_form_submit($form, &$form_state) {
 
    $type_id  = $form_state['values']['type_id'];
    $base     = $form_state['values']['base'];
@@ -765,13 +768,13 @@ function tripal_feature_aggregator_form_submit($form, &$form_state){
    $op      =  $form_state['values']['op'];
 
    // split apart the feature types to be aggregated
-   $types = preg_split('/\s+/',$others);
+   $types = preg_split('/\s+/', $others);
 
    // the SQL for finding the term
    $tsql = "
-      SELECT * 
-      FROM {cvterm} CVT 
-         INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id 
+      SELECT *
+      FROM {cvterm} CVT
+         INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
       WHERE CVT.name = '%s' and CV.name = 'sequence'";
 
    // the SQL for deleting an aggregator
@@ -782,43 +785,44 @@ function tripal_feature_aggregator_form_submit($form, &$form_state){
 
    // if this is an insert then we have a base type name.  We
    // need to get the corresponding term id
-   if($base){
+   if ($base) {
       $previous_db = tripal_db_set_active('chado');
-      $term = db_fetch_object(db_query($tsql,$base));
+      $term = db_fetch_object(db_query($tsql, $base));
       tripal_db_set_active($previous_db);
       $type_id = $term->cvterm_id;
    }
 
-   if(strcmp($op,'Delete')==0){
-      $result = db_query($dsql,$type_id);
-      if($result){
+   if (strcmp($op, 'Delete')==0) {
+      $result = db_query($dsql, $type_id);
+      if ($result) {
         drupal_set_message("Aggregator deleted");
-      } else {
+      }
+      else {
         drupal_set_message("Failed to delete mailing list.");
       }
    }
    else {
       // for an update, first remove all the current aggregator settings
       // and we'll add them again
-      $result = db_query($dsql,$type_id);
+      $result = db_query($dsql, $type_id);
 
       // the SQL for inserting the aggregated types
       $isql = "
          INSERT INTO {tripal_feature_relagg}
           (type_id,rel_type_id)
-         VALUES 
+         VALUES
           (%d,%d)
       ";
 
       // iterate through each type to be aggregated and add an entry in the table
-      foreach($types as $type){
+      foreach ($types as $type) {
          $previous_db = tripal_db_set_active('chado');
-         $term = db_fetch_object(db_query($tsql,$type));
+         $term = db_fetch_object(db_query($tsql, $type));
          tripal_db_set_active($previous_db);
-         $result = db_query($isql,$type_id,$term->cvterm_id);
+         $result = db_query($isql, $type_id, $term->cvterm_id);
       }
       drupal_set_message("Aggregator added");
-   } 
+   }
    return '';
 }
 
@@ -827,9 +831,9 @@ function tripal_feature_aggregator_form_submit($form, &$form_state){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_aggregator_ajax_edit (){ 
+function tripal_feature_aggregator_ajax_edit() {
    // get the database id, build the form and then return the JSON object
    $type_id = $_POST['type_id'];
-   $form = drupal_get_form('tripal_feature_aggregator_form',$type_id);
+   $form = drupal_get_form('tripal_feature_aggregator_form', $type_id);
    drupal_json(array('status' => TRUE, 'data' => $form));
 }

+ 96 - 105
tripal_feature/tripal_feature.api.inc

@@ -1,5 +1,5 @@
 <?php
- 
+
 /**
  * Implements hook_chado_feature_schema()
  * Purpose: To add descriptions and foreign keys to default table description
@@ -21,21 +21,21 @@ function tripal_feature_chado_feature_schema() {
           'organism_id' => 'organism_id',
         ),
   );
-  
+
   $description['foreign keys']['dbxref'] = array(
         'table' => 'dbxref',
         'columns' => array(
           'dbxref_id' => 'dbxref_id',
         ),
   );
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $referring_tables = array('analysisfeature',
     'element',
     'feature_cvterm',
@@ -80,14 +80,14 @@ function tripal_feature_chado_featureprop_schema() {
           'feature_id' => 'feature_id',
         ),
   );
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $referring_tables = array('analysisfeature',
     'featureprop_pub',
   );
@@ -118,7 +118,7 @@ function tripal_feature_chado_featureloc_schema() {
           'srcfeature_id' => 'feature_id'
         ),
   );
-  
+
   $referring_tables = array('analysisfeature',
     'featureloc_pub',
   );
@@ -264,12 +264,12 @@ function tripal_feature_chado_feature_synonym_schema() {
  *    The feature ID for the analysis feature. This argument is optional but
  *    if specified it must also be accompanied with an analysis ID.
  * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is 
- *    optional and can be used rather than specifying the $analysis_id and 
+ *    The analysis feature ID for the analysis feature. This argument is
+ *    optional and can be used rather than specifying the $analysis_id and
  *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the 
+ *    an $analysis_id, $feature_id and $analysisfeature_id, then the
  *    $analysisfeature_id is used and the other two arguments are ignored.
- * @param $property 
+ * @param $property
  *    The cvterm name of the properties to retrieve
  * @param $cv_name
  *    Optional.  The name of the cv to which the property belongs.  By
@@ -280,28 +280,27 @@ function tripal_feature_chado_feature_synonym_schema() {
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_analysis_get_property($analysis_id = NULL ,$feature_id = NUll, 
-   $analysisfeature_id = NULL, $property, $cv_name = 'tripal')
-{
-   
+function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
+   $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
+
    // check that the incoming arguments are correct
-   if(($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)){
-       watchdog('tripal_feature', 
-          'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified', 
-           array(), WATCHDOG_WARNING);       
+   if (($analysis_id and !$feature_id) or
+       (!$analysis_id and $feature_id)) {
+       watchdog('tripal_feature',
+          'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
+           array(), WATCHDOG_WARNING);
    }
 
    // get the analysisfeature_id if one is not provided
-   if(!$analysisfeature_id){
+   if (!$analysisfeature_id) {
       $columns = array('analysisfeature_id');
       $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature',$columns,$values);
+      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
       $analysisfeature_id = $result[0]->analysisfeature_id;
    }
 
    // get the property.
-   return tripal_core_get_property('analysisfeature',$analysisfeature_id,$property,$cv_name);
+   return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
 }
 
 /**
@@ -314,10 +313,10 @@ function tripal_feature_analysis_get_property($analysis_id = NULL ,$feature_id =
  *    The feature ID for the analysis feature. This argument is optional but
  *    if specified it must also be accompanied with an analysis ID.
  * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is 
- *    optional and can be used rather than specifying the $analysis_id and 
+ *    The analysis feature ID for the analysis feature. This argument is
+ *    optional and can be used rather than specifying the $analysis_id and
  *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the 
+ *    an $analysis_id, $feature_id and $analysisfeature_id, then the
  *    $analysisfeature_id is used and the other two arguments are ignored.
  * @param $property
  *   The cvterm name of the property to insert
@@ -335,35 +334,34 @@ function tripal_feature_analysis_get_property($analysis_id = NULL ,$feature_id =
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
-   $analysisfeature_id = NULL, $property, $value, $update_if_present = 0, 
-   $cv_name = 'tripal')
-{
-   
+   $analysisfeature_id = NULL, $property, $value, $update_if_present = 0,
+   $cv_name = 'tripal') {
+
    // check that the incoming arguments are correct
-   if(($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)){
-       watchdog('tripal_feature', 
-          'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified', 
-           array(), WATCHDOG_WARNING);       
+   if (($analysis_id and !$feature_id) or
+       (!$analysis_id and $feature_id)) {
+       watchdog('tripal_feature',
+          'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
+           array(), WATCHDOG_WARNING);
    }
 
    // get the analysisfeature_id if one is not provided
-   if(!$analysisfeature_id){
+   if (!$analysisfeature_id) {
       $columns = array('analysisfeature_id');
       $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature',$columns,$values);
+      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
       $analysisfeature_id = $result[0]->analysisfeature_id;
    }
 
    // insert the property.
-   return tripal_core_insert_property('analysisfeature',$analysisfeature_id,
-      $property,$cv_name,$value,$update_if_present);
+   return tripal_core_insert_property('analysisfeature', $analysisfeature_id,
+      $property, $cv_name, $value, $update_if_present);
 }
 
 /**
  * Update an analysis feature property using the property name. Use this
  * when a property only exists once for a given analysis feature.  When more
- * than one value can exist for the same property use the 
+ * than one value can exist for the same property use the
  * tripal_feature_analysis_update_property_by_id() function.
  *
  * @param $analysis_id
@@ -373,16 +371,16 @@ function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_i
  *    The feature ID for the analysis feature. This argument is optional but
  *    if specified it must also be accompanied with an analysis ID.
  * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is 
- *    optional and can be used rather than specifying the $analysis_id and 
+ *    The analysis feature ID for the analysis feature. This argument is
+ *    optional and can be used rather than specifying the $analysis_id and
  *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the 
+ *    an $analysis_id, $feature_id and $analysisfeature_id, then the
  *    $analysisfeature_id is used and the other two arguments are ignored.
  * @param $property
  *   The cvterm name of the property to update
  * @param $value
  *   The value of the property to update
- * @param $insert_if_missing 
+ * @param $insert_if_missing
  *   A boolean indicated whether to insert the record if it's absent
  * @param $cv_name
  *    Optional.  The name of the cv to which the property belongs.  By
@@ -396,36 +394,35 @@ function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_i
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll, 
-   $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0, 
-   $cv_name = 'tripal')
-{
-  
+function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
+   $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
+   $cv_name = 'tripal') {
+
    // check that the incoming arguments are correct
-   if(($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)){
-       watchdog('tripal_feature', 
-          'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified', 
-           array(), WATCHDOG_WARNING);       
+   if (($analysis_id and !$feature_id) or
+       (!$analysis_id and $feature_id)) {
+       watchdog('tripal_feature',
+          'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
+           array(), WATCHDOG_WARNING);
    }
 
    // get the analysisfeature_id if one is not provided
-   if(!$analysisfeature_id){
+   if (!$analysisfeature_id) {
       $columns = array('analysisfeature_id');
       $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature',$columns,$values);
+      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
       $analysisfeature_id = $result[0]->analysisfeature_id;
    }
 
    // update the property.
-   return tripal_core_update_property('analysisfeature',$analysisfeature_id,$property,$cv_name,$value, $insert_if_missing);
+   return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
 }
 
 /**
  * Update a property for an analysis feature using the analysisfeatureprop_id.
  *
  * @param $analysisfeatureprop_id
- *    The analysis feature property ID for the analysis feature. 
+ *    The analysis feature property ID for the analysis feature.
  * @param $property
  *   The cvterm name of the property
  * @param $value
@@ -439,17 +436,17 @@ function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_i
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id, 
-   $property, $value, $cv_name = 'tripal')
-{  
+function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
+   $property, $value, $cv_name = 'tripal') {
+
    // update the property.
    return tripal_core_update_property_by_id('analysisfeature',
-      $analysisfeatureprop_id,$property,$cv_name,$value);
+      $analysisfeatureprop_id, $property, $cv_name, $value);
 }
 /**
  * Delete an analysis feature property using the property name.  Use this
  * when a property only exists once for a given analysis feature.  When more
- * than one value can exist for the same property use the 
+ * than one value can exist for the same property use the
  * tripal_feature_analysis_delete_property_by_id() function.
  *
  * @param $analysis_id
@@ -459,10 +456,10 @@ function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  *    The feature ID for the analysis feature. This argument is optional but
  *    if specified it must also be accompanied with an analysis ID.
  * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is 
- *    optional and can be used rather than specifying the $analysis_id and 
+ *    The analysis feature ID for the analysis feature. This argument is
+ *    optional and can be used rather than specifying the $analysis_id and
  *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the 
+ *    an $analysis_id, $feature_id and $analysisfeature_id, then the
  *    $analysisfeature_id is used and the other two arguments are ignored.
  * @param $property
  *    The cvterm name of the property to delete
@@ -474,47 +471,45 @@ function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  * and then it will be deleted
  *
  * @return
- *   True of success, False otherwise 
+ *   True of success, False otherwise
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll, 
-   $analysisfeature_id = NULL, $property, $cv_name = 'tripal')
-{
+function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
+   $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
    // check that the incoming arguments are correct
-   if(($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)){
-       watchdog('tripal_feature', 
-          'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified', 
-           array(), WATCHDOG_WARNING);       
+   if (($analysis_id and !$feature_id) or
+       (!$analysis_id and $feature_id)) {
+       watchdog('tripal_feature',
+          'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
+           array(), WATCHDOG_WARNING);
    }
 
    // get the analysisfeature_id if one is not provided
-   if(!$analysisfeature_id){
+   if (!$analysisfeature_id) {
       $columns = array('analysisfeature_id');
       $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature',$columns,$values);
+      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
       $analysisfeature_id = $result[0]->analysisfeature_id;
    }
 
-   // get the property.   
-   return tripal_core_delete_property('analysisfeature',$analysisfeature_id,$property,$cv_name);
+   // get the property.
+   return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
 }
 /**
  * Delete a property using the analysisfeatureprop_id
  *
  * @param $analysisfeatureprop_id
- *    The analysis feature property ID for the analysis feature. 
+ *    The analysis feature property ID for the analysis feature.
  *
  * @return
- *   True of success, False otherwise 
+ *   True of success, False otherwise
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id)
-{
-   // get the property.   
-   return tripal_core_delete_property_by_id('analysisfeature',$analysisfeatureprop_id);
+function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
+   // get the property.
+   return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
 }
 /**
  * Retrieve properties of a given type for a given feature
@@ -532,9 +527,8 @@ function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id)
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_get_property($feature_id,$property,$cv_name='tripal')
-{
-   return tripal_core_get_property('feature',$feature_id,$property,$cv_name);
+function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
+   return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
 }
 
 /**
@@ -558,8 +552,7 @@ function tripal_feature_get_property($feature_id,$property,$cv_name='tripal')
  * @ingroup tripal_feature_api
  */
 function tripal_feature_insert_property($feature_id, $property, $value,
-   $update_if_present = 0, $cv_name = 'tripal')
-{
+   $update_if_present = 0, $cv_name = 'tripal') {
     return tripal_core_insert_property('feature', $feature_id, $property,
        $cv_name, $value, $update_if_present);
 }
@@ -573,7 +566,7 @@ function tripal_feature_insert_property($feature_id, $property, $value,
  *   The cvterm name of the property to update
  * @param $value
  *   The value of the property to update
- * @param $insert_if_missing 
+ * @param $insert_if_missing
  *   A boolean indicated whether to insert the record if it's absent
  * @param $cv_name
  *   Optional.  The name of the cv to which the property belongs.  By
@@ -587,10 +580,9 @@ function tripal_feature_insert_property($feature_id, $property, $value,
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_update_property($feature_id, $property, 
-  $value, $insert_if_missing = 0, $cv_name = 'tripal')
-{
-   return tripal_core_update_property('feature',$feature_id,$property,$cv_name,$value, $insert_if_missing);
+function tripal_feature_update_property($feature_id, $property,
+  $value, $insert_if_missing = 0, $cv_name = 'tripal') {
+   return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
 }
 
 /**
@@ -611,10 +603,9 @@ function tripal_feature_update_property($feature_id, $property,
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_update_property_by_id($featureprop_id, $property, 
-  $value, $cv_name = 'tripal')
-{
-   return tripal_core_update_property_by_id('feature',$featureprop_id,$property,$cv_name,$value);
+function tripal_feature_update_property_by_id($featureprop_id, $property,
+  $value, $cv_name = 'tripal') {
+   return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
 }
 
 /**
@@ -633,12 +624,12 @@ function tripal_feature_update_property_by_id($featureprop_id, $property,
  * and then it will be deleted
  *
  * @return
- *   True of success, False otherwise 
+ *   True of success, False otherwise
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_delete_property($feature_id,$property,$cv_name='tripal'){
-   return tripal_core_delete_property('feature',$feature_id,$property,$cv_name);
+function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
+   return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
 }
 /**
  * Delete a given feature property using the featureprop_id
@@ -647,10 +638,10 @@ function tripal_feature_delete_property($feature_id,$property,$cv_name='tripal')
  *   The feature_id of the property to delete
  *
  * @return
- *   True of success, False otherwise 
+ *   True of success, False otherwise
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_delete_property_by_id($featureprop_id){
-   return tripal_core_delete_property_by_id('feature',$featureprop_id);
+function tripal_feature_delete_property_by_id($featureprop_id) {
+   return tripal_core_delete_property_by_id('feature', $featureprop_id);
 }

+ 29 - 29
tripal_feature/tripal_feature.install

@@ -5,14 +5,14 @@
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_install(){
+function tripal_feature_install() {
    // create the module's data directory
    tripal_create_moddir('tripal_feature');
 
-   // create the tables that correlate drupal nodes with chado 
+   // create the tables that correlate drupal nodes with chado
    // features, organisms, etc....
    drupal_install_schema('tripal_feature');
-  
+
    // add the materialized view
    tripal_feature_add_organism_count_mview();
 
@@ -23,13 +23,13 @@ function tripal_feature_install(){
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_update_6000(){
+function tripal_feature_update_6000() {
    // recreate the materialized view
    tripal_feature_add_organism_count_mview();
    $ret = array(
       '#finished' => 1,
    );
-   
+
    return $ret;
 }
 
@@ -37,25 +37,25 @@ function tripal_feature_update_6000(){
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_update_6300(){
+function tripal_feature_update_6300() {
    // add the relationship aggregator table to the database
    $schema = tripal_feature_get_schemas('tripal_feature_relagg');
    $ret = array();
    db_create_table($ret, 'tripal_feature_relagg', $schema['tripal_feature_relagg']);
-   
+
    return $ret;
 }
 /**
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_add_organism_count_mview(){
+function tripal_feature_add_organism_count_mview() {
    $view_name = 'organism_feature_count';
 
    // Drop the MView table if it exists
    $mview_id = tripal_mviews_get_mview_id($view_name);
-   if($mview_id){
-      tripal_mviews_action("delete",$mview_id);
+   if ($mview_id) {
+      tripal_mviews_action("delete", $mview_id);
    }
 
    // Create the MView
@@ -75,12 +75,12 @@ function tripal_feature_add_organism_count_mview(){
       // columns for indexing
       'organism_id,cvterm_id,feature_type',
       // SQL statement to populate the view
-      'SELECT O.organism_id, O.genus, O.species, O.common_name, 
-          count(F.feature_id) as num_features, 
-          CVT.cvterm_id, CVT.name as feature_type 
-       FROM {Organism} O 
-          INNER JOIN Feature F           ON O.Organism_id = F.organism_id 
-          INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id 
+      'SELECT O.organism_id, O.genus, O.species, O.common_name,
+          count(F.feature_id) as num_features,
+          CVT.cvterm_id, CVT.name as feature_type
+       FROM {Organism} O
+          INNER JOIN Feature F           ON O.Organism_id = F.organism_id
+          INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id
        GROUP BY O.Organism_id, O.genus, O.species, O.common_name,
           CVT.cvterm_id, CVT.name',
       // special index
@@ -90,8 +90,8 @@ function tripal_feature_add_organism_count_mview(){
    // add a job to the job queue so this view gets updated automatically next
    // time the job facility is run
    $mview_id = tripal_mviews_get_mview_id($view_name);
-   if($mview_id){
-      tripal_mviews_action('update',$mview_id);
+   if ($mview_id) {
+      tripal_mviews_action('update', $mview_id);
    }
 }
 /**
@@ -108,19 +108,19 @@ function tripal_feature_schema() {
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_uninstall(){
+function tripal_feature_uninstall() {
 
    // Drop the MView table if it exists
    $mview_id = tripal_mviews_get_mview_id('organism_feature_count');
-   if($mview_id){
-      tripal_mviews_action("delete",$mview_id);
+   if ($mview_id) {
+      tripal_mviews_action("delete", $mview_id);
    }
 
    drupal_uninstall_schema('tripal_feature');
 
    // Get the list of nodes to remove
-   $sql_feature_id = "SELECT nid, vid ".
-                 "FROM {node} ".
+   $sql_feature_id = "SELECT nid, vid " .
+                 "FROM {node} " .
                  "WHERE type='chado_feature'";
    $result = db_query($sql_feature_id);
    while ($node = db_fetch_object($result)) {
@@ -130,35 +130,35 @@ function tripal_feature_uninstall(){
 
 /**
 * This function simply defines all tables needed for the module to work
-* correctly.  By putting the table definitions in a separate function we 
+* correctly.  By putting the table definitions in a separate function we
 * can easily provide the entire list for hook_install or individual
 * tables for an update.
 *
 * @ingroup tripal_feature
 */
-function tripal_feature_get_schemas ($table = NULL){  
+function tripal_feature_get_schemas($table = NULL) {
   $schema = array();
 
 
-  if(!$table or strcmp($table,'chado_feature')==0){
+  if (!$table or strcmp($table, 'chado_feature')==0) {
      $schema['chado_feature'] = array(
          'fields' => array(
             'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
             'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
             'feature_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-            'sync_date' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
+            'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
          ),
          'indexes' => array(
             'feature_id' => array('feature_id')
           ),
          'unique keys' => array(
-            'nid_vid' => array('nid','vid'),
+            'nid_vid' => array('nid', 'vid'),
             'vid' => array('vid')
          ),
          'primary key' => array('nid'),
      );
   }
-  if(!$table or strcmp($table,'tripal_feature_relagg')==0){
+  if (!$table or strcmp($table, 'tripal_feature_relagg')==0) {
      $schema['tripal_feature_relagg'] = array(
         'fields' => array(
            'type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),

+ 11 - 11
tripal_feature/tripal_feature.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal organism tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -15,7 +15,7 @@
  * @ingroup views
  * @ingroup tripal_feature
  */
- 
+
 /**
  * Implements hook_views_data()
  *
@@ -23,7 +23,7 @@
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -34,11 +34,11 @@ require_once('views/chado_feature.views.inc');
 require_once('views/misc_tables.views.inc');
 function tripal_feature_views_data()  {
   $data = array();
-  
+
   $data = array_merge($data, retrieve_feature_views_data());
   $data = array_merge($data, retrieve_chado_feature_views_data());
   $data = array_merge($data, retrieve_feature_misc_tables_views_data());
-  
+
   return $data;
 }
 
@@ -46,7 +46,7 @@ function tripal_feature_views_data()  {
  * Implements hook_views_handlers()
  *
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
@@ -74,7 +74,7 @@ function tripal_feature_views_handlers() {
  */
 function tripal_feature_views_data_alter(&$data) {
 
-  if( !(is_array($db_url) and array_key_exists('chado',$db_url)) ){
+  if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
 
     // Add featuer relationship to node
     $data['node']['feature_chado_nid'] = array(
@@ -92,16 +92,16 @@ function tripal_feature_views_data_alter(&$data) {
       ),
     );
   }
-  
+
 }
 
 /**
  *
  * @ingroup tripal_feature_views
  */
-function tripal_feature_views_default_views () {
+function tripal_feature_views_default_views() {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -431,6 +431,6 @@ function tripal_feature_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 27 - 27
tripal_feature/views/template.table_defn.views.inc

@@ -5,7 +5,7 @@
  *
  *   - Every instance of XXX should be replaced with the name of your table
  *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
+ *     then change $data['XXX']['table'] to $data['XXX']['table']['base']
  *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
  *   - Relationships between this table and others: YYY is the table you are trying to join to this
  *     one. You want to join a table to this one if this table contains a foreign key to the other
@@ -15,18 +15,18 @@
  *   - Create a field definition for each field in this table using the example fields already
  *     listed. Match the type of the database field to the field definition listed below.
  *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
+ *
+ *  NOTE: Creating the table definition file is not enough. You also need to call the
  *        retrieve_XXX_views_data() function from ../tripal_feature.views.inc:tripal_feature_views_data()
  *        by adding the following line:
  *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
+ *        to the function and including the file directly above the function (blow the function
  *        header by adding:
  *           require_once('views/XXX.views.inc');
  *
  *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
+ */
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -34,12 +34,12 @@
  *  with this module in:
  *  @see tripal_feature.views.inc --in tripal_feature_views_data()
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
 /*************************************************************************
- * Purpose: this function returns the portion of the data array 
+ * Purpose: this function returns the portion of the data array
  *   which describes the XXX table, it's fields and any joins between it and other tables
  * @see tripal_feature_views_data() --in tripal_feature.views.inc
  *
@@ -55,23 +55,23 @@
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
     $database = 'chado';
   }
-   
+
   //Basic table definition-----------------------------------
   $data['XXX']['table']['group'] = t('Chado XXX');
-  
+
   $data['XXX']['table'] = array(
     'field' => 'primary_id',
     'title' => t('Chado XXX'),
     'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
   );
-  if($database){
+  if ($database) {
      $data['XXX']['table']['database'] = $database;
   }
 
-  
+
   //Relationship Definitions---------------------------------
   //Join: YYY => XXX
   // Notice that this relationship tells the primary table to show it's fields to the
@@ -80,16 +80,16 @@
   $data['XXX']['table']['join']['YYY'] = array(
     'left_field' => 'foreign key in YYY table',
     'field' => 'primary key in XXX table',
-  );  
-  
+  );
+
   //Join: XXX => XY => YYY
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
+  // in the appropriate files (ie: for feature => library
   // describe in both feature.views.inc and library.views.inc)
   $data['XXX']['table']['join']['XY'] = array(
     'left_field' => 'matching XXX key in the XY table',
     'field' => 'primary key in XXX table',
-  );  
+  );
   $data['XXX']['table']['join']['YYY'] = array(
     'left_table' => 'XY',
     'left_field' => 'matching XXX key in the XY table',
@@ -99,9 +99,9 @@
     'left_field' => 'primary key in YYY table',
     'field' => 'matching YYY key in the XY table',
   );
-   
+
   //Table Field Definitions----------------------------------
-      
+
   //Field: XXX_id (primary key)
   $data['XXX']['field_name'] = array(
     'title' => t('XXX Primary Key'),
@@ -123,7 +123,7 @@
    * Remove this section when done
    */
 
-  //Field: plain_text_field (chado datatype)   
+  //Field: plain_text_field (chado datatype)
   $data['XXX']['plain_text_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -142,7 +142,7 @@
     ),
   );
 
-  //Field: numeric_field (chado datatype)   
+  //Field: numeric_field (chado datatype)
   $data['XXX']['numeric_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -158,7 +158,7 @@
     ),
   );
 
-  //Field: boolean_field (chado datatype)   
+  //Field: boolean_field (chado datatype)
   $data['XXX']['boolean_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -174,7 +174,7 @@
     ),
   );
 
-  //Field: unix_timestamp (chado datatype)   
+  //Field: unix_timestamp (chado datatype)
   $data['XXX']['unix_timestamp'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -190,7 +190,7 @@
     ),
   );
 
-  //Field: human_readable_date (chado datatype)   
+  //Field: human_readable_date (chado datatype)
   $data['XXX']['human_readable_date'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -202,10 +202,10 @@
       'handler' => 'views_handler_sort_date',
     ),
   );
-   
+
    /*
     * End of Example Field definitions
     */
-    
+
   return $data;
-}
+}