Browse Source

Working on showing remote content within the layout on this site

Stephen Ficklin 8 years ago
parent
commit
aa2b120a20

+ 1 - 1
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -178,7 +178,7 @@ class chado_base__organism_id extends TripalField {
       $field, $instance, $langcode, $items, $display) {
       $field, $instance, $langcode, $items, $display) {
 
 
     if (count($items) > 0) {
     if (count($items) > 0) {
-      $content =  $items[0]['value'];
+      $content = $items[0]['value']['label'];
       if (array_key_exists('entity', $items[0]['value'])) {
       if (array_key_exists('entity', $items[0]['value'])) {
         list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity']);
         list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity']);
         $content = l(strip_tags($items[0]['value']['label']), 'bio_data/' . $entity_id);
         $content = l(strip_tags($items[0]['value']['label']), 'bio_data/' . $entity_id);

+ 0 - 1
tripal_chado/includes/fields/chado_feature__residues.inc

@@ -155,7 +155,6 @@ class chado_feature__residues extends TripalField {
     );
     );
 
 
     $num_bases = 50;
     $num_bases = 50;
-    $feature = $entity->chado_record;
     foreach ($items as $delta => $item) {
     foreach ($items as $delta => $item) {
       // If there are no residues then skip this one.
       // If there are no residues then skip this one.
       if (!is_array($item['value']) or !array_key_exists('residues', $item['value'])) {
       if (!is_array($item['value']) or !array_key_exists('residues', $item['value'])) {

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

@@ -174,7 +174,6 @@ class chado_gene__transcripts extends TripalField {
 
 
     // Get the settings
     // Get the settings
     $settings = $display['settings'];
     $settings = $display['settings'];
-    $record = $entity->chado_record;
 
 
     $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
     $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
     $rows = array();
     $rows = array();

+ 1 - 2
tripal_chado/includes/fields/chado_linker__contact.inc

@@ -80,7 +80,7 @@ class chado_linker__contact extends TripalField {
       ),
       ),
       'settings' => array(
       'settings' => array(
         'chado_table' => $contact_table,
         'chado_table' => $contact_table,
-        'chado_column' => $pkey,
+        'chado_column' => 'contact_id',
         'base_table' => $table_name,
         'base_table' => $table_name,
         'semantic_web' => 'local:contact'
         'semantic_web' => 'local:contact'
       ),
       ),
@@ -162,7 +162,6 @@ class chado_linker__contact extends TripalField {
       $field, $instance, $langcode, $items, $display) {
       $field, $instance, $langcode, $items, $display) {
     // Get the settings
     // Get the settings
     $settings = $display['settings'];
     $settings = $display['settings'];
-    $record = $entity->chado_record;
 
 
     $headers = array('Name', 'Description', 'Type');
     $headers = array('Name', 'Description', 'Type');
     $rows = array();
     $rows = array();

+ 0 - 1
tripal_chado/includes/fields/chado_linker__expression.inc

@@ -157,7 +157,6 @@ class chado_linker__expression extends TripalField {
 
 
     // Get the settings
     // Get the settings
     $settings = $display['settings'];
     $settings = $display['settings'];
-    $record = $entity->chado_record;
 
 
     $content = '';
     $content = '';
     $rows = array();
     $rows = array();

+ 0 - 1
tripal_chado/includes/fields/chado_linker__genotype.inc

@@ -156,7 +156,6 @@ class chado_linker__genotype extends TripalField {
 
 
     // Get the settings
     // Get the settings
     $settings = $display['settings'];
     $settings = $display['settings'];
-    $record = $entity->chado_record;
 
 
     $headers = array('Name', 'Description', 'Type');
     $headers = array('Name', 'Description', 'Type');
     $rows = array();
     $rows = array();

+ 0 - 1
tripal_chado/includes/fields/chado_linker__phenotype.inc

@@ -156,7 +156,6 @@ class chado_linker__phenotype extends TripalField {
       $field, $instance, $langcode, $items, $display) {
       $field, $instance, $langcode, $items, $display) {
     // Get the settings
     // Get the settings
     $settings = $display['settings'];
     $settings = $display['settings'];
-    $record = $entity->chado_record;
 
 
     $headers = array('Name', 'Value', 'Type');
     $headers = array('Name', 'Value', 'Type');
     $rows = array();
     $rows = array();

+ 4 - 14
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -405,20 +405,6 @@ function tripal_chado_field_storage_expand_field($item_name, $value) {
      return array($item_name => $value);
      return array($item_name => $value);
    }
    }
 }
 }
-
-/**
- * Implements hook_field_storage_query().
- *
- * Used by EntityFieldQuery to find the entities having certain field values.
- *
- * We do not support use of the EntityFieldQuery API for Tripal based fields
- * because EFQ doesn't support when multiple storage backends are used. Instead
- * use the TripalFieldQuery class and implement the hook_storage_tquery()
- * function.
- */
-function tripal_chado_field_storage_query($query) {
-
-}
 /**
 /**
  * Implements hook_field_storage_tquery().
  * Implements hook_field_storage_tquery().
  *
  *
@@ -446,6 +432,7 @@ function tripal_chado_field_storage_tquery($conditions) {
     // Set the value for this field search.
     // Set the value for this field search.
     $value = NULL;
     $value = NULL;
     $subfields = explode('.', $filter);
     $subfields = explode('.', $filter);
+    print_r($subfields);
     if (count($subfields) > 1) {
     if (count($subfields) > 1) {
       // Get the term for this field's column and replace the field_name with
       // Get the term for this field's column and replace the field_name with
       // the term.  We need to do this for the recursive function to work.
       // the term.  We need to do this for the recursive function to work.
@@ -461,6 +448,7 @@ function tripal_chado_field_storage_tquery($conditions) {
       $value = $condition['value'];
       $value = $condition['value'];
     }
     }
 
 
+
     // Use the appropriate operator.
     // Use the appropriate operator.
     $operator = $condition['operator'];
     $operator = $condition['operator'];
     switch ($operator) {
     switch ($operator) {
@@ -503,6 +491,8 @@ function tripal_chado_field_storage_tquery($conditions) {
   // Iterate through the filters and perform the query
   // Iterate through the filters and perform the query
   $entity_ids = array();
   $entity_ids = array();
   foreach ($filters as $chado_table => $values) {
   foreach ($filters as $chado_table => $values) {
+    print_r($chado_table);
+    print_r($values);
     // First get the matching record IDs from the Chado table.
     // First get the matching record IDs from the Chado table.
     $schema = chado_get_schema($chado_table);
     $schema = chado_get_schema($chado_table);
     $pkey = $schema['primary key'][0];
     $pkey = $schema['primary key'][0];

+ 26 - 13
tripal_ws/includes/tripal_ws.admin.inc

@@ -1,7 +1,7 @@
 <?php
 <?php
 /**
 /**
  * Provide form to store information of other Tripal sites
  * Provide form to store information of other Tripal sites
- * 
+ *
  * @param unknown $form
  * @param unknown $form
  * @param unknown $form_state
  * @param unknown $form_state
  */
  */
@@ -10,8 +10,8 @@ function tripal_ws_tripal_sites_form($form, &$form_state) {
   $form = array();
   $form = array();
   $values = key_exists('values', $form_state) ? $form_state['values'] : NULL;
   $values = key_exists('values', $form_state) ? $form_state['values'] : NULL;
   $tripal_site = $values ? $values['tripal_site'] : 0;
   $tripal_site = $values ? $values['tripal_site'] : 0;
-  
-  $results = 
+
+  $results =
     db_select('tripal_sites', 'ts')
     db_select('tripal_sites', 'ts')
       ->fields('ts')
       ->fields('ts')
       ->execute();
       ->execute();
@@ -33,14 +33,27 @@ function tripal_ws_tripal_sites_form($form, &$form_state) {
   if (count($rows) == 0) {
   if (count($rows) == 0) {
     $rows[] = array('No configured Tripal site.', array('colspan' => 5));
     $rows[] = array('No configured Tripal site.', array('colspan' => 5));
   }
   }
-  $output = theme('table', array(
-      'header' => $headers,
-      'rows' => $rows,
-    ));
-    $form['table'] = array(
-      '#markup' => $output
-    );
-  
+
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  $output = theme_table($table);
+
+  $form['instructions'] = array(
+    '#type' => 'item',
+    '#markup' => t('The following is a list of remote Tripal sites with which
+        this site can communicate. You may add and remove site as needed.')
+  );
+  $form['table'] = array(
+    '#markup' => $output
+  );
+
   return $form;
   return $form;
 }
 }
 
 
@@ -112,7 +125,7 @@ function tripal_ws_tripal_sites_edit_form($form, &$form_state, $tripal_site_id =
     '#name' => 'cancel_button',
     '#name' => 'cancel_button',
     '#limit_validation_errors' => array()
     '#limit_validation_errors' => array()
   );
   );
-  
+
   return $form;
   return $form;
 }
 }
 
 
@@ -283,6 +296,6 @@ function tripal_ws_tripal_sites_remove_form_submit($form, &$form_state) {
       ->condition('id', $id)
       ->condition('id', $id)
       ->execute();
       ->execute();
     drupal_set_message('The Tripal site \'' .$name . '\' has been removed.');
     drupal_set_message('The Tripal site \'' .$name . '\' has been removed.');
-  }    
+  }
   drupal_goto('/admin/tripal/storage/ws/tripal_sites');
   drupal_goto('/admin/tripal/storage/ws/tripal_sites');
 }
 }

+ 4 - 1
tripal_ws/tripal_ws.install

@@ -53,7 +53,10 @@ function tripal_ws_tripal_sites_schema() {
       'url' => array('url'),
       'url' => array('url'),
       'description' => array('description'),
       'description' => array('description'),
     ),
     ),
-    'unique keys' => array('url' => array('url')),
+    'unique keys' => array(
+      'tripal_sites_c1' => array('url', 'version'),
+      'tripal_sites_c2' => array('name')
+    ),
     'primary key' => array('id'),
     'primary key' => array('id'),
   );
   );
   return $schema;
   return $schema;

+ 77 - 3
tripal_ws/tripal_ws.module

@@ -36,10 +36,17 @@ function tripal_ws_menu() {
     'type' => MENU_CALLBACK,
     'type' => MENU_CALLBACK,
   );
   );
 
 
