Explorar el Código

Merge pull request #365 from tripal/7.x-3.x-small_fixes

7.x 3.x small fixes
Bradford Condon hace 6 años
padre
commit
6579091d14

+ 7 - 1
tripal/api/tripal.entities.api.inc

@@ -645,6 +645,8 @@ function tripal_create_bundle_fields($bundle, $term) {
     $function = $module . '_bundle_fields_info';
     $temp = $function('TripalEntity', $bundle);
     if (is_array($temp)) {
+      // TODO: it would be good to check this array to make sure it follows
+      // protocol.  It would help identify potential errors.
       $info = array_merge($info, $temp);
     }
   }
@@ -680,7 +682,11 @@ function tripal_create_bundle_fields($bundle, $term) {
   foreach ($modules as $module) {
     $function = $module . '_bundle_instances_info';
     $temp = $function('TripalEntity', $bundle);
-    $info = array_merge($info, $temp);
+    if (is_array($temp)) {
+      // TODO: it would be good to check this array to make sure it follows
+      // protocol.  It would help identify potential errors.
+      $info = array_merge($info, $temp);
+    }
   }
 
   // Allow modules to alter which fields should be attached to content

+ 22 - 2
tripal_chado/api/tripal_chado.custom_tables.api.inc

@@ -86,8 +86,10 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_if_exist
 }
 
 /**
- * Add a new table to the Chado schema. This function is simply a wrapper for
- * the db_create_table() function of Drupal, but ensures the table is created
+ * Add a new table to the Chado schema. 
+ * 
+ * This function is simply a wrapper for  the db_create_table() function of 
+ * Drupal, but ensures the table is created
  * inside the Chado schema rather than the Drupal schema.  If the table already
  * exists then it will be dropped and recreated using the schema provided.
  * However, it will only drop a table if it exsits in the tripal_custom_tables
@@ -128,6 +130,24 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_if_exist
  */
 function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE,
     $mview_id = NULL, $redirect = TRUE) {
+  
+  if (!$table) {
+    tripal_report_error('trp_ctables', TRIPAL_ERROR, 
+      'Please provide a value for the $table argument to the chado_create_custom_table() function');
+    return FALSE;
+  }
+  if (!$schema) {
+    tripal_report_error('trp_ctables', TRIPAL_ERROR, 
+      'Please provide a value for the $schema argument to the chado_create_custom_table() function');
+    return FALSE;
+  }
+  if ($schema and !is_array($schema)) {
+    tripal_report_error('trp_ctables', TRIPAL_ERROR, 
+      'Please provide an array for the $schema argument to the chado_create_custom_table() function');
+    return FALSE;
+  }
+  // TODO: make sure the schema is valid by adding extra checks.
+  
 
   global $databases;
   $created = 0;

+ 2 - 2
tripal_chado/api/tripal_chado.schema.api.inc

@@ -531,8 +531,8 @@ function chado_get_schema($table) {
   // An API call we can call directly.  The only time this occurs is
   // during an upgrade of a major Drupal version and tripal_core is disabled.
   if ((!$table_arr or !is_array($table_arr)) and
-        function_exists('tripal_core_' . $hook_name)) {
-    $api_hook = "tripal_core_" . $hook_name;
+        function_exists('tripal_chado_' . $hook_name)) {
+    $api_hook = "tripal_chado_" . $hook_name;
     $table_arr = $api_hook();
   }
 

+ 1 - 1
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -142,7 +142,7 @@ class sbo__database_cross_reference extends ChadoField {
     $linker_table = $base_table . '_dbxref';
     $options = array('return_array' => 1);
     $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (count($record->$linker_table) > 0) {
+    if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
       $i = 0;
       foreach ($record->$linker_table as $index => $linker) {
         $dbxref = $linker->dbxref_id;

+ 9 - 11
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -122,23 +122,21 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
     $pager = $this->ajaxifyPager($pager, $entity);
     $page_items = array_chunk($rows, $items_per_page);
 
-    $content = '';
-    if ($total_pages > 1) {
-      if (count($rows) == 1) {
-        $content = 'There is ' . count($rows) . ' relationship.';
-      }
-      if (count($rows) > 1) {
-        $content = 'There are ' . count($rows) . ' relationships.';
-      }
+    $caption = '';
+    if ($total_records == 1) {
+      $caption = 'There is ' . count($rows) . ' relationship.';
+    }
+    else {
+      $caption = 'There are ' . count($rows) . ' relationships.';
     }
-    $content .= theme_table(array(
+    $content = theme_table(array(
       'header' => $headers,
       'rows' => count($rows) > 0 ? $page_items[$current_page] : array(),
       'attributes' => array(
-        'id' => 'sbo--relationship-table',
+        'class' => 'tripal-data-table',
       ),
       'sticky' => FALSE,
-      'caption' => '',
+      'caption' => $caption,
       'colgroups' => array(),
       'empty' => $settings['empty'],
     ));

+ 1 - 1
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -103,7 +103,7 @@ class schema__publication extends ChadoField {
       'return_array' => 1,
     );
     $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (count($record->$linker_table) > 0) {
+    if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
       $i = 0;
       foreach ($record->$linker_table as $index => $linker) {
         $pub = $linker->pub_id;

+ 7 - 4
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc

@@ -258,9 +258,11 @@ class sio__annotation extends ChadoField {
     $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
     $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
 
-    $vocabulary = chado_get_semweb_term('cvterm', 'cv_id');
-    $accession = chado_get_semweb_term('dbxref', 'accession');
-    $definition = chado_get_semweb_term('cvterm', 'definition');
+    $vocabulary = tripal_get_chado_semweb_term('cvterm', 'cv_id');
+    $accession = tripal_get_chado_semweb_term('dbxref', 'accession');
+    $definition = tripal_get_chado_semweb_term('cvterm', 'definition');
+    $name = tripal_get_chado_semweb_term('cvterm', 'name');
+
     if (array_key_exists('is_not', $schema['fields'])) {
       $negation = chado_get_semweb_term($field_table, 'is_not');
     }
@@ -307,6 +309,7 @@ class sio__annotation extends ChadoField {
         'value' => array(
           $vocabulary => $cvterm->dbxref_id->db_id->name,
           $accession => $cvterm->dbxref_id->accession,
+          $name => $cvterm->name,
           $definition => isset($cvterm->definition) ? $cvterm->definition : ''
         ),
         'chado-' . $field_table . '__' . $pkey => $linker->$pkey,
@@ -370,4 +373,4 @@ function chado_linker__cvterm_widget_form_ajax_callback($form, $form_state) {
 
 
   return $form[$field_name]['und'][$delta];
-}
+}

+ 8 - 5
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_formatter.inc

@@ -12,15 +12,17 @@ class sio__annotation_formatter extends ChadoFieldFormatter {
    * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-    $headers = array('Term', 'Definition');
+    $headers = array('Term', 'Name', 'Definition');
     $rows = array();
 
     $field_table = $this->instance['settings']['chado_table'];
     $schema = chado_get_schema($field_table);
 
-    $vocabulary_term = chado_get_semweb_term('cvterm', 'cv_id');
-    $accession_term = chado_get_semweb_term('dbxref', 'accession');
-    $definition_term = chado_get_semweb_term('cvterm', 'definition');
+    $vocabulary_term = tripal_get_chado_semweb_term('cvterm', 'cv_id');
+    $accession_term = tripal_get_chado_semweb_term('dbxref', 'accession');
+    $definition_term = tripal_get_chado_semweb_term('cvterm', 'definition');
+    $name_term = tripal_get_chado_semweb_term('cvterm', 'name');
+
     if (array_key_exists('is_not', $schema['fields'])) {
       $negation_term = chado_get_semweb_term($field_table, 'is_not');
     }
@@ -40,6 +42,7 @@ class sio__annotation_formatter extends ChadoFieldFormatter {
 
         $row = array(
           $accession,
+          $item['value'][$name_term],
           $item['value'][$definition_term],
         );
 
@@ -54,7 +57,7 @@ class sio__annotation_formatter extends ChadoFieldFormatter {
     }
 
     // Theme the results in a talbe.
-    $caption = 'This record is associated with the following annotations.';
+    $caption = 'This record has the following annotations.';
     $table = array(
       'header' => $headers,
       'rows' => $rows,

+ 6 - 1
tripal_chado/includes/TripalImporter/GFF3Importer.inc

@@ -565,7 +565,12 @@ class GFF3Importer extends TripalImporter {
         $strand = -1;
       }
       if (strcmp($phase, '.') == 0) {
-        $phase = '';
+        if ($type == 'CDS') {
+          $phase = '0';
+        }
+        else {
+          $phase = '';
+        }
       }
       if (array_key_exists($type, $cvterm_lookup)) {
         $cvterm = $cvterm_lookup[$type];