Browse Source

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson 11 years ago
parent
commit
93b64de231

+ 2 - 1
tripal_analysis/includes/tripal_analysis.form.inc

@@ -17,7 +17,7 @@ function chado_analysis_form($node, &$form_state) {
   //    form elements and the form is being rebuilt
   //
   // set form field defaults
-  $analysis_id = null;
+  $analysis_id    = null;
   $analysisname   = '';
   $program        = '';
   $programversion = '';
@@ -581,6 +581,7 @@ function chado_analysis_validate($node, &$form_state) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_validate($node, &$form_state) {
+  // remove surrounding white-space on submitted values
   $node->analysisname = trim($node->analysisname);
   $node->description = trim($node->description);
   $node->program = trim($node->program);

+ 4 - 3
tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php

@@ -1,9 +1,10 @@
 <?php
 $analysis = $variables['node']->analysis;
-$analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.description');
-?>
+$analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.description'); ?>
+
 <div id="tripal_analysis-base-box" class="tripal_analysis-info-box tripal-info-box">
-  <div class="tripal_analysis-info-box-title tripal-info-box-title">Details</div><?php 
+  <div class="tripal_analysis-info-box-title tripal-info-box-title">Details</div>
+  <div class="tripal__analysis-info-box-desc tripal-info-box-desc"></div><?php 
     
   // the $headers array is an array of fields to use as the colum headers. 
   // additional documentation can be found here 

+ 10 - 6
tripal_analysis/tripal_analysis.module

@@ -151,7 +151,6 @@ function tripal_analysis_permission() {
 function tripal_analysis_theme($existing, $type, $theme, $path) {
   $core_path = drupal_get_path('module', 'tripal_core');
 
-  $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
   $items = array(
     'node__chado_analysis' => array(
       'template' => 'node--chado-generic',
@@ -298,11 +297,17 @@ function tripal_analysis_views_api() {
 
 
 
-/*
- *
-*/
+/**
+ * Implementation of hook_form_alter()
+ * 
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
 function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
   if ($form_id == "chado_analysis_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
   }
 }
 /**
@@ -593,8 +598,7 @@ function chado_analysis_load($nodes) {
     // build the analysis variable
     $values = array('analysis_id' => $analysis_id);
     $analysis = tripal_core_generate_chado_var('analysis', $values);
-
-
+    
     // add in the description field
     $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
     $nodes[$nid]->analysis = $analysis;

+ 8 - 2
tripal_contact/tripal_contact.module

@@ -685,10 +685,16 @@ function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
   $contact->all_relationships = $relationships;
 }
 
-/*
- *
+/**
+ * Implementation of hook_form_alter()
+ * 
+ * @param $form
+ * @param $form_state
+ * @param $form_id
  */
 function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
   if ($form_id == "chado_contact_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
   }
 }

+ 20 - 29
tripal_core/api/tripal_core_chado.api.inc

@@ -221,12 +221,9 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
   // get the table description
   $table_desc = tripal_core_get_chado_table_schema($table);
   if (empty($table_desc)) {
-    tripal_core_report_error(
-      'tripal_core',
-      TRIPAL_WARNING,
+    tripal_core_report_error('tripal_core', TRIPAL_WARNING,
       'tripal_core_chado_insert; There is no table description for !table_name',
-      array('!table_name' => $table),
-      array('print' => $print_errors)
+      array('!table_name' => $table), array('print' => $print_errors)
     );
   }
 
@@ -1127,9 +1124,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     // make sure the field is in the table description. If not then return an error
     // message
     if (!array_key_exists($field, $table_desc['fields'])) {
-      tripal_core_report_error(
-        'tripal_core',
-        TRIPAL_ERROR,
+      tripal_core_report_error('tripal_core', TRIPAL_ERROR,
         'tripal_core_chado_select: The field "%field" does not exist for the table "%table".  Cannot perform query. Values: %array',
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)),
         array('print' => $print_errors)
@@ -2143,9 +2138,7 @@ function chado_query($sql, $args = array()) {
 
   // Args should be an array
   if (!is_array($args)) {
-    tripal_core_report_error(
-      'tripal_core',
-      TRIPAL_ERROR,
+    tripal_core_report_error('tripal_core', TRIPAL_ERROR,
       'chado_query; Need to pass an array to chado_query, "%value" passed instead. Query: %query',
       array('%value' => $args, '%query' => $sql)
     );
@@ -2157,7 +2150,19 @@ function chado_query($sql, $args = array()) {
   if ($is_local) {
     $sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
     $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
-    $results = db_query($sql, $args);
+    
+    // the featureloc table has some indexes that use function that call other functions
+    // and those calls do not reference a schema, therefore, any tables with featureloc
+    // must automaticaly have the chado schema set as active to find 
+    if(preg_match('/chado.featureloc/i', $sql)) {
+      $previous_db = tripal_db_set_active('chado') ;
+      $results = db_query($sql, $args);
+      tripal_db_set_active($previous_db);
+    }
+    // for all other tables we should have everything in scope so just run the query
+    else {
+      $results = db_query($sql, $args);
+    }
   }
   // if Chado is not local to the Drupal database then we have to
   // switch to another database
@@ -2537,13 +2542,8 @@ function tripal_core_delete_property_by_id($basetable, $record_id) {
  * Start a transaction block. Ensures the use of a persistent chado connection
  */
 function tripal_db_start_transaction() {
-/*  $connection = tripal_db_persistent_chado();
-  if ($connection) {
-    chado_query("BEGIN");
-    return $connection;
-  }
-  return FALSE;
-*/
+  $transaction = db_transaction();
+  return $transaction;
 }
 
 /**
@@ -2557,15 +2557,6 @@ function tripal_db_set_savepoint_transaction($savepoint, $release = FALSE) {
   chado_query("SAVEPOINT :savepoint", array(':savepoint' => $savepoint));
 }
 
-/**
- * A simple function to commit a database transaction
- *
- * @return nothing
- */
-function tripal_db_commit_transaction() {
-  chado_query("COMMIT");
-}
-
 /**
  * Rollback changes.
  *
@@ -3096,7 +3087,7 @@ function tripal_db_set_active($dbname  = 'default') {
   $chado_exists = variable_get('chado_schema_exists', FALSE);
   if ($dbname ) {
     if ($dbname == 'chado') {
-      db_query('set search_path to chado');
+      db_query('set search_path to chado,public');
       return 'default';
     }
     else {

+ 1 - 1
tripal_core/theme/css/tripal.css

@@ -75,7 +75,7 @@ table.tripal-table-horz .tripal-table-odd-row {
 }
 
 .tripal-info-box-desc {
-  padding-bottom: 15px;
+  /* padding-bottom: 15px; */
 }
 /* hide the title when inside of a block on a panel */
 .pane-block .tripal-info-box-title {

+ 1 - 41
tripal_cv/api/tripal_cv.api.inc

@@ -736,7 +736,7 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
       return 0;
     } 
     $result = chado_query($cvtermsql, array(':accession' => $accession, ':name' => $dbname));
-    $cvterm = $result->fetchObject();   
+    $cvterm = $result->fetchObject();
   }
   // upate the cvterm
   elseif ($update) { 
@@ -763,46 +763,6 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
   return $cvterm;
 }
 
-
-/**
- * This function defines the custom tables that will be created 
- * in the chado schema.
- *
- * @ingroup tripal_cv_api
- */
-function tripal_cv_get_custom_tables($table = NULL) {
-
- if (!$table or strcmp($table, 'tripal_obo_temp')==0) {
-    $schema['tripal_obo_temp'] = array(
-      'table' => 'tripal_obo_temp',
-      'fields' => array(
-        'id' => array(
-          'type' => 'varchar',
-          'length' => '255',
-          'not null' => TRUE,
-        ),
-        'stanza' => array(
-          'type' => 'text',
-          'not null' => TRUE,
-        ),
-        'type' => array(
-          'type' => 'varchar',
-          'length' => '50',
-          'not null' => TRUE,
-        ),
-      ),
-      'indexes' => array(
-        'tripal_obo_temp_idx0' => array('id'),
-        'tripal_obo_temp_idx0' => array('type'),
-      ),
-      'unique keys' => array(
-        'tripal_obo_temp_uq0' => array('id'),
-      ),
-    );
-  }
-  return $schema;
-}
-
 /**
  * This function allows other modules to programatically
  * submit an ontology for loading into Chado.  This function

+ 49 - 45
tripal_cv/includes/obo_loader.inc

@@ -219,54 +219,58 @@ function tripal_cv_load_update_cvtermpath($newcvs, $jobid) {
  */
 function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
   
-  $header = array();
-    
-  // make sure our temporary table exists
-  $ret = array(); 
-  if (!chado_table_exists('tripal_obo_temp')) { 
-    $schema = tripal_cv_get_custom_tables('tripal_obo_temp');  
-    $success = tripal_core_create_custom_table('tripal_obo_temp', $schema['tripal_obo_temp']);
-    if (!$success) {
-      watchdog('T_obo_loader', "Cannot create temporary loading table", array(), WATCHDOG_ERROR); 
-      return;
-    } 
-  }
-  // empty the temp table
-  $sql = "DELETE FROM {tripal_obo_temp}";
-  chado_query($sql);
-
-  print "Step 1: Preloading File $file\n";  
-
-  // make sure we have an 'internal' and a '_global' database
-  if (!tripal_db_add_db('internal')) {
-    tripal_cv_obo_quiterror("Cannot add 'internal' database");
-  }
-  if (!tripal_db_add_db('_global')) {
-    tripal_cv_obo_quiterror("Cannot add '_global' database");
-  }
-
-  // parse the obo file
-  $default_db = tripal_cv_obo_parse($file, $header, $jobid);
-
-  // add the CV for this ontology to the database
-  $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
-  if (!$defaultcv) {
-    tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+  $transaction = db_transaction();
+  print "\nNOTE: Loading of this OBO file is performed using a database transaction. \n" .
+      "If the load fails or is terminated prematurely then the entire set of \n" .
+      "insertions/updates is rolled back and will not be found in the database\n\n";
+  try {
+    $header = array();
+      
+    // make sure our temporary table exists
+    $ret = array(); 
+  
+    // empty the temp table
+    $sql = "DELETE FROM {tripal_obo_temp}";
+    chado_query($sql);
+  
+    print "Step 1: Preloading File $file\n";  
+  
+    // make sure we have an 'internal' and a '_global' database
+    if (!tripal_db_add_db('internal')) {
+      tripal_cv_obo_quiterror("Cannot add 'internal' database");
+    }
+    if (!tripal_db_add_db('_global')) {
+      tripal_cv_obo_quiterror("Cannot add '_global' database");
+    }
+  
+    // parse the obo file
+    $default_db = tripal_cv_obo_parse($file, $header, $jobid);
+  
+    // add the CV for this ontology to the database
+    $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
+    if (!$defaultcv) {
+      tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+    }
+    $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
+  
+    // add any typedefs to the vocabulary first
+    print "\nStep 2: Loading type defs...\n"; 
+    tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid);
+  
+    // next add terms to the vocabulary
+    print "\nStep 3: Loading terms...\n";  
+    if (!tripal_cv_obo_process_terms($defaultcv, $jobid, $newcvs, $default_db)) {
+      tripal_cv_obo_quiterror('Cannot add terms from this ontology');
+    }
   }
-  $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
-
-  // add any typedefs to the vocabulary first
-  print "\nStep 2: Loading type defs...\n"; 
-  tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid);
-
-  // next add terms to the vocabulary
-  print "\nStep 3: Loading terms...\n";  
-  if (!tripal_cv_obo_process_terms($defaultcv, $jobid, $newcvs, $default_db)) {
-    tripal_cv_obo_quiterror('Cannot add terms from this ontology');
+  catch (Exception $e) {
+    print "\n"; // make sure we start errors on new line
+    watchdog_exception('T_obo_loader', $e);
+    $transaction->rollback();
+    print "FAILED: Rolling back database changes...\n";
+    return 0;
   }
 
-  // transaction is complete
-  tripal_db_commit_transaction();
   return;
 }
 

+ 38 - 1
tripal_cv/tripal_cv.install

@@ -49,8 +49,11 @@ function tripal_cv_install() {
   // add the cv_root_mview
   tripal_cv_add_cv_root_mview();
 
-  // create the tables that correlate OBO files/references with a chado CV
+  // add defaults to the tables that correlate OBO files/references with a chado CV
   tripal_cv_add_obo_defaults();
+  
+  // add the custom tables to Chado
+  tripal_cv_add_custom_tables();
 }
 /**
  * Implementation of hook_uninstall().
@@ -95,6 +98,7 @@ function tripal_cv_schema() {
     ),
     'primary key' => array('obo_id'),
   );
+  
 
   return $schema;
 }
@@ -170,3 +174,36 @@ function tripal_cv_add_obo_defaults() {
     db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
   }
 }
+
+/**
+ * 
+ */
+function tripal_cv_add_custom_tables() {
+  $schema = array(
+    'table' => 'tripal_obo_temp',
+    'fields' => array(
+      'id' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'stanza' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => '50',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_obo_temp_idx0' => array('id'),
+      'tripal_obo_temp_idx0' => array('type'),
+    ),
+    'unique keys' => array(
+      'tripal_obo_temp_uq0' => array('id'),
+    ),
+  );
+  tripal_core_create_custom_table('tripal_obo_temp', $schema, TRUE);
+}

+ 10 - 0
tripal_cv/tripal_cv.module

@@ -66,6 +66,7 @@ function tripal_cv_menu() {
     'weight' => 10
   );
 
+  // The OBO loader will be available in two places
   $items['admin/tripal/chado/tripal_cv/obo_loader'] = array(
     'title' => 'Load Ontology',
     'description' => 'Load an Ontology into chado as a controlled vocabulary.',
@@ -74,6 +75,15 @@ function tripal_cv_menu() {
     'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_CALLBACK,
   );
+  
+  $items['admin/tripal/loaders/obo_loader'] = array(
+    'title' => 'Load Ontology',
+    'description' => 'Load an Ontology into chado as a controlled vocabulary.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_obo_form'),
+    'access arguments' => array('administer controlled vocabularies'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
   /*
    * Menu for updating the cvtermpath

+ 0 - 45
tripal_feature/api/tripal_feature.api.inc

@@ -831,51 +831,6 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
   return $residues;
 }
 
-
-/**
- * This function defines the custom tables that will be created 
- * in the chado schema.
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_get_custom_tables($table = NULL) {
-
- if (!$table or strcmp($table, 'tripal_gff_temp')==0) {
-    $schema['tripal_gff_temp'] = array(
-      'table' => 'tripal_gff_temp',
-      'fields' => array(
-        'feature_id' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-        ),
-        'organism_id' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-        ),
-        'uniquename' => array(
-          'type' => 'text',
-          'not null' => TRUE,
-        ),
-        'type_name' => array(
-          'type' => 'varchar',
-          'length' => '1024',
-          'not null' => TRUE,
-        ),
-      ),
-      'indexes' => array(
-        'tripal_gff_temp_idx0' => array('feature_id'),
-        'tripal_gff_temp_idx0' => array('organism_id'),
-        'tripal_gff_temp_idx1' => array('uniquename'),
-      ),
-      'unique keys' => array(
-        'tripal_gff_temp_uq0' => array('feature_id'),
-        'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
-      ),
-    );
-  }
-  return $schema;
-}
-
 /**
  * Using the tripal_core_expand_chado_vars function to retrieve a set
  * of relationships can be very slow, especialy if there are many relationships

File diff suppressed because it is too large
+ 528 - 541
tripal_feature/includes/gff_loader.inc


+ 3 - 3
tripal_feature/includes/tripal_feature.admin.inc

@@ -538,9 +538,9 @@ function tripal_feature_set_taxonomy($node, $feature_id) {
   // get the cvterm and the organism for this feature
   $sql = "
     SELECT CVT.name AS cvname, O.genus, O.species
-    FROM {CVTerm} CVT
-      INNER JOIN {Feature} F on F.type_id = CVT.cvterm_id
-      INNER JOIN {Organism} O ON F.organism_id = O.organism_id
+    FROM {cvterm} CVT
+      INNER JOIN {feature} F on F.type_id = CVT.cvterm_id
+      INNER JOIN {organism} O ON F.organism_id = O.organism_id
     WHERE F.feature_id = :feature_id
   ";
   $feature = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();

+ 6 - 6
tripal_feature/includes/tripal_feature.sync_features.inc

@@ -144,12 +144,12 @@ function tripal_feature_set_urls($na = NULL, $job = NULL) {
   // are not Chado tables we must manually prepare them 
   $psql = "
     PREPARE del_url_alias_by_src (text) AS
-    DELETE FROM {url_alias} WHERE src = \$1
+    DELETE FROM {url_alias} WHERE source = \$1
   ";
   db_query($psql);
   $psql = "
     PREPARE ins_url_alias_nisrds (text, text) AS
-    INSERT INTO url_alias (src, dst) VALUES (\$1, \$2)
+    INSERT INTO url_alias (source, alias) VALUES (\$1, \$2)
   ";
   db_query($psql);
   
@@ -183,20 +183,20 @@ function tripal_feature_set_urls($na = NULL, $job = NULL) {
     }
     
     // remove any previous alias and then add the new one
-    $success = db_query("EXECUTE del_url_alias_by_src(:src)", array(':src' => $src));    
+    $success = db_query("EXECUTE del_url_alias_by_src(:source)", array(':source' => $src));    
     if (!$success) {
       db_query('DEALLOCATE "del_url_alias_by_src"');
       db_query('DEALLOCATE "ins_url_alias_nisrds"');
       db_query("ROLLBACK");
-      watchdog('trp-seturl', "Failed Removing URL Alias: %src", array('%src' => $src), WATCHDOG_ERROR);
+      watchdog('trp-seturl', "Failed Removing URL Alias: %source", array('%source' => $src), WATCHDOG_ERROR);
       return;
     }
-    $success = db_query("EXECUTE ins_url_alias_nisrds(:src, :dst)", array(':src' => $src, ':dst' => $dst));
+    $success = db_query("EXECUTE ins_url_alias_nisrds(:source, :alias)", array(':source' => $src, ':alias' => $dst));
     if (!$success) {
       db_query('DEALLOCATE "del_url_alias_by_src"');
       db_query('DEALLOCATE "ins_url_alias_nisrds"');
       db_query("ROLLBACK");
-      watchdog('trp-seturl', "Failed Adding URL Alias: %dst", array('%dst' => $dst), WATCHDOG_ERROR);
+      watchdog('trp-seturl', "Failed Adding URL Alias: %alias", array('%alias' => $dst), WATCHDOG_ERROR);
       return;
     }
 

+ 3 - 0
tripal_feature/theme/css/tripal_feature.css

@@ -2,6 +2,9 @@
 #tripal_feature-sequence-residues {
   background-color: #FFFFFF;
   font-family: monospace;
+  margin: 10px 0 0 0;
+  padding: 0px;
+  font-size: medium;
 }
 
 pre#tripal_feature-featureloc_sequence {

+ 104 - 42
tripal_feature/theme/tripal_feature/tripal_feature_base.tpl.php

@@ -1,47 +1,109 @@
 <?php
+$feature  = $variables['node']->feature;  ?>
 
-$feature  = $variables['node']->feature;
-
-?>
 <div id="tripal_feature-base-box" class="tripal_feature-info-box tripal-info-box">
-  <div class="tripal_feature-info-box-title tripal-info-box-title">Feature Details</div>
-  <div class="tripal_feature-info-box-desc tripal-info-box-desc"></div>
+  <div class="tripal_feature-info-box-title tripal-info-box-title">Details</div>
+  <div class="tripal_feature-info-box-desc tripal-info-box-desc"></div> <?php
+   
+  // the $headers array is an array of fields to use as the colum headers. 
+  // additional documentation can be found here 
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  // This table for the analysis has a vertical header (down the first column)
+  // so we do not provide headers here, but specify them in the $rows array below.
+  $headers = array();
+  
+  // the $rows array contains an array of rows where each row is an array
+  // of values for each column of the table in that row.  Additional documentation
+  // can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+  $rows = array();
+
+  // Name row
+  $rows[] = array(
+    array(
+      'data' => 'Name',
+      'header' => TRUE
+    ),
+    $feature->name
+  );
+  // Unique Name row
+  $rows[] = array(
+    array(
+      'data' => 'Unique Name',
+      'header' => TRUE
+    ),
+    $feature->uniquename
+  );
+  // Type row
+  $rows[] = array(
+    array(
+      'data' => 'Type',
+      'header' => TRUE
+    ),
+    $feature->type_id->name
+  );
+  // Organism row
+  if ($feature->organism_id->nid) {
+    $organism = l("<i>" . $feature->organism_id->genus . " " . $feature->organism_id->species . "</i> (" .$feature->organism_id->common_name .")", "node/".$feature->organism_id->nid, array('html' => TRUE));
+  } 
+  else {
+    $organism = $feature->organism_id->genus ." " . $feature->organism_id->species ." (" .$feature->organism_id->common_name .")";
+  }
+  $rows[] = array(
+    array(
+      'data' => 'Organism',
+      'header' => TRUE
+    ),
+    $organism
+  );
+  // Seqlen row
+  if($feature->seqlen > 0) {
+    $rows[] = array(
+      array(
+        'data' => 'Sequence length',
+        'header' => TRUE
+      ),
+      $feature->seqlen
+    );
+  }
+  // allow site admins to see the feature ID
+  if (user_access('access administration pages')) { 
+    // Feature ID
+    $rows[] = array(
+      array(
+        'data' => 'Feature ID',
+        'header' => TRUE
+      ),
+      $feature->feature_id
+    );
+  }
+  // Is Obsolete Row
+  if($feature->is_obsolete == TRUE){
+    $rows[] = array(
+      array(
+        'data' => '<div class="tripal_feature-obsolete">This feature is obsolete</div>',
+        'colspan' => 2
+      ),
+    );
+  }
 
-   <?php if(strcmp($feature->is_obsolete,'t')==0){ ?>
-      <div class="tripal_feature-obsolete">This feature is obsolete</div>
-   <?php }?>
-   <table id="tripal_feature-base-table" class="tripal_feature-table tripal-table tripal-table-vert">
-      <tr class="tripal_feature-table-even-row tripal-table-even-row">
-        <th>Name</th>
-        <td><?php print $feature->name; ?></td>
-      </tr>
-      <tr class="tripal_feature-table-odd-row tripal-table-odd-row">
-        <th nowrap>Unique Name</th>
-        <td><?php print $feature->uniquename; ?></td>
-      </tr>
-      <tr class="tripal_feature-table-even-row tripal-table-even-row">
-        <th>Internal ID</th>
-        <td><?php print $feature->feature_id; ?></td>
-      </tr>
-      <tr class="tripal_feature-table-odd-row tripal-table-odd-row">
-        <th>Type</th>
-        <td><?php print $feature->type_id->name; ?></td>
-      </tr>
-      <tr class="tripal_feature-table-even-row tripal-table-even-row">
-        <th>Organism</th>
-        <td>
-          <?php if ($feature->organism_id->nid) { 
-      	   print "<a href=\"".url("node/".$feature->organism_id->nid)."\">".$feature->organism_id->genus ." " . $feature->organism_id->species ." (" .$feature->organism_id->common_name .")</a>";      	 
-          } else { 
-            print $feature->organism_id->genus ." " . $feature->organism_id->species ." (" .$feature->organism_id->common_name .")";
-          } ?>
-        </td>
-     	</tr> <?php   
-     	if ($feature->seqlen) { ?>
-        <tr class="tripal_feature-table-odd-row tripal-table-odd-row">
-          <th>Length</th>
-          <td><?php print $feature->seqlen ?></td>
-        </tr> <?php 
-     	} ?>   	                                
-   </table>
+  // the $table array contains the headers and rows array as well as other
+  // options for controlling the display of the table.  Additional
+  // documentation can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_feature-table-base',
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  
+  // once we have our table array structure defined, we call Drupal's theme_table()
+  // function to generate the table.
+  print theme_table($table); ?>
 </div>

+ 15 - 7
tripal_feature/theme/tripal_feature/tripal_feature_sequence.tpl.php

@@ -1,18 +1,26 @@
 <?php
 $feature = $variables['node']->feature;
 
-// add the residues to the feature object.  Fields of type 'text' in Chado
-// are not automatically added, so we must add them manually
-$feature = tripal_core_expand_chado_vars($feature,'field','feature.residues');
+// we don't want to get the sequence for traditionally large types. They are
+// too big,  bog down the web browser, take longer to load and it's not
+// reasonable to print them on a page.
+$residues ='';
+if(strcmp($feature->type_id->name,'scaffold') !=0 and
+   strcmp($feature->type_id->name,'chromosome') !=0 and
+   strcmp($feature->type_id->name,'supercontig') !=0 and
+   strcmp($feature->type_id->name,'pseudomolecule') !=0) {
+  $feature = tripal_core_expand_chado_vars($feature,'field','feature.residues');
+  $residues = $feature->residues;
+} 
 
-if ($feature->residues) { ?>
+if ($residues) { ?>
   <div id="tripal_feature-sequence-box" class="tripal_feature-info-box tripal-info-box">
     <div class="tripal_feature-info-box-title tripal-info-box-title">Sequence</div>
     <div class="tripal_feature-info-box-desc tripal-info-box-desc">The sequence for this <?php print $feature->type_id->name; ?> </div>
     <pre id="tripal_feature-sequence-residues"><?php 
-      // format the sequence to break ever 100 residues
-      print ereg_replace("(.{60})","\\1<br>",$feature->residues); ?>  
+      // format the sequence to break every 100 residues
+      print preg_replace("/(.{50})/","\\1<br>",$feature->residues); ?>  
     </pre>
-  </div><?php
+  </div> <?php
 }
 

+ 39 - 19
tripal_feature/theme/tripal_feature/tripal_feature_synonyms.tpl.php

@@ -7,27 +7,47 @@ $options = array('return_array' => 1);
 $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_synonym', $options);
 $synonyms = $feature->feature_synonym;
 
-
 if(count($synonyms) > 0){ ?>
   <div id="tripal_feature-synonyms-box" class="tripal_feature-info-box tripal-info-box">
     <div class="tripal_feature-info-box-title tripal-info-box-title">Synonyms</div>
-    <div class="tripal_feature-info-box-desc tripal-info-box-desc">The feature '<?php print $feature->name ?>' has the following synonyms</div>
-
-    <table id="tripal_feature-synonyms-table" class="tripal_feature-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Synonym</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($synonyms as $feature_synonym){
-        $class = 'tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td><?php print $feature_synonym->synonym_id->name?></td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table>
+    <div class="tripal_feature-info-box-desc tripal-info-box-desc">The feature '<?php print $feature->name ?>' has the following synonyms</div><?php
+    
+    // the $headers array is an array of fields to use as the colum headers. 
+    // additional documentation can be found here 
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    // This table for the analysis has a vertical header (down the first column)
+    // so we do not provide headers here, but specify them in the $rows array below.
+    $headers = array('Synonym');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+    $rows = array();
+    foreach ($synonyms as $feature_synonym){
+      $rows[] = array(
+        $feature_synonym->synonym_id->name
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_feature-table-synonyms',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+      print theme_table($table); ?>
   </div><?php
 }

+ 42 - 0
tripal_feature/tripal_feature.install

@@ -53,6 +53,9 @@ function tripal_feature_install() {
   if ($mview_id = tripal_mviews_get_mview_id('organism_feature_count')) {
     tripal_mviews_action('update', $mview_id);
   }
+  
+  // add the custom tables to Chado
+  tripal_feature_add_custom_tables();
 }
 
 /**
@@ -180,4 +183,43 @@ function tripal_feature_add_organism_count_mview() {
   ";
 
   tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
+}
+
+/**
+ * 
+ */
+function tripal_feature_add_custom_tables() {
+  
+  $schema['tripal_gff_temp'] = array(
+    'table' => 'tripal_gff_temp',
+    'fields' => array(
+      'feature_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'organism_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'uniquename' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'type_name' => array(
+        'type' => 'varchar',
+        'length' => '1024',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_gff_temp_idx0' => array('feature_id'),
+      'tripal_gff_temp_idx0' => array('organism_id'),
+      'tripal_gff_temp_idx1' => array('uniquename'),
+    ),
+    'unique keys' => array(
+      'tripal_gff_temp_uq0' => array('feature_id'),
+      'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
+    ),
+  );
+  tripal_core_create_custom_table('tripal_gff_temp', $schema, TRUE);
 }

+ 123 - 302
tripal_feature/tripal_feature.module

@@ -20,6 +20,7 @@ require_once "includes/fasta_loader.inc";
 require_once "includes/gff_loader.inc";
 require_once "includes/seq_extract.inc";
 require_once "includes/tripal_feature-delete.inc";
+require_once "includes/tripal_feature.form.inc";
 
 /**
  *
@@ -206,7 +207,7 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
   $items['admin/tripal/chado/tripal_feature/sync'] = array(
-    'title' => ' Sync',
+    'title' => 'Sync',
     'description' => 'Sync features from Chado with Drupal',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_feature_sync_form'),
@@ -288,12 +289,14 @@ function tripal_feature_menu() {
  * @ingroup tripal_feature
  */
 function tripal_feature_theme($existing, $type, $theme, $path) {
-  return array(
-    'tripal_feature_search_index' => array(
-      'variables' => array('node'),
-    ),
-    'tripal_feature_search_results' => array(
-       'variables' => array('node'),
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
+  $items = array(
+    'node__chado_feature' => array(
+      'template' => 'node--chado-generic',
+      'render element' => 'node',
+      'base hook' => 'node',
+      'path' => "$core_path/theme",
     ),
     'tripal_organism_feature_browser' => array(
       'variables' => array('node' => NULL),
@@ -306,56 +309,64 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'path' => "$path/theme/tripal_organism",
     ),
     'tripal_feature_base' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_base',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_base',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_sequence' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_sequence',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_sequence',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_proteins' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_proteins',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_proteins',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_synonyms' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_synonyms',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_synonyms',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_phenotypes' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_phenotypes',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_phenotypes',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_featurepos' => array(
-       'arguments' => array('node' => NULL),
-       'template' => 'tripal_feature_featurepos',
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_feature_featurepos',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_featureloc_sequences' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_featureloc_sequences',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_featureloc_sequences',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_references' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_references',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_references',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_properties' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_properties',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_properties',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_terms' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_terms',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_terms',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_alignments' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_alignments',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_alignments',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_relationships' => array(
-       'variables' => array('node' => NULL),
-       'template' => 'tripal_feature_relationships',
-    ),
-    'tripal_feature_edit_ALL_properties_form' => array(
-      'arguments' => array('form' => NULL),
-      'function' => 'theme_tripal_feature_edit_ALL_properties_form',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_relationships',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_feature_help' => array(
       'template' => 'tripal_feature_help',
@@ -368,6 +379,8 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
        'arguments' => array('form'),
     )
   );
+  
+  return $items;
 }
 /**
  *
@@ -665,7 +678,8 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
   // remove any old synonyms
   $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = :feature_id";
   if (!chado_query($feature_syn_dsql, array(':feature_id' => $feature_id))) {
-    $error .= "Could not remove synonyms from feature. ";
+    watchdog('tripal_feature', "Could not remove synonyms from feature. ", array(), WATCHDOG_ERROR);
+    return;
   }
 
   // return if we don't have any synonmys to add
@@ -676,7 +690,8 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
   foreach ($syn_array as $syn) {
     // skip this item if it's empty
     if (!$syn) {
-    break; }
+      break; 
+    }
 
     // check to see if we have this accession number already in the database
     // if so then don't add it again. it messes up drupal if the insert fails.
@@ -688,13 +703,14 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
         INSERT INTO {synonym} (name, synonym_sgml, type_id)
         VALUES (:name, :synonym_sgml,
           (SELECT cvterm_id
-           FROM {CVTerm} CVT
-             INNER JOIN CV ON CVT.cv_id = CV.cv_id
+           FROM {cvterm} CVT
+             INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
            WHERE CV.name = 'feature_property' and CVT.name = 'synonym')
           )
       ";
       if (!chado_query($synonym_isql, array(':name' => $syn, ':synonym_sgml' => $syn))) {
-        $error .= "Could not add synonym. ";
+        watchdog('tripal_feature', "Could not add synonym. ", array(), WATCHDOG_WARNING);
+        return;
       }
       // now get the synonym we just added
       $synonym_sql = "SELECT synonym_id FROM {synonym} WHERE name = :name";
@@ -707,13 +723,10 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
       VALUES (:synonym_id, :feature_id, :pub_id)";
     $args = array(':synonym_id' => $synonym->synonym_id, ':feature_id' => $feature_id, ':pub_id'=> 1);
     if (!chado_query($feature_syn_isql, $args)) {
-      $error .= "Could not add synonyms to feature. ";
+      watchdog('tripal_feature', "Could not associate synonym with feature. ", array(), WATCHDOG_WARNING);
+      return;
     }
   }
-
-  // return to the drupal database
-  return $error;
-
 }
 /**
  *
@@ -773,265 +786,47 @@ function chado_feature_add_gbaccession($accession, $feature_id) {
   return $error;
 }
 
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function chado_feature_form($node, $param) {
-
-  $form = array();
-
-  $feature = $node->feature;
-
-  // add the residues to the feature object
-  $feature = tripal_core_expand_chado_vars($feature, 'field', 'feature.residues');
-
-  // if the node has synonyms then use that as the form may be returning
-  // from an error.  Otherwise try to find synonyms from the database
-  $synonyms = $node->synonyms;
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_synonym');
-  $feature_synonyms = $feature->feature_synonym;
-  if (!$synonyms) {
-    if (!is_array($feature_synonyms)) {
-      $synonyms = $feature_synonyms->synonym_id->name;
-    }
-    elseif (is_array($feature_synonyms)) {
-      foreach ($feature_synonyms as $index => $synonym) {
-        $synonyms .= $synonym->synonym_id->name . "\n";
-      }
-    }
-  }
-
-  $analyses = $node->analyses;
-  $references = $node->references;
-
-  // We need to pass above variables for preview to show
-  $form['feature'] = array(
-    '#type' => 'value',
-    '#value' => $feature
-  );
-  // This field is read when previewing a node
-  $form['synonyms'] = array(
-    '#type' => 'value',
-    '#value' => $synonyms
-  );
-  // This field is read when previewing a node
-  $form['analyses'] = array(
-    '#type' => 'value',
-    '#value' => $analyses
-  );
-  // This field is read when previewing a node
-  $form['references'] = array(
-    '#type' => 'value',
-    '#value' => $references
-  );
-
-  // keep track of the feature id if we have one.  If we do have one then
-  // this would indicate an update as opposed to an insert.
-  $form['feature_id'] = array(
-    '#type' => 'value',
-    '#value' => $feature->feature_id,
-  );
-
-  /*
-  $form['title']= array(
-    '#type' => 'textfield',
-    '#title' => t('Title'),
-    '#required' => TRUE,
-    '#default_value' => $node->title,
-    '#description' => t('The title must be a unique identifier for this feature.  It is recommended to use a combination of uniquename, organism and feature type in the title as this is guranteed to be unique.'),
-    '#maxlength' => 255
-  );*/
-
-  $form['uniquename']= array(
-    '#type' => 'textfield',
-    '#title' => t('Unique Feature Name'),
-    '#required' => TRUE,
-    '#default_value' => $feature->uniquename,
-    '#description' => t('Enter a unique name for this feature.  This name must be unique for the organism and feature type.'),
-    '#maxlength' => 255
-  );
-
-  $form['fname']= array(
-    '#type' => 'textfield',
-    '#title' => t('Feature Name'),
-    '#required' => TRUE,
-    '#default_value' => $feature->name,
-    '#description' => t('Enter the name used by humans to refer to this feature.'),
-    '#maxlength' => 255
-  );
-
-  // get the sequence ontology CV ID
-  $values = array('name' => 'sequence');
-  $cv = tripal_core_chado_select('cv', array('cv_id'), $values);
-  $cv_id = $cv[0]->cv_id;
-
-  $form['feature_type'] = array(
-   '#title'       => t('Feature Type'),
-   '#type'        => 'textfield',
-   '#description' => t("Choose the feature type."),
-   '#required'    => TRUE,
-   '#default_value' => $feature->type_id->name,
-   '#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
-  );
-
-  // get the list of organisms
-  $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
-  $org_rset = chado_query($sql);
-  $organisms = array();
-  $organisms[''] = '';
-  while ($organism = $org_rset->fetchObject()) {
-    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-  }
-  $form['organism_id'] = array(
-    '#title'       => t('Organism'),
-    '#type'        => t('select'),
-    '#description' => t("Choose the organism with which this feature is associated"),
-    '#required'    => TRUE,
-    '#default_value' => $feature->organism_id->organism_id,
-    '#options'     => $organisms,
-  );
-
-  // Get synonyms
-  if ($synonyms) {
-    if (is_array($synonyms)) {
-      foreach ($synonyms as $synonym) {
-        $syn_text .= "$synonym->name\n";
-      }
-    }
-    else {
-      $syn_text = $synonyms;
-    }
-  }
-  $form['synonyms']= array(
-    '#type' => 'textarea',
-    '#title' => t('Synonyms'),
-    '#required' => FALSE,
-    '#default_value' => $syn_text,
-    '#description' => t('Enter alternate names (synonmys) for this feature to help in searching and identification. You may enter as many alternate names as needed each on different lines.'),
-  );
-
-  $form['residues']= array(
-    '#type' => 'textarea',
-    '#title' => t('Residues'),
-    '#required' => FALSE,
-    '#default_value' => $feature->residues,
-    '#description' => t('Enter the nucelotide sequences for this feature'),
-  );
-
-  $checked = '';
-  if ($feature->is_obsolete == 't') {
-    $checked = '1';
-  }
-  $form['is_obsolete']= array(
-    '#type' => 'checkbox',
-    '#title' => t('Is Obsolete'),
-    '#required' => FALSE,
-    '#default_value' => $checked,
-    '#description' => t('Check this box if this sequence should be retired and no longer included in further analysis.'),
-  );
-  return $form;
-}
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function chado_feature_validate($node) {
-  $result = 0;
-
-  // make sure the feature type is a real sequence ontology term
-  $type = tripal_cv_get_cvterm_by_name($node->feature_type, NULL, 'sequence');
-  if (!$type) {
-    form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
-  }
 
-  // if this is an update, we want to make sure that a different feature for
-  // the organism doesn't already have this uniquename. We don't want to give
-  // two sequences the same uniquename
-  if ($node->feature_id) {
-    $sql = "
-      SELECT *
-      FROM {feature} F
-        INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
-      WHERE
-        F.uniquename     = :uname AND
-        F.organism_id    = :orgnism_id AND
-        CVT.name         = :cvtname AND
-        NOT f.feature_id = :feature_id
-    ";
-    $args = array(':uname' => $node->uniquename, ':organism_id' => $node->organism_id,
-      ':cvtname' => $node->feature_type, ':feature_id' => $node->feature_id);
-    $result = chado_query($sql, $args)->fetchObject();
-    if ($result) {
-      form_set_error('uniquename', t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature."));
-    }
-  }
-
-  // if this is an insert then we just need to make sure this name doesn't
-  // already exist for this organism if it does then we need to throw an error
-  else {
-    $sql = "
-      SELECT *
-      FROM {feature} F
-        INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
-      WHERE
-        F.uniquename  = :name AND
-        F.organism_id = :organism_id AND
-        CVT.name      = :cvtname
-    ";
-    $args = array(':name' => $node->uniquename, ':organism_id' => $node->organism_id, ':cvtname' => $node->feature_type);
-    $result = chado_query($sql, $args)->fetchObject();
-    if ($result) {
-      form_set_error('uniquename', t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature."));
-    }
-  }
-
-  // we don't allow a genbank accession number for a contig
-  if ($node->feature_type == 'contig' and $node->gbaccession) {
-    form_set_error('gbaccession', t("Contigs cannot have a genbank accession number.  Please change the feature type or remove the accession number"));
-  }
-}
 /**
  *  When a node is requested by the user this function is called to allow us
  *  to add auxiliary data to the node object.
  *
  * @ingroup tripal_feature
  */
-function chado_feature_load($node) {
-
-  // get the feature details from chado
-  $feature_id = chado_get_id_for_node('feature', $node->nid);
-
-  $values = array('feature_id' => $feature_id);
-  $feature = tripal_core_generate_chado_var('feature', $values);
-
-  // by default, the titles are saved using the unique constraint.  We will
-  // keep it the same, but remove the duplicate name if the unique name and name
-  // are identical
-  $title_type = variable_get('chado_feature_title', 'unique_constraint');
-  if ($title_type == 'unique_constraint') {
-    if (strcmp($feature->name, $feature->uniquename)==0) {
-      $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
+function chado_feature_load($nodes) {
+
+  foreach ($nodes as $nid => $node) {
+    // find the feature and add in the details
+    $feature_id = chado_get_id_for_node('feature', $nid);
+  
+    // build the feature variable
+    $values = array('feature_id' => $feature_id);
+    $feature = tripal_core_generate_chado_var('feature', $values);
+    $nodes[$nid]->feature = $feature;
+
+    // by default, the titles are saved using the unique constraint.  We will
+    // keep it the same, but remove the duplicate name if the unique name and name
+    // are identical. This doesn't change the title saved in the database, just what is shown
+    // to the user on the page
+    $title_type = variable_get('chado_feature_title', 'unique_constraint');
+    if ($title_type == 'unique_constraint') {
+      if (strcmp($feature->name, $feature->uniquename)==0) {
+        $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
+      }
+      // in previous version of Tripal, the feature title was simply the unique name.
+      // so, we recreate the title just to be sure all of our feature pages are consistent
+      else {
+        $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
+      }
     }
-    // in previous version of Tripal, the feature title was simply the unique name.
-    // so, we recreate the title just to be sure all of our feature pages are consistent
-    else {
-      $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
+    // set the title to be the feature name or uniquename as configured
+    if ($title_type == 'feature_name') {
+      $node->title = $feature->name;
+    }
+    if ($title_type == 'feature_unique_name') {
+      $node->title = $feature->uniquename;
     }
   }
-  // set the title to be the feature name or uniquename as configured
-  if ($title_type == 'feature_name') {
-    $node->title = $feature->name;
-  }
-  if ($title_type == 'feature_unique_name') {
-    $node->title = $feature->uniquename;
-  }
-
-  $additions = new stdClass();
-  $additions->feature = $feature;
-  return $additions;
 }
 /**
  *
@@ -1895,11 +1690,12 @@ function tripal_feature_node_insert($node) {
       }
 
       // remove any previous alias
-      db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => "node/$node->nid"));
+      db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
 
       // set the URL for this feature page
       $url_alias = tripal_feature_get_feature_url($node);
-      path_set_alias("node/$node->nid", $url_alias);
+      $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
+      path_save($path_alias);
       break;
   }
 }
@@ -1909,6 +1705,25 @@ function tripal_feature_node_insert($node) {
  */
 function tripal_feature_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {
+    case 'chado_feature':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_feature_base'] = array(
+          '#value' => theme('tripal_feature_base', array('node' => $node)),
+        );
+        $node->content['tripal_feature_seqence'] = array(
+          '#value' => theme('tripal_feature_sequence', array('node' => $node)),
+        );
+        $node->content['tripal_feature_synonyms'] = array(
+          '#value' => theme('tripal_feature_synonyms', array('node' => $node)),
+        );
+      }
+      if ($view_mode == 'teaser') {
+        $node->content['tripal_feature_teaser'] = array(
+          '#value' => theme('tripal_feature_teaser', array('node' => $node)),
+        );
+      }
+      break;
     case 'chado_organism':
       // Show feature browser and counts
       if ($view_mode == 'full') {
@@ -1939,11 +1754,12 @@ function tripal_feature_node_update($node) {
   switch ($node->type) {
     case 'chado_feature':
       // remove any previous alias
-      db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => "node/$node->nid"));
+      db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
 
       // set the URL for this feature page
       $url_alias = tripal_feature_get_feature_url($node);
-      path_set_alias("node/$node->nid", $url_alias);
+      $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
+      path_save($path_alias);
       break;
   }
 }
@@ -2411,10 +2227,11 @@ function tripal_feature_match_features_page($id) {
 }
 
 /**
- *
- * @param unknown_type $form
- * @param unknown_type $form_state
- * @param unknown_type $form_id
+ * Implementation of hook_form_alter()
+ * 
+ * @param $form
+ * @param $form_state
+ * @param $form_id
  */
 function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == "tripal_feature_seq_extract_form") {
@@ -2423,4 +2240,8 @@ function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
     // to the normal form URL
     $form['#action'] = url("find/sequences");
   }
+  // turn off preview button for insert/updates
+  if ($form_id == "chado_feature_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
 }

+ 14 - 0
tripal_featuremap/tripal_featuremap.module

@@ -667,3 +667,17 @@ function chado_featuremap_delete(&$node) {
   chado_query("DELETE FROM {featuremap} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
   chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
 }
+
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_featuremap_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
+}

+ 13 - 0
tripal_library/tripal_library.module

@@ -748,3 +748,16 @@ function chado_library_delete(&$node) {
 }
 
 
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_library_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_library_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
+}

+ 34 - 22
tripal_organism/tripal_organism.module

@@ -199,6 +199,18 @@ function tripal_organism_theme($existing, $type, $theme, $path) {
   );
   return $items;
 }
+/**
+ * 
+ * @param $node
+ */
+function tripal_organism_node_presave($node) {
+  switch ($node->type) {
+    case 'chado_organism':
+      // set the title for the node
+      $node->title = "$node->genus $node->species";
+      break;
+  }
+}
 /**
  *
  * @ingroup tripal_feature
@@ -217,7 +229,7 @@ function tripal_organism_node_view($node, $view_mode, $langcode) {
           '#value' => theme('tripal_organism_teaser', array('node' => $node)),
         );
       }
-  	  break;
+      break;
   }
 }
 /**
@@ -262,7 +274,7 @@ function tripal_organism_permission() {
  */
 function tripal_organism_views_api() {
   return array(
-    'api' => 3.0,
+    'api' => 2.0,
   );
 }
 /**
@@ -433,13 +445,6 @@ function chado_organism_insert($node) {
     drupal_write_record('chado_organism', $record);
   }
 
-  // set the title for the node
-  $record = new stdClass();
-  $record->title = "$node->genus $node->species";
-  $record->nid = $node->nid;
-  drupal_write_record('node', $record, 'nid');
-  drupal_write_record('node_revisions', $record, 'nid');
-
   // add the image
   chado_organism_add_image($node);
 }
@@ -472,13 +477,6 @@ function chado_organism_update($node) {
   );
   $org_status = tripal_core_chado_update('organism', $match, $values);
 
-  // set the title for the node
-  $record = new stdClass();
-  $record->title = "$node->genus $node->species";
-  $record->nid = $node->nid;
-  drupal_write_record('node', $record, 'nid');
-  drupal_write_record('node_revisions', $record, 'nid');
-
   // add the image
   chado_organism_add_image($node);
 }
@@ -595,12 +593,6 @@ function chado_organism_form($node, $form_state) {
     $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
   }
 
-  $form['abbreviation']= array(
-    '#type' => 'textfield',
-    '#title' => t('Abbreviation'),
-    '#required' => TRUE,
-    '#default_value' => $abbreviation,
-  );
   $form['genus']= array(
     '#type' => 'textfield',
     '#title' => t('Genus'),
@@ -613,6 +605,12 @@ function chado_organism_form($node, $form_state) {
     '#required' => TRUE,
     '#default_value' => $species,
   );
+  $form['abbreviation']= array(
+    '#type' => 'textfield',
+    '#title' => t('Abbreviation'),
+    '#required' => TRUE,
+    '#default_value' => $abbreviation,
+  );
   $form['common_name']= array(
     '#type' => 'textfield',
     '#title' => t('Common Name'),
@@ -656,3 +654,17 @@ function chado_organism_load($nodes) {
     $nodes[$nid]->organism = $organism;
   }
 }
+
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_organism_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
+}

+ 13 - 0
tripal_project/tripal_project.module

@@ -596,4 +596,17 @@ function tripal_project_preprocess_tripal_project_relationships(&$variables) {
 
   $project->all_relationships = $relationships;
 
+}
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_project_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_project_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
 }

+ 2 - 1
tripal_pub/includes/tripal_pub.admin.inc

@@ -262,7 +262,8 @@ function tripal_pub_set_pub_url($node, $pub_id) {
   // remove any previous alias
   db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => $node_url));
   // add the new alias
-  path_set_alias($node_url, $url_alias);
+  $path_alias = array("source" => $node_url, "alias" => $url_alias);
+  path_save($path_alias);
 
   return $url_alias;
 }

+ 14 - 0
tripal_pub/tripal_pub.module

@@ -999,3 +999,17 @@ function tripal_pub_node_update($node) {
     tripal_pub_set_pub_url($node, $pub_id);
   }
 }
+
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_pub_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
+}

+ 18 - 2
tripal_stock/tripal_stock.module

@@ -1155,7 +1155,8 @@ function tripal_stock_node_insert($node) {
 
       // set the URL for this stock page
       $url_alias = tripal_stock_get_stock_url($node);
-      path_set_alias("node/$node->nid", $url_alias);
+      $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
+      path_save($path_alias);
       break;
   }
 }
@@ -1172,7 +1173,8 @@ function tripal_stock_node_update($node) {
 
       // set the URL for this stock page
       $url_alias = tripal_stock_get_stock_url($node);
-      path_set_alias("node/$node->nid", $url_alias);
+      $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
+      path_save($path_alias);
       break;
   }
 }
@@ -1262,4 +1264,18 @@ function tripal_stock_match_stocks_page($id) {
   $output = "<p>The following stocks match the name '$id'.</p>";
   $output .= theme_table($header, $rows, $table_attrs, $caption);
   return $output;
+}
+
+/**
+ * Implementation of hook_form_alter()
+ *
+ * @param $form
+ * @param $form_state
+ * @param $form_id
+ */
+function tripal_stock_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
+  if ($form_id == "chado_stock_node_form") {
+    $form['actions']['preview']['#access'] = FALSE;
+  }
 }

Some files were not shown because too many files changed in this diff