Browse Source

Fix for sbo__relationship field Issue #1159

dsenalik 4 years ago
parent
commit
e0163f72f9

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

@@ -438,15 +438,17 @@ class sbo__relationship extends ChadoField {
     // Example: The genetic_marker, MARKER1 , derives from the sequence_variant, VARIANT1.
     // The above relationship will be shown both on marker and variant pages
     // and as such both subject and object names need to be shown.
-    $clause = 'The ' . $subject_type . ', ' .
-      $subject_name . ', ' . $verb . ' ' . $rel_type_clean . ' ' .
-      $object_type . ', ' . $object_name . '.';
+    // Keep the clause as an array for now so we can apply formatting
+    // and links in the formatter
+    $clause = [ 'The ', $subject_type, ', ', $subject_name, ', ',
+                $verb, ' ', $rel_type_clean, ' ', $object_type,
+                ', ', $object_name, '.' ];
     $entity->{$field_name}['und'][$delta]['value']['SIO:000493'] = $clause;
 
     // Adding a label allows us to provide a single text value for the
     // entire field. It is this text value that can be used in tab/csv
     // downloaders.
-    $entity->{$field_name}['und'][$delta]['value']['rdfs:label'] = $clause;
+    $entity->{$field_name}['und'][$delta]['value']['rdfs:label'] = implode('', $clause);
 
     $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
     $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;
@@ -524,7 +526,7 @@ class sbo__relationship extends ChadoField {
       // relationship type and the object and subject
       'include_fk' => [
         'type_id' => 1,
-          $object_id_key => [
+        $object_id_key => [
           'type_id' => 1,
           'organism_id' => 1,
         ],
@@ -658,6 +660,7 @@ class sbo__relationship extends ChadoField {
       case 'genome of':
       case 'part of':
         $verb = 'is a';
+        break;
       case 'position of':
       case 'sequence of':
       case 'variant of':
@@ -674,6 +677,7 @@ class sbo__relationship extends ChadoField {
       case 'is a':
       case 'is a maternal parent of':
       case 'is a paternal parent of':
+      case 'is a subproject of':
       case 'is consecutive sequence of':
       case 'maximally overlaps':
       case 'overlaps':

+ 8 - 12
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -72,7 +72,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       $subject_type = $item['value']['local:relationship_subject']['rdfs:type'];
       $object_name = $item['value']['local:relationship_object']['schema:name'];
       $object_type = $item['value']['local:relationship_object']['rdfs:type'];
-      $phrase = $item['value']['SIO:000493'];
+      $clause_parts = $item['value']['SIO:000493'];
 
       // Handle some special cases.
       // For mRNA objects we don't want to show the CDS, exons, 5' UTR, etc.
@@ -87,31 +87,27 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
         continue;
       }
 
-      // Add bold font to the object and subject names.
-      // @todo add back in bolding...
-      // @todo Fix Current Bug: if type name is in the object name, weird bolding happens.
-      // $phrase = preg_replace("/$subject_type/", "<b>$subject_type</b>", $phrase);
-      // $phrase = preg_replace("/$object_type/", "<b>$object_type</b>", $phrase);
-
       // Convert the object/subject to a link if an entity exists for it.
       if (array_key_exists('entity', $item['value']['local:relationship_object'])) {
         list($entity_type, $object_entity_id) = explode(':', $item['value']['local:relationship_object']['entity']);
 
         if ($object_entity_id != $entity->id) {
-          $link = l($object_name, 'bio_data/' . $object_entity_id);
-          $phrase = str_replace($object_name, $link, $phrase);
+          $clause_parts[11] = l($clause_parts[11], 'bio_data/' . $object_entity_id);
         }
       }
       if (array_key_exists('entity', $item['value']['local:relationship_subject'])) {
         list($entity_type, $subject_entity_id) = explode(':', $item['value']['local:relationship_subject']['entity']);
         if ($subject_entity_id != $entity->id) {
-          $link = l($subject_name, 'bio_data/' . $subject_entity_id);
-          $phrase = str_replace($subject_name, $link, $phrase);
+          $clause_parts[3] = l($clause_parts[3], 'bio_data/' . $subject_entity_id);
         }
       }
 
+      // Add bold font to the object and subject names.
+      $clause_parts[3] = '<b>' . $clause_parts[3] . '</b>';
+      $clause_parts[11] = '<b>' . $clause_parts[11] . '</b>';
+
       $rows[][] = [
-        'data' => $phrase,
+        'data' => implode('', $clause_parts),
         //'class' => array('tripal-entity-unattached field-items')
       ];
     }