protected function TripalWebService::getContextTerm

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

Converts a term array into an value appropriate for an @id or @type.

Parameters

$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).

2 calls to TripalWebService::getContextTerm()
TripalContentService_v0_1::addEntityFields in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Adds the fields as properties of an entity resource.
TripalWebService::addContextTerm in tripal_ws/includes/TripalWebService.inc
Adds a term to the '@context' section for a given resource.

File

tripal_ws/includes/TripalWebService.inc, line 591

Class

TripalWebService

Code

protected function getContextTerm($term, $sanitize = array()) {
  if (!$term) {
    $backtrace = debug_backtrace();
    throw new Exception('getContextTerm: Please provide a non NUll or non empty $term.');

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

  $key = $term['name'];
  $key_adj = $key;
  if (in_array('spacing', $sanitize)) {
    $key_adj = preg_replace('/ /', '_', $key_adj);
  }
  if (in_array('lowercase', $sanitize)) {
    $key_adj = strtolower($key_adj);
  }
  return $key_adj;
}