Browse Source

Fixed bug in chado_generate_var for adding the entity_id and also linking to the organism in the organism field

Stephen Ficklin 7 years ago
parent
commit
88eb993eba

+ 3 - 17
tripal_chado/api/tripal_chado.variables.api.inc

@@ -312,24 +312,10 @@ function chado_generate_var($table, $values, $base_options = array()) {
       // Check to see if the current record maps to an entity.  Because
       // multiple bundles can map to the same table we have to check
       // all bundles for this table.
- /*
-      $bundles = db_select('chado_bundle', 'cb');
-      $bundles->fields('tb', array('name'));
-      $bundles->join('tripal_bundle', 'tb', 'tb.id = cb.bundle_id');
-      $bundles->condition('cb.data_table', $table);
-      $bundles->execute();
-      foreach ($bundles as $bundle) {
-        $cbundle_table = chado_get_bundle_entity_table($bundle);
-        $record = $db_select($cbundle_table, 'ce')
-          ->fields('ce', 'entity_id')
-          ->condition('record_id', $object->{$table_primary_key})
-          ->execute()
-          ->fetchObject();
-        if ($record) {
-          $object->entity_id = $record->entity_id;
-        }
+      $entity_id = chado_get_record_entity_by_table($table, $object->{$table_primary_key});
+      if ($entity_id) {
+        $object->entity_id = $entity_id;
       }
-*/
 
       // remove any fields where criteria needs to be evalulated---------------------------------------
       // The fields to be removed can be populated by implementing either

+ 2 - 3
tripal_chado/includes/TripalFields/obi__organism/obi__organism.inc

@@ -114,9 +114,8 @@ class obi__organism extends ChadoField {
       $entity->{$field_name}['und'][0]['chado-' . $field_table . '__organism_id'] = $organism->organism_id;
 
       // Is there a published entity for this organism?
-      if (property_exists($entity->chado_record->$field_column, 'entity_id')) {
-        $fk_entity_id = $entity->chado_record->$field_column->entity_id;
-        $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $fk_entity_id;
+      if (property_exists($record->{$field_column}, 'entity_id')) {
+        $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
       }
     }
   }

+ 6 - 1
tripal_chado/includes/TripalFields/obi__organism/obi__organism_formatter.inc

@@ -14,6 +14,11 @@ class obi__organism_formatter extends ChadoFieldFormatter {
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
     if (count($items) > 0) {
       $content = $items[0]['value']['rdfs:label'];
+      $entity = isset($item['value']['entity']) ? $item['value']['entity'] : '';
+      if ($entity) {
+        list($entity_type, $entity_id) = explode(':', $entity);
+        $content = l(content, 'bio_data/' . $entity_id);
+      }
       if (array_key_exists('entity', $items[0]['value'])) {
         list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity']);
         $content = l(strip_tags($items[0]['value']['rdfs:label']), 'bio_data/' . $entity_id);
@@ -27,4 +32,4 @@ class obi__organism_formatter extends ChadoFieldFormatter {
       );
     }
   }
-}
+}