Browse Source

Fixed location on map field

Stephen Ficklin 8 years ago
parent
commit
f74eea2518

+ 44 - 0
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map.inc

@@ -60,7 +60,51 @@ class ogi__location_on_map extends ChadoField {
    * @see TripalField::load()
    */
   public function load($entity, $details = array()) {
+    $record = $details['record'];
+    $settings = $this->field['settings'];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
 
+    // Set some defaults for the empty record.
+    $entity->{$field_name}['und'][0] = array(
+      'value' => array(),
+    );
+
+    // Add the featurepos records to our $record.
+    $options = array(
+      'return_array' => TRUE,
+      'include_fk' => array(
+        'srcfeature_id' => array(
+          'type_id' => 1,
+        ),
+        'feature_id' => array(
+          'type_id' => 1
+        ),
+      )
+    );
+    $feature = chado_expand_var($record, 'table', 'featurepos', $options);
+
+    // Iterate through the positions and add them to our values.
+    $i = 0;
+    if (isset($feature->featurepos->feature_id)) {
+      foreach ($feature->featurepos->feature_id AS $featurepos) {
+        // Get details about the map
+        $featuremap = chado_generate_var('featuremap', array('featuremap_id' => $featurepos->featuremap_id));
+        $value = array (
+          // Map.
+          'data:1274' => array(
+            'schema:name' => $featurmap->name,
+            'schema:description' => $featuremap->description,
+          ),
+          tripal_get_chado_semweb_term('featurepos', 'mappos') => $featurepos->mappos
+        );
+        if (property_exists($featuremap, 'entity_id')) {
+          $value['data:1274']['entity'] = 'TripalEntity:' . $featuremap->entity_id;
+        }
+        $entity->{$field_name}['und'][$i]['value'][] = $value;
+        $i++;
+      }
+    }
   }
 
 }

+ 40 - 0
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map_formatter.inc

@@ -21,5 +21,45 @@ class ogi__location_on_map_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 
+    $rows = array();
+    $headers = array('Map', 'Position', 'Map Description');
+    foreach ($items as $delta => $item) {
+      if (!$item['value']) {
+        continue;
+      }
+      $val = $item['value'];
+      $map_name = $item['value']['data:1274']['schema:name'];
+      $map_desc = $item['value']['data:1274']['schema:description'];
+      $position = $item['value'][tripal_get_chado_semweb_term('featurepos', 'mappos')];
+      $rows[] = array(
+        $map_name,
+        $map_desc,
+        $position
+      );
+    }
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_feature-table-map-positions',
+        'class' => 'tripal-data-table'
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => 'This are no positions on any maps.',
+    );
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    if (count($items) > 0) {
+      $element[0] = array(
+        '#type' => 'markup',
+        '#markup' => theme_table($table),
+      );
+    }
   }
 }

+ 9 - 1
tripal_chado/includes/tripal_chado.semweb.inc

@@ -192,6 +192,14 @@ function tripal_chado_populate_vocab_SIO() {
     'cv_name' => 'SIO',
     'definition' => 'references is a relation between one entity and the entity that it makes reference to by name, but is not described by it.',
   ));
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SIO:000056',
+    'name' => 'position',
+    'cv_name' => 'SIO',
+    'definition' => 'A measurement of a spatial location relative to a frame of reference or other objects.',
+  ));
+  tripal_associate_chado_semweb_term('featurepos', 'mappos', $term);
 }
 /**
  * Adds the EDAM database and terms.
@@ -360,7 +368,7 @@ function tripal_chado_populate_vocab_OGI() {
     'cv_name' => 'ogi',
     'definition' => '',
   ));
-  tripal_associate_chado_semweb_term('featurepos', 'mappos', $term);
+
 }
 /**
  * Adds the Information Artifact Ontology database and terms.

+ 4 - 0
tripal_chado_views/includes/tripal_chado_views_integration.inc

@@ -27,6 +27,10 @@ function tripal_chado_views_delete_all_integrations() {
  * @ingroup tripal_chado_views
  */
 function tripal_chado_views_integrate_all_chado_tables() {
+  // The tripal_chado_views and tripal_chado module are so highly tied
+  // together it may make sense for them to be one module.  But in the
+  // event that one is enabled and the other not we will have problems
+  // with the load below.
   module_load_include('inc', 'tripal_chado', 'api/tripal_chado.mviews.api');
 
   // First integrate all of the Chado tables. Those that are base tables