Browse Source

WIP fields

bradfordcondon 6 years ago
parent
commit
effd01dc0d

+ 7 - 7
tripal_chado/includes/TripalFields/local__child_properties/local__child_properties.inc

@@ -59,13 +59,13 @@ class local__child_properties extends ChadoField {
 
     $properties = [];
 
-    foreach ($master as $child){
-
-      //remove all the other fields from the expand_var.
-      
-      $child['info'] = $child['info']->featureprops;
-
-    }
+//    foreach ($master as $child){
+//
+//      //remove all the other fields from the expand_var.
+//
+//      $child['info'] = $child['info']->featureprops;
+//
+//    }
 
     //TODO: filter this to just hte properties.
     // Right now we include everything because we are having this field do double duty for annotations.

+ 7 - 98
tripal_chado/includes/TripalFields/local__child_properties/local__child_properties_formatter.inc

@@ -9,19 +9,8 @@
  */
 class local__child_properties_formatter extends ChadoFieldFormatter {
 
-  /**
-   * The default label for this field.
-   */
   public static $default_label = 'Child Properties';
-
-  /**
-   * The list of field types for which this formatter is appropriate.
-   */
   public static $field_types = ['local__child_properties'];
-
-  /**
-   * The list of default settings for this formatter.
-   */
   public static $default_settings = [
     'setting1' => 'default_value',
   ];
@@ -41,22 +30,16 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
     // Get the settings.
     $settings = $display['settings'];
 
-    // For now, values come from the data__sequence_features field.
-    // $data = $entity->{'data__sequence_features'}['und'];.
-    // insert into chado.featureprop (feature_id, type_id, value, rank) VALUES (5505, 100, 'some madeup prop value on a protein', 0);.
+    // Get the data for this field.
     $data = $entity->{'local__child_properties'}['und'];
 
     if (!$data) {
       return;
     }
 
-    $i = 0;
-
     foreach ($data as $i => $value) {
 
       $child = $value['value'];
-
-      // TODO: this is an extra undefined!  bad.
       // Assumption: we're on the gene entity.  We've got an array of mRNA feature ID's.
       $header = [
         'Feature Name',
@@ -67,7 +50,6 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
 
       $info = $child['info'];
       $name = $info->uniquename;
-
       $element[0][$i] = [
         '#type' => 'fieldset',
         '#title' => $name,
@@ -77,7 +59,6 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
             'collapsed',
           ],
         ],
-        // see: https://www.drupal.org/forum/support/module-development-and-code-questions/2012-02-07/drupal-render-fieldset-element
         '#attached' => ['js' => ['misc/collapse.js', 'misc/form.js']],
       ];
 
@@ -88,95 +69,27 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
         '#markup' => $table,
         '#title' => t("Child Properties for !root", ['!root' => $name]),
       ];
-
-      $rows = $this->getAnnotationRows($child);
-      $header = ['name', 'type', 'annotation'];
-
-      $table = theme('table', ['rows' => $rows, 'header' => $header]);
-      $element[0][$i]['annotation_table'] = [
-        '#markup' => $table,
-        '#title' => t("Annotations for !root", ['!root' => $name]),
-      ];
-
-      $i++;
     }
   }
 
   /**
-   * This functionality should move to a separate field.
+   * Recursively goes through the child feature array for property listings.
    *
-   * @param $data
-   */
-  private function getAnnotationRows($data) {
-
-    $rows = [];
-
-    $info = $data['info'];
-
-    $children = $data['children'] ?? NULL;
-
-    $annotations = $info->feature_cvterm;
-
-    if ($annotations) {
-
-      if (is_array($annotations)) {
-        foreach ($annotations as $ann) {
-
-          $annotation_name = $ann->cvterm_id->name;
-          if ($ann->is_not) {
-            $annotation_name = "is not " . $annotation_name;
-          }
-
-          $rows[] = [
-            $info->uniquename,
-            $info->type_id->name,
-            $annotation_name,
-          ];
-        }
-      }
-      else {
-        $annotation_name = $annotations->cvterm_id->name;
-        if ($annotations->is_not) {
-          $annotation_name = "is not " . $annotation_name;
-        }
-
-        $rows[] = [
-          $info->uniquename,
-          $info->type_id->name,
-          $annotation_name,
-        ];
-
-      }
-
-    }
-
-    if ($children && !empty($children)) {
-
-      foreach ($children as $child) {
-        $rows = array_merge($this->getAnnotationRows($child), $rows);
-      }
-    }
-    return $rows;
-
-  }
-
-  /**
-   * Recursively goes through the child feature array and builds an array of.
+   * @param array $data
+   *   Data formatted by the data__sequence_features field.
+   *    Expects an info and a children key.
    *
-   * @param $data
+   * @return array
+   *   Rows array suitable for table.
    */
   private function getPropRows($data) {
 
     $rows = [];
-
     $info = $data['info'];
-
     $children = $data['children'] ?? NULL;
-
     $props = $info->featureprop;
 
     if ($props) {
-
       // If there is only one property, it will be an object not an array.
       if (is_array($props)) {
         foreach ($props as $prop) {
@@ -195,16 +108,12 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
           $props->type_id->name,
           $props->value,
         ];
-
       }
-
     }
 
     if ($children && !empty($children)) {
-
       foreach ($children as $child) {
         $result = array_merge($this->getPropRows($child), $rows);
-
         $rows = $result;
       }
     }

+ 14 - 0
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc

@@ -328,6 +328,20 @@ class sio__annotation extends ChadoField {
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__pub_id'] = $linker->pub_id;
       }
     }
