Browse Source

Fixed issues with some fields

Stephen Ficklin 8 years ago
parent
commit
ab0561996c

+ 1 - 1
tripal_chado/includes/TripalFields/local__source_data/local__source_data_formatter.inc

@@ -22,7 +22,7 @@ class local__source_data_formatter extends ChadoFieldFormatter {
            <dt>Source Version</dt>
            <dd>: " . $items[0]['value']['IAO:0000129'] . " </dd>
            <dt>Source URI</dt>
-           <dd>: " . $items[0]['value']['data:1047'] . " </dd>
+           <dd>: " . l($items[0]['value']['data:1047'], $items[0]['value']['data:1047'], array('attributes' => array('target' => '_blank'))) . " </dd>
         </dl>
       ";
     }

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

@@ -12,7 +12,7 @@ class sbo__database_cross_reference extends ChadoField {
   // --------------------------------------------------------------------------
 
   // The default lable for this field.
-  public static $default_label = 'Database cross reference';
+  public static $default_label = 'Cross reference';
 
   // The default description for this field.
   public static $description = 'This record can be cross referenced with a record in
@@ -80,7 +80,7 @@ class sbo__database_cross_reference extends ChadoField {
       'value' => array(
         /* sub elements that may be present in the values array
         // Database name
-        'data:1056' => '',
+        'data:1048' => '',
         // Accession
         'data:2091' => '',
         'schema:url' => '',
@@ -113,7 +113,7 @@ class sbo__database_cross_reference extends ChadoField {
         $URL = tripal_get_dbxref_url($dbxref);
         $entity->{$field_name}['und'][$i] = array(
           'value' => array(
-            'data:1056' => $dbxref->db_id->name,
+            'data:1048' => $dbxref->db_id->name,
             'data:2091' => $dbxref->accession,
             'schema:url' => $URL,
           ),
@@ -216,4 +216,4 @@ class sbo__database_cross_reference extends ChadoField {
       }
     }
   }
-}
+}

+ 2 - 2
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc

@@ -2,7 +2,7 @@
 
 class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
   // The default lable for this field.
-  public static $default_label = 'Database cross reference';
+  public static $default_label = 'Cross reference';
 
   // The list of field types for which this formatter is appropriate.
   public static $field_types = array('sbo__database_cross_reference');
@@ -26,7 +26,7 @@ class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
       if (!$item['value']) {
         continue;
       }
-      $content = $item['value']['data:1056'] . ':' . $item['value']['data:2091'];
+      $content = $item['value']['data:1048'] . ':' . $item['value']['data:2091'];
       if ($item['value']['schema:url']) {
         $content = l($content, $item['value']['schema:url'], array('attributes' => array('target' => '_blank')));
       }

+ 20 - 5
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -2,7 +2,7 @@
 
 class sbo__database_cross_reference_widget extends ChadoFieldWidget {
   // The default lable for this field.
-  public static $default_label = 'Database cross reference';
+  public static $default_label = 'Cross reference';
 
   // The list of field types for which this formatter is appropriate.
   public static $field_types = array('sbo__database_cross_reference');
@@ -165,10 +165,24 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
     $version = isset($form_state['values'][$field_name][$langcode][$delta]['version']) ? $form_state['values'][$field_name][$langcode][$delta]['version'] : '';
     $description = isset($form_state['values'][$field_name][$langcode][$delta]['description']) ? $form_state['values'][$field_name][$langcode][$delta]['description'] : '';
 
+
     // If the dbxref_id does not match the db_id + accession then the user
     // has selected a new dbxref record and we need to update the hidden
     // value accordingly.
     if ($db_id and $accession) {
+      // If the dbxref doesn't exist then let's add it.
+      $values = array(
+        'db_id' => $db_id,
+        'accession' => $accession,
+      );
+      $options = array('is_duplicate' => TRUE);
+      $has_duplicate = chado_select_record('dbxref', array('*'), $values, $options);
+      if (!$has_duplicate) {
+        tripal_insert_dbxref(array(
+          'db_id' => $db_id,
+          'accession' => $accession,
+        ));
+      }
       $dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
       if ($dbxref and $dbxref->dbxref_id != $dbxref_id) {
         $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__dbxref_id'] = $dbxref->dbxref_id;
@@ -182,6 +196,7 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__dbxref_id'] = '';
     }
+
   }
 
   /**
@@ -222,11 +237,11 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
  */
 function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_state) {
 
-  $instance = $form['#instance'];
   $field_name = $form_state['triggering_element']['#parents'][0];
   $delta = $form_state['triggering_element']['#parents'][2];
   $field = field_info_field($field_name);
   $field_type = $field['type'];
+  $instance = $form[$field_name]['und'][$delta]['#instance'];
   $field_table = $instance['settings']['chado_table'];
   $field_column = $instance['settings']['chado_column'];
   $field_prefix = 'chado-' . $field_table . '__dbxref_id';
@@ -234,7 +249,7 @@ function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_st
   // Check to see if this dbxref already exists. If not then
   // give a notice to the user that the dbxref will be added.
   $db_id = $form_state['values'][$field_name]['und'][$delta]['db_id'];
-  $db_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
+  $accession = $form_state['values'][$field_name]['und'][$delta]['accession'];
   if ($db_id and $accession) {
     $values = array(
       'db_id' => $db_id,
@@ -243,9 +258,9 @@ function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_st
     $options = array('is_duplicate' => TRUE);
     $has_duplicate = chado_select_record('dbxref', array('*'), $values, $options);
     if (!$has_duplicate) {
-      drupal_set_message('The selected cross reference is new and will be added for future auto completions.');
+      drupal_set_message('The selected cross reference is new and will be added.');
     }
   }
 
   return $form[$field_name]['und'][$delta];
-}
+}

+ 7 - 0
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -30,6 +30,10 @@ class schema__publication_formatter extends ChadoFieldFormatter {
       if ($entity) {
         list($entity_type, $entity_id) = explode(':', $entity);
         $new_title = l($title, 'bio_data/' . $entity_id);
+        // If a title has parens we need to escape them for the
+        // regular expression to work.
+        $title = preg_replace('/\(/', '\(', $title);
+        $title = preg_replace('/\)/', '\)', $title);
         $citation = preg_replace("/$title/", $new_title, $citation);
       }
       $list_items[] = $citation;
@@ -47,6 +51,9 @@ class schema__publication_formatter extends ChadoFieldFormatter {
       );
       $list = theme_item_list($list);
     }
+    else {
+      $list = $list_items[0];
+    }
     $element[0] = array(
       '#type' => 'markup',
       '#markup' => $list,

+ 2 - 2
tripal_chado/includes/TripalFields/sio__references/sio__references.inc

@@ -73,7 +73,7 @@ class sio__references extends ChadoField {
     );
 
     // Iterate through all of the _pub tables and look for any that have
-    // linked to this record. If os then add them.
+    // linked to this record. If so then add them.
     $chado_tables = chado_get_table_names(TRUE);
     $delta = 0;
     foreach ($chado_tables as $chado_table) {
@@ -148,4 +148,4 @@ class sio__references extends ChadoField {
     }
   }
 
-}
+}