Просмотр исходного кода

Fixed bugs with relationship field

Stephen Ficklin 8 лет назад
Родитель
Сommit
68f3bb393c

+ 5 - 5
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -248,7 +248,7 @@ class sbo__relationship extends ChadoField {
         $subject_name = isset($relationship->$subject_id_key->name) ? $relationship->$subject_id_key->name : '';
         if (!$subject_name) {
           if ($relationship->tablename == 'organism_relationship') {
-            $subject_name = $relationship->$subject_id_key->genus . ' ' . $relationship->$subject_id_key->species; 
+            $subject_name = $relationship->$subject_id_key->genus . ' ' . $relationship->$subject_id_key->species;
           }
         }
         $subject_type =  isset($relationship->$subject_id_key->type_id) ? $relationship->$subject_id_key->type_id->name : ' ';
@@ -660,10 +660,10 @@ class sbo__relationship extends ChadoField {
       $subject_id_key = 'subject_project_id';
       $object_id_key = 'object_project_id';
     }
-    else if ($field_table == 'organism_relationship') {
-      $subject_id_key = 'subject_organism_id';
-      $object_id_key = 'object_organism_id';
-    }
+//     else if ($field_table == 'organism_relationship') {
+//       $subject_id_key = 'subject_organism_id';
+//       $object_id_key = 'object_organism_id';
+//     }
 
     foreach ($items as $delta => $item) {
       $subject_id = $item['chado-' . $field_table . '__' . $subject_id_key];

+ 12 - 10
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

@@ -75,10 +75,10 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       $subject_id_key = 'subject_project_id';
       $object_id_key = 'object_project_id';
     }
-    else if ($field_table == 'organism_relationship') {
-      $subject_id_key = 'subject_organism_id';
-      $object_id_key = 'object_organism_id';
-    }
+//     else if ($field_table == 'organism_relationship') {
+//       $subject_id_key = 'subject_organism_id';
+//       $object_id_key = 'object_organism_id';
+//     }
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
@@ -357,10 +357,10 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       $subject_id_key = 'subject_project_id';
       $object_id_key = 'object_project_id';
     }
-    else if ($field_table == 'organism_relationship') {
-      $subject_id_key = 'subject_organism_id';
-      $object_id_key = 'object_organism_id';
-    }
+//     else if ($field_table == 'organism_relationship') {
+//       $subject_id_key = 'subject_organism_id';
+//       $object_id_key = 'object_organism_id';
+//     }
 
     $voc_id = array_key_exists('vocabulary', $form_state['values'][$field_name][$langcode][$delta]) ? $form_state['values'][$field_name][$langcode][$delta]['vocabulary'] : '';
     $type_name = array_key_exists('type_name', $form_state['values'][$field_name][$langcode][$delta]) ? $form_state['values'][$field_name][$langcode][$delta]['type_name'] : '';
@@ -424,7 +424,7 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $subject_id_key] = $subject_id;
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $object_id_key] = $object_id;
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__type_id'] = $type_id;
-      if ($field_table == 'feature_relationship') {
+      if (array_key_exists('rank', $schema['fields'])) {
         $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__rank'] = $form_state['values'][$field_name][$langcode][$delta]['_weight'];
       }
     }
@@ -433,7 +433,9 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $object_id_key] = '';
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__type_id'] = '';
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__value'] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__rank'] = '';
+      if (array_key_exists('rank', $schema['fields'])) {
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__rank'] = '';
+      }
     }
   }
 

+ 1 - 1
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -42,7 +42,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
-
+dpm($field_vals);
   // First, write the record for the base table.  If we have a record id then
   // this is an update and we need to set the primary key.  If not, then this
   // is an insert and we need to set the type_id if the table supports it.

+ 10 - 7
tripal_chado/includes/tripal_chado.fields.inc

@@ -179,9 +179,11 @@ function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type
   $schema = chado_get_schema($table_name);
 
   // BASE TYPE_ID
-  // Exculde the type_id field on the organism table that will be handled
-  // by the infraspecific type field.
-  if (array_key_exists('type_id', $schema['fields']) and $table_name != 'organism') {
+  // Exclude the type_id field on base tables where content types are mapped
+  // by the type_id field or on the organism table where the type_id is mean
+  // as an infraspecific name type.
+  if (array_key_exists('type_id', $schema['fields']) and
+      $table_name != 'organism' and $type_field != 'type_id') {
     $field_name = 'schema__additional_type';
     $field_type = 'schema__additional_type';
     $info[$field_name] = array(
@@ -785,10 +787,11 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
   $schema = chado_get_schema($table_name);
 
   // BASE TYPE_ID
-  // Exculde the type_id field on the organism table that will be handled
-  // by the infraspecific type field.
-  if (array_key_exists('type_id', $schema['fields']) and $table_name != 'organism') {
-
+  // Exclude the type_id field on base tables where content types are mapped
+  // by the type_id field or on the organism table where the type_id is mean
+  // as an infraspecific name type.
+  if (array_key_exists('type_id', $schema['fields']) and
+      $table_name != 'organism' and $type_field != 'type_id') {
     $field_name = 'schema__additional_type';
     $is_required = FALSE;
     if (array_key_exists('not null', $schema['fields']['type_id']) and