Преглед изворни кода

Added a chado_linker_featurepos field. Fixed bugs for chado_linker_cvterm_adder that checks for duplicate fields

Chun-Huai Cheng пре 8 година
родитељ
комит
f6867f2a15

+ 16 - 0
tripal/includes/TripalEntity.inc

@@ -114,6 +114,7 @@ class chado_linker__cvterm extends TripalField {
     $fkey_value = $element['#entity']->chado_record_id;
     $cvterm_name = '';
     $cvterm_id = '';
+    $title = '';
     $is_not = '';
     $cvterm = NULL;
 
@@ -122,6 +123,7 @@ class chado_linker__cvterm extends TripalField {
     if (array_key_exists($delta, $items)) {
       $record_id = $items[$delta]['value'];
       $cvterm_name = $items[$delta]['cvterm__name'];
+      $title =$items[$delta]['pub'];
       $is_not = $items[$delta]['chado-' . $table_name . '__is_not'];
       $cvterm_id = $items[$delta]['chado-' . $table_name . '__cvterm_id'];
     }
@@ -184,6 +186,20 @@ class chado_linker__cvterm extends TripalField {
         'method' => 'replace'
       ),
     );
+    
+    $widget['pub'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Publication'),
+      '#default_value' => $title,
+      '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/pub',
+      '#ajax' => array(
+        'callback' => "chado_linker__pub_widget_form_ajax_callback",
+        'wrapper' => "$table_name-$delta",
+        'effect' => 'fade',
+        'method' => 'replace'
+      ),
+      '#maxlength' => 100000,
+    );
 
     $widget['chado-' . $table_name . '__is_not'] = array(
       '#type' => 'checkbox',

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

@@ -145,7 +145,7 @@ class chado_linker__cvterm_adder extends TripalField {
           $pkey = $schema['primary key'][0];
 
           // Add the field if it doesn't already exists.
-          $field = field_info_field('cvterm');
+          $field = field_info_field($type_field_name);
           if (!$field) {
             $create_info = array(
               'field_name' => $type_field_name,
@@ -167,7 +167,7 @@ class chado_linker__cvterm_adder extends TripalField {
           // Attach the field to the bundle if it isn't already.
           if (!$field or !array_key_exists('bundles', $field) or
               !array_key_exists('TripalEntity', $field['bundles']) or
-              !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
+              !in_array($bundle, $field['bundles']['TripalEntity'])) {
                 $createInstanceInfo = array(
                   'field_name' => $type_field_name,
                   'entity_type' => 'TripalEntity',

+ 24 - 9
tripal_chado/includes/TripalFields/chado_linker__featurepos.inc

@@ -50,23 +50,20 @@ class chado_linker__featurepos extends TripalField {
     $settings = $display['settings'];
 
     $rows = array();
-    $headers = array('Map', 'Mapped Feature', 'Name', 'Position');
+    $headers = array('Map', 'Mapped Feature', 'Position');
 
     foreach ($items as $delta => $item) {
       if (!$item['value']) {
         continue;
       }
-
       $val = $item['value'];
       $map_name = $val['map_name'];
       $mapped_feature_name = $val['mapped_feature_name'];
-      $feature_name = $val['name'];
       $position = $val['position'];
 
       $rows[] = array(
         $map_name, 
         $mapped_feature_name,
-        $feature_name,
         $position
       );
     }
@@ -86,7 +83,7 @@ class chado_linker__featurepos extends TripalField {
       'sticky' => FALSE,
       'caption' => '',
       'colgroups' => array(),
-      'empty' => 'This record is not aligned to any locations.',
+      'empty' => 'This record is not found on any map.',
     );
 
     // once we have our table array structure defined, we call Drupal's theme_table()
@@ -127,10 +124,28 @@ class chado_linker__featurepos extends TripalField {
     );
     $feature = chado_expand_var($record, 'table', 'featurepos', $options);
 
-     // iterate through the results and add them to our featureposes array
-     $featureposes = array();
-     return $featureposes;
-   }
+    // iterate through the results and add them to our featureposes array
+    $featureposes = array();
+    if (isset($feature->featurepos->feature_id)) {
+       foreach ($feature->featurepos->feature_id AS $featurepos) {
+         $featuremap_id = $featurepos->featuremap_id;
+         $featuremap = chado_generate_var('featuremap', array('featuremap_id' => $featuremap_id));
+         $map_feature_id = $featurepos->map_feature_id;
+         $map_feature = chado_generate_var('feature', array('feature_id' => $map_feature_id));
+         $mappos = $featurepos->mappos;
+         $featureposes [] = array (
+           'map_name' => $featuremap->name,
+           'mapped_feature_name' => $map_feature->name,
+           'position' => $mappos
+         );
+      }
+    }
+    $i = 0;
+    foreach ($featureposes as $position) {
+      $entity->{$field_name}['und'][$i]['value'] = $position;
+      $i++;
+    }
+  }
 
   /**
    * We don't want a widget so override this function.

+ 53 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -448,6 +448,29 @@ function tripal_chado_create_tripalfields_linker(&$info, $details, $entity_type,
       ),
     );
   }
+  
+  // FEATUREPOS
+  if ($table_name == 'feature') {
+    $schema = chado_get_schema('featurepos');
+    $pkey = $schema['primary key'][0];
+    $field_name = 'featurepos';
+    $field_type = 'chado_linker__featurepos';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+      'settings' => array(
+        'chado_table' => 'featurepos',
+        'chado_column' => $pkey,
+        'base_table' => 'feature',
+        'semantic_web' => 'SO:position_of',
+      ),
+    );
+  }
   // GENOTYPE
   $genotype_table = $table_name . '_genotype';
   if (chado_table_exists($genotype_table)) {
@@ -1197,6 +1220,36 @@ function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $
       ),
     );
   }
+  
+  // FEATUREPOS
+  if ($table_name == 'feature') {
+    $field_name = 'featurepos';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Map Positions',
+      'description' => 'The positions on a genetic map.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => FALSE,
+      ),
+      'widget' => array(
+        'type' => 'chado_linker__featurepos_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'chado_linker__featurepos_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
+  
   // GENOTYPE
   $genotype_table = $table_name . '_genotype';
   if (chado_table_exists($genotype_table)) {

+ 2 - 1
tripal_chado/theme/css/tripal_chado.css

@@ -5,7 +5,8 @@
 .secondary-dbxref-widget-item,
 .kvproperty-adder-widget-item,
 .chado-linker--relationship-widget-item,
-.chado-linker--relationship-instance-settings-option2-item {
+.chado-linker--relationship-instance-settings-option2-item,
+.annotation-cvterm-widget {
    float: left;
    margin-right: 10px;
 }