Browse Source

Added labels and help where needed to the elementInfo functions of the TripalFields

Stephen Ficklin 7 years ago
parent
commit
e09c7bedc9

+ 18 - 1
tripal/tripal_views_query.inc

@@ -27,7 +27,7 @@ class tripal_views_query extends views_plugin_query {
   /**
    * The sort item that are to be included in the query.
    */
-  var $sort;
+  var $order;
 
 
 
@@ -63,6 +63,7 @@ class tripal_views_query extends views_plugin_query {
     parent::init($base_table, $base_field, $options);
     $this->fields = array();
     $this->where = array();
+    $this->order = array();
 
     // Creqte the TripalFieldQuery object.
     $this->query = new TripalFieldQuery();
@@ -267,6 +268,13 @@ class tripal_views_query extends views_plugin_query {
         $field_ids = array();
         foreach ($this->fields as $details) {
           $field_name = $details['field_name'];
+          // If the field_name comes to us with a period in it then it means that
+          // we need to separate the field name from sub-element names.
+          $matches = array();
+          if (preg_match('/^(.+?)\.(.*)$/', $field_name, $matches)) {
+            $field_name = $matches[1];
+            $element_name = $matches[2];
+          }
           $field = field_info_field($field_name);
           if ($field) {
             $fields[$field_name] = $field;
@@ -305,6 +313,15 @@ class tripal_views_query extends views_plugin_query {
               $view->result[$i]->$field_name = $entity->status;
               continue;
             }
+
+            // If the field_name comes to us with a period in it then it means that
+            // we need to separate the field name from sub-element names.
+            $matches = array();
+            if (preg_match('/^(.+?)\.(.*)$/', $field_name, $matches)) {
+              $field_name = $matches[1];
+              $element_name = $matches[2];
+            }
+
             if (array_key_exists($field_name, $fields)) {
               $items = field_get_items('TripalEntity', $entity, $field_name);
               $view->result[$i]->$field_name = $items;

+ 50 - 7
tripal/views_handlers/tripal_views_handler_field_element.inc

@@ -61,22 +61,65 @@ class tripal_views_handler_field_element extends tripal_views_handler_field {
       $element_name = preg_replace('/__/', ':', $element_name);
     }
 
-    $value = $this->get_value($values);
+    // Get the items for this field.
+    $items = $this->get_value($values);
+
+    // Is this a nested element? If not make sure we have an array of element
+    // names to make it easier to deal with the name below.
+    $elements = explode('.', $element_name);
+    if (count($elements) == 0) {
+      $elements[] = $element_name;
+    }
 
     // Handle single value fields:
-    if (count($value) == 0) {
+    if (count($items) == 0) {
       return '';
     }
-    if (count($value) == 1) {
-      return $this->sanitize_value($value[0]['value'][$element_name], 'xss');
+    else if (count($items) == 1) {
+      $item = $items[0];
+      $element = array_shift($elements);
+      if (is_array($item['value'][$element])) {
+        return $this->_get_element_value($elements, $item['value'][$element]);
+      }
+      else {
+        return $this->sanitize_value($item['value'][$element_name], 'xss');
+      }
+    }
+    else if (count($items) <= 10) {
+      $element = array_shift($elements);
+      $element_values = array();
+      foreach ($items as $index => $item) {
+        if (is_array($item['value'][$element])) {
+          $element_values[] = $this->_get_element_value($elements, $item['value'][$element]);
+        }
+        else {
+          $element_values[] = $this->sanitize_value($item['value'][$element], 'xss');
+        }
+      }
+      // TODO: theming this way should probably be handled by a sepcial
+      // field handler that the user can tweak. But for now we'll just do this.
+      return theme_item_list(array(
+        'items' => $element_values,
+        'title' => NULL,
+        'type' => 'ul',
+        'attributes' => array(),
+      ));
     }
     else {
-      dpm($value);
       return t('Too many values to show.');
     }
   }
 
-  protected function get_element_value($value, $element_name) {
-
+  /**
+   * A recursive function for retrieving a nested element value.
+   */
+  private function _get_element_value($elements, $item_values) {
+    $element = array_shift($elements);
+    if (is_array($item_values[$element])) {
+      return $this->_get_element_value($elements, $item_values[$element]);
+    }
+    else {
+      return $this->sanitize_value($item_values[$element], 'xss');
+    }
   }
 }

+ 6 - 0
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc

@@ -77,18 +77,24 @@ class chado_linker__contact extends ChadoField {
           $type_term => array(
             'searchable' => TRUE,
             'name' => 'type',
+            'label' => 'Contact Type',
+            'help' => 'The type of contact',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           $name_term => array(
             'searchable' => TRUE,
             'name' => 'name',
+            'label' => 'Contact Name',
+            'help' => 'The name of the contact.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           $description_term => array(
             'searchable' => TRUE,
             'name' => 'description',
+            'label' => 'Contact Description',
+            'help' => 'A descriptoin of the contact.',
             'operations' => array('contains'),
             'sortable' => FALSE,
           ),

+ 10 - 0
tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates.inc

@@ -69,12 +69,16 @@ class data__sequence_coordinates extends ChadoField {
           'data:3002' => array(
             'searchable' => TRUE,
             'name' => 'source_feature',
+            'label' => 'Location Reference Name',
+            'help' => 'The genomic feature on which this feature is localized.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           'local:fmin' => array(
             'searchable' => TRUE,
             'name' => 'feature min',
+            'label' => 'Location Start Position',
+            'help' => 'The start position',
             'type' => 'numeric',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
@@ -82,6 +86,8 @@ class data__sequence_coordinates extends ChadoField {
           'local:fmax' => array(
             'searchable' => TRUE,
             'name' => 'feature max',
+            'label' => 'Location End Position',
+            'help' => 'The end position',
             'type' => 'numeric',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
@@ -90,6 +96,8 @@ class data__sequence_coordinates extends ChadoField {
             'searchable' => TRUE,
             'name' => 'phase',
             'type' => 'numeric',
+            'label' => 'Location Phase',
+            'help' => 'The phase of the feature (applicable only to coding sequences).',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
           ),
@@ -97,6 +105,8 @@ class data__sequence_coordinates extends ChadoField {
             'searchable' => TRUE,
             'name' => 'strand',
             'type' => 'numeric',
+            'label' => 'Location Strand',
+            'help' => 'The orientation of this feature where it is localized',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
           ),

+ 6 - 0
tripal_chado/includes/TripalFields/local__source_data/local__source_data.inc

@@ -74,18 +74,24 @@ class local__source_data extends ChadoField {
           $sourcename_term => array(
             'searchable' => TRUE,
             'name' => 'sourcename',
+            'label' => 'Data Source Name',
+            'help' => 'The name of the data source used for the analysis.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           $sourceversion_term => array(
             'searchable' => FALSE,
             'name' => 'sourceversion',
+            'label' => 'Data Source Version',
+            'help' => 'If applicable, the version number of the source data used for the analysis.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           $sourceuri_term => array(
             'searchable' => FALSE,
             'name' => 'sourceuri',
+            'label' => 'Data Source URI',
+            'help' => 'If applicable, the universal resource indicator (e.g. URL) of the source data used for the analysis.',
             'operations' => array(),
             'sortable' => FALSE,
           ),

+ 7 - 1
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map.inc

@@ -76,12 +76,16 @@ class ogi__location_on_map extends ChadoField {
             'elements' => array(
               $name_term => array(
                 'name' => 'map_name',
+                'label' => 'Map Name',
+                'help' => 'The name of the map.',
                 'searchable' => TRUE,
                 'operations' => array('eq', 'ne', 'contains', 'starts'),
                 'sortable' => FALSE,
               ),
               $description_term => array(
                 'name' => 'map_description',
+                'label' => 'Map Description',
+                'help' => 'A description of the map.',
                 'searchable' => TRUE,
                 'operations' => array('eq', 'ne', 'contains', 'starts'),
                 'sortable' => FALSE,
@@ -89,7 +93,9 @@ class ogi__location_on_map extends ChadoField {
             ),
           ),
           $mappos_term => array(
-            'name' => 'Map',
+            'name' => 'map_position_type',
+            'label' => 'Map Position Type',
+            'help' => 'Maps may use different coordinate systems. This indicates the type of coordinate.',
             'searchable' => TRUE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,

+ 6 - 0
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -75,18 +75,24 @@ class sbo__database_cross_reference extends ChadoField {
           $dbname_term => array(
             'searchable' => TRUE,
             'name' => 'db_name',
+            'label' => 'Database Name',
+            'help' => 'The name of the remote database that houses the cross reference.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           $accession_term => array(
             'searchable' => TRUE,
             'name' => 'accession',
+            'label' => 'Database Accession',
+            'help' => 'The unique accession (identifier) in the database that houses the cross reference.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           'schema:url' => array(
             'searchable' => FALSE,
             'name' => 'URL',
+            'label' => 'Database URL',
+            'help' => 'The URL of the database that houses the cross reference.',
             'sortable' => FALSE,
           ),
         ),

+ 6 - 0
tripal_chado/includes/TripalFields/sio__references/sio__references.inc

@@ -70,18 +70,24 @@ class sio__references extends ChadoField {
           'rdfs:type' => array(
             'searchable' => TRUE,
             'name' => 'type',
+            'label' => 'Reference Type',
+            'help' => 'The type of item referred to by the publication.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           'schema:name' => array(
             'searchable' => TRUE,
             'name' => 'name',
+            'label' => 'Reference Name',
+            'help' => 'The name of the item referred to by the publication.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
           'data:0842'=> array(
             'searchable' => TRUE,
             'name' => 'identifier',
+            'label' => 'Reference Identifier',
+            'help' => 'The unique identifier of the item referred to by the publication.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),

+ 6 - 0
tripal_chado/includes/TripalFields/so__genotype/so__genotype.inc

@@ -70,17 +70,23 @@ class so__genotype extends ChadoField {
           'rdfs:type' => array(
             'searchable' => FALSE,
             'name' => 'genotype_type_name',
+            'label' => 'Genotype Type',
+            'help' => 'The type of genotype.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'schema:name' => array(
             'name' => 'genotype_name',
+            'label' => 'Genotype Name',
+            'help' => 'The name of the genotype.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'schema:description' => array(
             'name' => 'genotype_description',
+            'label' => 'Genotype Description',
+            'help' => 'A description of the genotype.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,

+ 8 - 0
tripal_chado/includes/TripalFields/so__transcript/so__transcript.inc

@@ -67,24 +67,32 @@ class so__transcript extends ChadoField {
         'elements' => array(
           'rdfs:type' => array(
             'name' => 'transcript_type',
+            'label' => 'Transcript Type',
+            'help' => 'The type of a transcript.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'schema:name' => array(
             'name' => 'transcript_name',
+            'label' => 'Transcript Name',
+            'help' => 'The name of a transcript.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'data:0842' => array(
             'name' => 'transcript_uniquename',
+            'label' => 'Transcript Identifier',
+            'help' => 'The unique identifier of a transcript.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'SO:0000735' => array(
             'name' => 'loc',
+            'label' => 'Transcript Location',
+            'help' => 'The location of the transcript on a reference feature.',
             'searchable' => FALSE,
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,