Browse Source

Fixed up the phenotype field again... but still needs more work

Stephen Ficklin 7 years ago
parent
commit
62019c5236

+ 1 - 4
tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype.inc

@@ -109,11 +109,8 @@ class sbo__phenotype extends ChadoField {
         if ($phenotype->cvalue_id) {
           $entity->{$field_name}['und'][$i]['value']['value'] =  $phenotype->cvalue_id->name;
         }
-        elseif ($phenotype->value) {
-          $entity->{$field_name}['und'][$i]['value']['value'] =  $phenotype->value;
-        }
         else {
-          $entity->{$field_name}['und'][$i]['value']['value'] =  'N/A';
+          $entity->{$field_name}['und'][$i]['value']['value'] =  $phenotype->value;
         }
         
         $entity->{$field_name}['und'][$i][$field_table . '__' . $pkey] = $phenotype_linker->$pkey;

+ 42 - 10
tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype_formatter.inc

@@ -23,9 +23,14 @@ class sbo__phenotype_formatter extends ChadoFieldFormatter {
     // Get the settings
     $settings = $display['settings'];
 
-    $headers = array('Name', 'Value', 'Type');
+    $headers = array();
     $rows = array();
+    $has_type = FALSE;
+    $has_value = FALSE;
+    $has_name = FALSE;
 
+    // First iterate through the phenotypes to see if
+    // we have all of the data columns.
     foreach ($items as $delta => $item) {
       $phenotype = $item['value'];
       if (!$phenotype) {
@@ -33,16 +38,43 @@ class sbo__phenotype_formatter extends ChadoFieldFormatter {
       }
 
       // Get the field values
-      $phenotype_name = $phenotype['name'];
-      $value = $phenotype['value'];
-      $type = $phenotype['type'];
-
-      // Add a link i there is an entity.
-      if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
-        list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
-        $phenotype_name = l($phenotype_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
+      if ($phenotype['name']) {
+        $has_name = TRUE;
+      }
+      if ($phenotype['value']) {
+        $has_value = TRUE;
+      }
+      if ($phenotype['type']) {
+        $has_type = TRUE;
+      }
+    }
+    foreach ($items as $delta => $item) {
+      $row = array();
+      if ($has_type) {
+        $row[] = $phenotype['type'];
       }
-      $rows[] = array($phenotype_name, $value, $type);
+      if ($has_name) {
+        $phenotype_name = $phenotype['name'];
+        // Add a link i there is an entity.
+        if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
+          list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
+          $phenotype_name = l($phenotype_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
+        }
+        $row[] = $phenotype_name;
+      }
+      if ($has_value) {
+        $row[] = $phenotype['value'];
+      }
+      $rows[] = $row;
+    }
+    if ($has_type) {
+      $header[] = 'Phenotype';
+    }
+    if ($has_name) {
+      $header[] = 'Property';
+    }
+    if ($has_value) {
+      $header[] = 'Value';
     }
     $table = array(
       'header' => $headers,