+
+
+    //  Deal with annotations from child features and their children.
+    // TODO: only check if we're attached to a feature that's a gene.
+    // TODO: filter out chado_expand_var stuff that isnt feature_relationship
+
+
+    $master = $entity->data__sequence_features['und'];
+
+    if ($master && !empty($master)) {
+
+      $entity->{$field_name}['und'][0]['child_annotations'] = $master;
+    }
+
   }
 }
 

+ 74 - 2
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_formatter.inc

@@ -56,7 +56,7 @@ class sio__annotation_formatter extends ChadoFieldFormatter {
       }
     }
 
-    // Theme the results in a talbe.
+    // Theme the results in a table.
     $caption = 'This record has the following annotations.';
     $table = array(
       'header' => $headers,
@@ -72,10 +72,82 @@ class sio__annotation_formatter extends ChadoFieldFormatter {
     );
 
     if (count($items) > 0) {
-      $element[0] = array(
+      $element[0]['base'] = array(
         '#type' => 'markup',
         '#markup' => theme_table($table),
       );
     }
+
+
+    $rows = $this->getAnnotationRows($child);
+    $header = ['name', 'type', 'annotation'];
+
+    $table = theme('table', ['rows' => $rows, 'header' => $header]);
+    $element[0][$i]['annotation_table'] = [
+      '#markup' => $table,
+      '#title' => t("Annotations for !root", ['!root' => $name]),
+    ];
+
+  }
+
+
+
+  /**
+   * Get annotations for child features, from the data__sequence_features field.
+   *
+   * @param $data
+   */
+  private function getAnnotationRows($data) {
+
+    $rows = [];
+
+    $info = $data['info'];
+
+    $children = $data['children'] ?? NULL;
+
+    $annotations = $info->feature_cvterm;
+
+    if ($annotations) {
+
+      if (is_array($annotations)) {
+        foreach ($annotations as $ann) {
+
+          $annotation_name = $ann->cvterm_id->name;
+          if ($ann->is_not) {
+            $annotation_name = "is not " . $annotation_name;
+          }
+
+          $rows[] = [
+            $info->uniquename,
+            $info->type_id->name,
+            $annotation_name,
+          ];
+        }
+      }
+      else {
+        $annotation_name = $annotations->cvterm_id->name;
+        if ($annotations->is_not) {
+          $annotation_name = "is not " . $annotation_name;
+        }
+
+        $rows[] = [
+          $info->uniquename,
+          $info->type_id->name,
+          $annotation_name,
+        ];
+
+      }
+
+    }
+
+    if ($children && !empty($children)) {
+
+      foreach ($children as $child) {
+        $rows = array_merge($this->getAnnotationRows($child), $rows);
+      }
+    }
+    return $rows;
+
   }
+
 }