Tripal
Functions
Web Services

Functions

 hook_tripal_ws_value (&$items, $field, $instance)
 
 tripal_get_web_services ()
 
 tripal_load_include_web_service_class ($class)
 
 tripal_add_site ($name, $url, $version, $description)
 
 tripal_remove_site ($record_id)
 
 tripal_get_remote_content ($site_id, $path='', $query='')
 
 tripal_get_remote_context ($context_url, $cache_id)
 
 tripal_get_remote_content_context ($site_id, $context_url, $bundle_accession, $field_accession='')
 
 tripal_clear_remote_cache ($site_id)
 
 tripal_get_remote_API_doc ($site_id)
 
 tripal_load_remote_entities ($remote_entity_ids, $site_id, $bundle_accession, $field_ids)
 
 tripal_load_remote_entity ($remote_entity_id, $site_id, $bundle_accession, $field_ids)
 
 _tripal_update_remote_entity_field ($field_data, $context, $depth=0)
 
 tripal_get_remote_field_info ($site_id, $bundle_accession, $field_accession)
 
 tripal_get_remote_field_instance_info ($site_id, $bundle_accession, $field_accession)
 
 tripal_get_remote_content_doc ($site_id, $bundle_accession)
 
 tripal_get_remote_field_doc ($site_id, $bundle_accession, $field_accession)
 
 tripal_get_remote_field_formatters ($site_id, $bundle_accession, $field_accession)
 

Detailed Description

