Browse Source

Fixes to fields

Stephen Ficklin 8 years ago
parent
commit
eed6e37264

+ 5 - 1
tripal_chado/includes/fields/chado_base__dbxref_id.inc

@@ -318,7 +318,11 @@ class chado_base__dbxref_id extends TripalField {
 
     // Set some defauls for the empty record
     $entity->{$field_name}['und'][0] = array(
-      'value' => array(),
+      'value' => array(
+        'vocabulary' => '',
+        'accession' => '',
+        'URL' => '',
+      ),
       $field_table . '__' . $field_column => '',
       $field_table . '__dbxref_id--dbxref_id' => '',
       $field_table . '__dbxref_id--db_id' => '',

+ 6 - 1
tripal_chado/includes/fields/chado_gene__transcripts.inc

@@ -232,7 +232,12 @@ class chado_gene__transcripts extends TripalField {
 
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
-      'value' => array(),
+      'value' => array(
+        'type' => '',
+        'name' => '',
+        'identifier' => '',
+        'location' => '',
+      ),
     );
 
     // TODO: If the tripal_get_feature_relationships() slows this down then

+ 49 - 20
tripal_ws/tripal_ws.module

@@ -137,26 +137,41 @@ function tripal_ws_entity_load($entities, $type) {
 
 function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
 
+  // Get the content type on this site
+  $bundle = tripal_load_bundle_entity(array('label' => $ctype));
+  $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
+  $term = reset($term);
+  $vocab = $term->vocab;
+
+  $query = db_select('tripal_sites', 'ts');
+  $query->fields('ts');
+  $query->condition('id', $site_id);
+  $site = $query->execute()->fetchObject();
+
+  if (!$site) {
+    return 'Could not find specified site.';
+  }
+
   // Get the content from the web services of the remote site.
-  $url = "https://dev.bioinfo.wsu.edu/~ccheng/tripal3/ws/v0.1/content/gene/12";
+  $url = $site->url . "/ws/v0.1/content/" . $ctype . "/" . $id;
   $json = file_get_contents($url);
   $response = json_decode($json, TRUE);
-  //dpm($response);
+dpm($response);
 
   // Set the title for this page to match the title provided.
   drupal_set_title($response['label']);
 
   // Attribute this data to the proper source.
   $source_url = l($response['label'], $response['itemPage'], array('attributes' => array('target' => '_blank')));
-  $content = '<div><strong>Source:</strong> Chun-huai\'s amazing test site: ' . $source_url . '</div>';
+  $content = '<div><strong>Source:</strong> ' . $site->name . ': ' . $source_url . '</div>';
 
   // Fake an entity so we can display this content using the same
   // entity type on this site.
   $entity = new TripalEntity(array(), 'TripalEntity');
   $entity->id = 807;
   $entity->type = 'TripalEntity';
-  $entity->bundle = 'bio_data_266';
-  $entity->term_id = 266;
+  $entity->bundle = $bundle->name;
+  $entity->term_id = $term->id;
   $entity->title = $response['label'];
   $entity->uid = 1;
   $entity->status = 1;
@@ -167,7 +182,7 @@ function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
   foreach ($fields as $field) {
     if (isset($field['bundles']['TripalEntity'])) {
       foreach ($field['bundles']['TripalEntity'] as $bundle_name) {
-        if ($bundle_name == 'bio_data_266') {
+        if ($bundle_name == $bundle->name) {
           $my_fields[] = $field;
         }
       }
@@ -206,26 +221,40 @@ function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
       // handle that separately.
       if (isset($response['@context'][$term_name]['@type']) and
           $response['@context'][$term_name]['@type'] == '@id') {
-        continue;
+        $subquery = json_decode(file_get_contents($response[$term_name]), TRUE);
+
+        // If the result is a collection then we want to add each value with
+        // it's own delta value.
+        if (array_key_exists('@type', $subquery) and $subquery['@type'] == 'Collection') {
+          $i = 0;
+          $f = array();
+          foreach ($subquery['member'] as $member) {
+            $f['und'][$i]['value'] = $member;
+            $i++;
+          }
+          $entity->$field_name = $f;
+        }
+        // If the result is not a collection then just add it.
+        else {
+          dpm($response[$term_name]);
+          dpm($subquery);
+          unset($subquery['@context']);
+          unset($subquery['@id']);
+          $f = array();
+          $f['und'][0]['value'] = $subquery;
+          $entity->$field_name = $f;
+        }
       }
-
       // For all fields that are currently attached, add the field and
       // value to the entity.
-      $f = array();
-      $f['und'][0]['value'] = $response[$term_name];
-      $entity->$field_name = $f;
+      else {
+        $f = array();
+        $f['und'][0]['value'] = $response[$term_name];
+        $entity->$field_name = $f;
+      }
     }
   }
 
-//   // For fields that are links rather than values then we
-//   $sequences_json = file_get_contents($response['sequence']);
-//   $sequences = json_decode($sequences_json, TRUE);
-//   $entity->feature__residues = array();
-//   foreach ($sequences['member'] as $delta => $value) {
-//     $entity->feature__residues['und'][$delta]['value'] = $sequences['member'][$delta];
-//   }
-//   dpm($entity);
-
   // Generate the View for this entity
   $entities = array();
   $entities[] = $entity;