protected function TripalWebService::addContextTerm

3.x TripalWebService.inc protected TripalWebService::addContextTerm($resource, $term, $sanitize = array())

Adds a term to the '@context' section for a given resource.

Parameters

$resource: A TripalWebServiceResource instance.

$term: The term array.

$santize: An array of keywords indicating how to santize the key. By default, no sanitizing occurs. The two valid types are 'lowercase', and 'spacing' where 'lowercase' converts the term name to all lowercase and 'spacing' replaces any spaces with underscores.

Return value

The id (the term name but with spaces replaced with underscores).

3 calls to TripalWebService::addContextTerm()
TripalContentService_v0_1::sanitizeFieldKeys in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Rewrites the keys of a field's items array for use with web services.
TripalWebService::addResourceProperty in tripal_ws/includes/TripalWebService.inc
Adds a key/value property to the given resource.
TripalWebService::setResourceType in tripal_ws/includes/TripalWebService.inc
Sets the type for the given resource.

File

tripal_ws/includes/TripalWebService.inc, line 626

Class

TripalWebService

Code

protected function addContextTerm($resource, $term, $sanitize = array()) {
  if (!is_a($resource, 'TripalWebServiceResource')) {
    throw new Exception('addContextTerm: Please provide a $resource of type TripalWebServiceResource.');
  }

  if (!$term) {
    $backtrace = debug_backtrace();
    throw new Exception('addContextTerm: Please provide a non NUll or non empty $term.');

  }
  if (!$term['name']) {
    throw new Exception('addContextTerm: The provided term does not have a name: ' . print_r($term, TRUE));
  }

  // Make sure the vocab is present
  $vocab = $term['vocabulary'];
  $this->addContextVocab($resource, $vocab);

  // Sanitize the term key
  $key_adj = $this->getContextTerm($term, $sanitize);

  // Create the compact IRI
  $compact_iri = $vocab['short_name'] . ':' . $term['accession'];

  // If the full naming is indicated in the service parameters then
  // set the full name of the keys to include the vocab short name.
  if (array_key_exists('full_keys', $this->params)) {
    //$key_adj = $vocab['short_name'] . ':' . $key_adj;
  }

  $iri = $term['url'];

  $resource->addContextItem($key_adj, $compact_iri);
  $resource->addContextItem($compact_iri, $iri);

  return $key_adj;
}