{@ The Tripal Web Services API provides a set of functions for interacting with the Tripal Web Services.

Function Documentation

◆ _tripal_update_remote_entity_field()

_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_dataThe field array as returned by web services.
$contextThe web service JSON-LD context for the bundle to which the field belongs.

◆ hook_tripal_ws_value()

hook_tripal_ws_value ( $items,
  $field,
  $instance 
)

Adjust the values of a field for display in web services.

This hook should be used sparingly. It is meant primarily to adjust 3rd Party (non Tripal) fields so that they work with web services. The caller should adjust the $items array as needed. This change only affects the value displayed in web services. Web services expect that every field have a 'value' element for each of the items. If a field for some reason does not have a 'value' element then this hook will allow setting of that element.

Parameters
$itemsThe list of items for the field.
$fieldThe field array.
$instanceThe field instance array.

◆ tripal_add_site()

tripal_add_site (   $name,
  $url,
  $version,
  $description 
)

Adds a new site to the web services table.

Parameters
$nameName of site to be included.
$urlURL of site to be added.
$versionVersion of the API being used. default to 1
$descriptionA description of the site and any additional info that would be helpful for admins.
Returns
TRUE if the site is successfully added, FALSE otherwise.

◆ tripal_clear_remote_cache()

tripal_clear_remote_cache (   $site_id)

Clears the cached remote site documentation and context.

When querying a remote website, the site's API documenation and page context is cached to make re-use of that information easier in the future. This function can be used to clear those caches.

Parameters
$site_idThe numeric site ID for the remote Tripal site.

◆ tripal_get_remote_API_doc()

tripal_get_remote_API_doc (   $site_id)

Retrieves the API documentation for a remote Tripal web service.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
Returns
The vocabulary of a remote Tripal web service, or FALSE if an error occured.

◆ tripal_get_remote_content()

tripal_get_remote_content (   $site_id,
  $path = '',
  $query = '' 
)

Makes a request to the "content" service of a remote Tripal web site.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$pathThe web service path for the content (excluding 'web-services/vX.x/content'). To retrieve the full content listing leave this paramter empty.
$queryAn query string to appear after the ? in a URL.
Returns
The JSON response formatted in a PHP array or FALSE if a problem occured.

◆ tripal_get_remote_content_context()

tripal_get_remote_content_context (   $site_id,
  $context_url,
  $bundle_accession,
  $field_accession = '' 
)

Retrieves the JSON-LD context for a bundle or field on a remote Tripal site.

The $site_id, $bundle_accession and $field_accession variables are not needed to retrieve the context, but are used for caching the context to make subsequent calls execute faster. This function is meant to be used only for the 'content' service provided by Tripal.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$context_urlThe Full URL for the context file on the remote Tripal site. This URL can be found in the '@context' key of any response from a remote Tripal web services call.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_accessionThe controlled vocabulary term accession for the property (i.e. field) of the Class (i.e. content type).
Returns
The JSON-LD context mapping array.

◆ tripal_get_remote_content_doc()

tripal_get_remote_content_doc (   $site_id,
  $bundle_accession 
)

Retreive the content type information from a remote Tripal site.

The array returned is equivalent to the Hydra Vocabulary "supportedClass" stanza.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
Returns
A PHP array corresponding to the Hydra Class stanza (i.e. a content type). Returns NULL if the class ID cannot be found.

◆ tripal_get_remote_context()

tripal_get_remote_context (   $context_url,
  $cache_id 
)

Retrieves the JSON-LD context for any remote Tripal web service.

Parameters
$context_urlThe Full URL for the context file on the remote Tripal site. This URL can be found in the '@context' key of any response from a remote Tripal web services call.
$cache_idA unique ID for caching of this context result to speed furture queries.
Returns
The JSON-LD context mapping array, or FALSE if the context could not be retrieved.

◆ tripal_get_remote_field_doc()

tripal_get_remote_field_doc (   $site_id,
  $bundle_accession,
  $field_accession 
)

Retrieves the field information for a content type from a remote Tripal site.

The array returned is equivalent to the Hydra Vocabulary "supportedProperty" stanza that belongs to a Hydra Class (content type).

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_accessionThe controlled vocabulary term accession for the property (i.e. field) of the Class (i.e. content type).
Returns
A PHP array corresponding to the Hydra property stanza (field) that belongs to the given Class (i.e. a content type). Retruns NULL if the property cannot be found.

◆ tripal_get_remote_field_formatters()

tripal_get_remote_field_formatters (   $site_id,
  $bundle_accession,
  $field_accession 
)

Retrieves the list of download formatters for a remote field.

All Tripal fields support the abilty for inclusion in files that can downloaded. This function is used to identify what formatters these fields are appropriate for. If those download formatter classes exist on this site then the field can be used with that formatter.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_accessionThe controlled vocabulary term accession for the property (i.e. field) of the Class (i.e. content type).
Returns
An array of field downloader class names that are compoatible with the field and which exist on this site.

◆ tripal_get_remote_field_info()

tripal_get_remote_field_info (   $site_id,
  $bundle_accession,
  $field_accession 
)

Behaves similar to the field_info_field() function but for remote fields.

Returns a "fake" field info array for fields attached to content types on remote Tripal sites.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_accessionThe controlled vocabulary term accession for the property (i.e. field) of the Class (i.e. content type).
Returns
An array similar to that returned by the field_info_field function of Drupal for local fields.

◆ tripal_get_remote_field_instance_info()

tripal_get_remote_field_instance_info (   $site_id,
  $bundle_accession,
  $field_accession 
)

Behaves similar to the field_info_instance() function but for remote fields.

Returns a "fake" instance info array for fields attached to content types on remote Tripal sites.

Parameters
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_accessionThe controlled vocabulary term accession for the property (i.e. field) of the Class (i.e. content type).
Returns
An array similar to that returned by the field_info_instance function of Drupal for local fields.

◆ tripal_get_web_services()

tripal_get_web_services ( )

Retrieves a list of TripalWebService implementations.

The TripalWebService classes can be added by a site developer that wishes to create a new Tripal compatible web serivce. The class file should be placed in the [module]/includes/TripalWebService directory. Tripal will support any service as long as it is in this directory and extends the TripalWebService class.

Returns
A list of TripalWebService names.

◆ tripal_load_include_web_service_class()

tripal_load_include_web_service_class (   $class)

Loads the TripalWebService class file into scope.

Parameters
$classThe TripalWebService class to include.
Returns
TRUE if the field type class file was found, FALSE otherwise.

◆ tripal_load_remote_entities()

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_idsArray of the remote ids.
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_idsThe 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.
Returns
An array of fake entity objects where the key is the entity_id and the value is the object.

◆ tripal_load_remote_entity()

tripal_load_remote_entity (   $remote_entity_id,
  $site_id,
  $bundle_accession,
  $field_ids 
)

Queries a remote site for an entity.

This function returns a "fake" entity containing values for all fields specified.

Parameters
$remote_entity_idA remote entity ID.
$site_idThe numeric site ID for the remote Tripal site.
$bundle_accessionThe controlled vocabulary term accession for the content type on the remote Tripal site.
$field_idsThe 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.
Returns
A fake entity object.

◆ tripal_remove_site()

tripal_remove_site (   $record_id)

Remove a site from the web services table.

Parameters
$record_idID of the record to be deleted.
Returns
TRUE if the record was successfully deleted, FALSE otherwise.