function _tripal_update_remote_entity_field

3.x tripal_ws.api.inc _tripal_update_remote_entity_field($field_data, $context, $depth = 0)

A helper function for the tripal_get_remote_entity() function.

This function converts the field's key elements to their vocabulary term accessions.

Parameters

$field_data: The field array as returned by web services.

$context: The web service JSON-LD context for the bundle to which the field belongs.

Related topics

2 calls to _tripal_update_remote_entity_field()
tripal_load_remote_entities in tripal_ws/api/tripal_ws.api.inc
Queries a remote site for an array of bulk entity ids.
tripal_load_remote_entity in tripal_ws/api/tripal_ws.api.inc
Queries a remote site for an entity.

File

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

Code

function _tripal_update_remote_entity_field($field_data, $context, $depth = 0) {


  // Check if this is an array.
  if ($field_data['@type'] == 'Collection') {
    $members = array();
    foreach ($field_data['member'] as $member) {
      $next_depth = $depth + 1;
      $members[] = _tripal_update_remote_entity_field($member, $context, $next_depth);
    }

    // If we only have one item then just return it as a single item.
    // TODO: we may need to check cardinality of the field and be more
    // strict about how we return the value.
    if ($field_data['totalItems'] == 1) {
      return $members[0];
    }
    else {
      return $members;
    }
  }

  $value = array();
  foreach ($field_data as $k => $v) {
    // Skip the JSON-LD keys.
    if ($k == '@id' or $k == '@type' or $k == '@context') {
      continue;
    }
    // Find the term accession for this element, and if the key's value is an
    // array then recurse.
    $accession = $context[$k];
    if (is_array($v)) {
      $next_depth = $depth + 1;
      $subvalue = _tripal_update_remote_entity_field($v, $context, $next_depth);
      $value[$accession] = $subvalue;
    }
    else {
      $value[$accession] = $v;
    }
  }
  return $value;

}