function tripal_load_remote_entities

3.x tripal_ws.api.inc tripal_load_remote_entities($remote_entity_ids, $site_id, $bundle_accession, $field_ids)

Queries a remote site for an array of bulk entity ids.

This function returns an array of "fake" entities containing values for fields specified.

Parameters

$remote_entity_ids: Array of the remote ids.

$site_id: The numeric site ID for the remote Tripal site.

$bundle_accession: The controlled vocabulary term accession for the content type on the remote Tripal site.

$field_ids: The controlled vocabulary term accessions for the fields available on the remote content type. Any remote fields that matches these IDs will be added to the entity returned.

Return value

An array of fake entity objects where the key is the entity_id and the value is the object.

Related topics

1 call to tripal_load_remote_entities()
TripalEntityCollection::write in tripal/includes/TripalEntityCollection.inc
Writes the collection to a file using a given formatter.

File

tripal_ws/api/tripal_ws.api.inc, line 470
This file provides the Tripal Web Services API: a set of functions for interacting with the Tripal Web Services.

Code

function tripal_load_remote_entities($remote_entity_ids, $site_id, $bundle_accession, $field_ids) {

  if (!$remote_entity_ids) {
    throw new Exception('Please provide the list of remote entity ids for the tripal_load_remote_entities function.');
  }
  if (!is_array($remote_entity_ids)) {
    throw new Exception('Please provide an array for the remote entity ids for the tripal_load_remote_entities function.');
  }
  if (!$site_id) {
    throw new Exception('Please provide a numeric site ID for the tripal_load_remote_entities function.');
  }
  if (!$bundle_accession) {
    throw new Exception('Please provide the bundle accession for the tripal_load_remote_entities function.');
  }
  if (!$field_ids) {
    throw new Exception('Please provide the list of field IDs for the tripal_load_remote_entities function.');
  }
  if (!is_array($field_ids)) {
    throw new Exception('Please provide an array for the field IDs for the tripal_load_remote_entities function.');
  }

  // Get the site documentation (loads from cache if already retrieved).
  $site_doc = tripal_get_remote_API_doc($site_id);

  // Generate an array for the query and then execute it.
  $query = 'page=1&limit=' . count($remote_entity_ids) .
    '&ids=' . urlencode(implode(",", $remote_entity_ids)) .
    '&fields=' . urlencode(implode(",", $field_ids));

  $results = tripal_get_remote_content($site_id, $bundle_accession, $query);
  if (!$results) {
    return FALSE;
  }

  // Get the context JSON for this remote entity, we'll use it to map
  $context_url = $results['@context'];
  $context = tripal_get_remote_content_context($site_id, $context_url, $bundle_accession);
  if (!$context) {
    return $entity;
  }

  $total_items = $results['totalItems'];
  $members = $results['member'];

  $entities = array();
  foreach ($members as $member) {
    // Start building the fake entity.
    $entity_id = preg_replace('/^.*?(\d+)$/', '$1', $member['@id']);
    $entity = new stdClass();
    $entity->entityType = 'TripalEntity';
    $entity->entityInfo =[];
    $entity->id = $entity_id;
    $entity->type = 'TripalEntity';
    $entity->bundle = $bundle_accession;
    $entity->site_id = $site_id;

    $member = _tripal_update_remote_entity_field($member, $context, 1);
    foreach ($member as $field_id => $value) {
      $field = tripal_get_remote_field_info($site_id, $bundle_accession, $field_id);
      $instance = tripal_get_remote_field_instance_info($site_id, $bundle_accession, $field_id);
      $field_name = $field['field_name'];
      $entity->{$field_name}['und'][0]['value'] = $value;
    }

    $entities[$entity_id] = $entity;
  }
  return $entities;
}