function tripal_load_term_entity

3.x tripal.entities.api.inc tripal_load_term_entity($values)

Retrieves a TripalTerm entity that matches the given arguments.

Parameters

$values: An associative array used to match a term. Valid keys may be:

  • vocabulary: Must always be used with accession to uniquely identify a term.
  • accession: Must always be used with vocabulary to uniquely identify a term.
  • term_id: Can be used alone to uniquely identify a term.

Return value

A TripalTerm entity object or NULL if not found.

Related topics

22 calls to tripal_load_term_entity()
chado_migrate_tripal_content_type in tripal_chado/api/tripal_chado.migrate.api.inc
Migrate Tripal content types
TripalBundle::__construct in tripal/includes/TripalBundle.inc
tripal_admin_add_type_form_submit in tripal/includes/TripalBundleUIController.inc
Implements hook_submit() for the tripal_admin_add_type_form.
tripal_bundle_default_views in tripal/tripal.views_default.inc
tripal_chado_bundle_create in tripal_chado/includes/tripal_chado.bundle.inc

... See full list

File

tripal/api/tripal.entities.api.inc, line 253
Provides an application programming interface (API) for working with TripalEntity content types (bundles) and their entities.

Code

function tripal_load_term_entity($values) {
  $vocabulary = array_key_exists('vocabulary', $values) ? $values['vocabulary'] : '';
  $accession = array_key_exists('accession', $values) ? $values['accession'] : '';
  $term_id = array_key_exists('term_id', $values) ? $values['term_id'] : '';

  $term = NULL;

  if ($vocabulary and $accession) {
    $query = db_select('tripal_term', 'tt');
    $query->join('tripal_vocab', 'tv', 'tv.id = tt.vocab_id');
    $query->fields('tt', array('id'))
      ->fields('tv', array('vocabulary'))
      ->condition('tv.vocabulary', $vocabulary)
      ->condition('tt.accession', $accession);
    $term = $query->execute()->fetchObject();
  }
  else if ($term_id) {
    $query = db_select('tripal_term', 'tt');
    $query->fields('tt', array('id'))
      ->condition('tt.id', $term_id);
    $term = $query->execute()->fetchObject();
  }

  if ($term) {
    $entity = entity_load('TripalTerm', array($term->id));
    return reset($entity);
  }
  return NULL;
}