+  $items['remote/%/%/%/%'] = array(
+    'page callback' => 'tripal_ws_load_remote_entity',
+    'page arguments' => array(1, 2, 3, 4),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+
   // Tripal Web Services setting groups
   // Tripal Web Services setting groups
   $items['admin/tripal/storage/ws'] = array(
   $items['admin/tripal/storage/ws'] = array(
-    'title' => 'Web Services',
-    'description' => t("Import data from other Tripal sites using the web services."),
+    'title' => 'Remote Tripal Sites',
+    'description' => t("Create mashups of content using data from this site and remote Tripal sites."),
     'weight' => 20,
     'weight' => 20,
     'page callback' => 'system_admin_menu_block_page',
     'page callback' => 'system_admin_menu_block_page',
     'access arguments' => array('administer tripal'),
     'access arguments' => array('administer tripal'),
@@ -47,7 +54,7 @@ function tripal_ws_menu() {
     'file path' => drupal_get_path('module', 'system'),
     'file path' => drupal_get_path('module', 'system'),
   );
   );
   $items['admin/tripal/storage/ws/tripal_sites'] = array(
   $items['admin/tripal/storage/ws/tripal_sites'] = array(
-    'title' => 'Other Tripal Sites',
+    'title' => 'Configuration',
     'description' => t('Provides information about other Tripal sites.
     'description' => t('Provides information about other Tripal sites.
         This allows data exchange and communication betwen Tripal
         This allows data exchange and communication betwen Tripal
         enabled sites through the web services.'),
         enabled sites through the web services.'),
@@ -118,4 +125,71 @@ function tripal_ws_services() {
 
 
   drupal_add_http_header('Content-Type', 'application/ld+json');
   drupal_add_http_header('Content-Type', 'application/ld+json');
   print drupal_json_encode($response);
   print drupal_json_encode($response);
+}
+
+function tripal_ws_entity_load($entities, $type) {
+  foreach ($entities as $entity) {
+    //if ($entiy->type = 'TripalEntity') {
+      dpm($entity);
+    //}
+  }
+}
+
+function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
+
+  // 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";
+  $json = file_get_contents($url);
+  $response = json_decode($json, TRUE);
+  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>';
+
+  // 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->title = $response['label'];
+  $entity->uid = 1;
+  $entity->status = 1;
+
+  // Add fields.
+  $entity->feature__name = array(
+    'und' => array(
+      0 => array(
+        'value' => $response['name'],
+      ),
+    ),
+  );
+  $entity->feature__organism_id = array(
+    'und' => array(
+      0 => array(
+        'value' => $response['organism'],
+      ),
+    ),
+  );
+  $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;
+  $view = entity_view('TripalEntity', $entities);
+  $content .= drupal_render($view['TripalEntity'][807]);
+
+  return $content;
+
 }
 }