public function obi__organism::load

3.x obi__organism.inc public obi__organism::load($entity)

Overrides TripalField::load

See also

TripalField::load()

File

tripal_chado/includes/TripalFields/obi__organism/obi__organism.inc, line 84

Class

obi__organism

Code

public function load($entity) {

  $record = $entity->chado_record;
  $settings = $this->instance['settings'];

  $field_name = $this->field['field_name'];
  $field_type = $this->field['type'];
  $field_table = $this->instance['settings']['chado_table'];
  $field_column = $this->instance['settings']['chado_column'];

  // Get the terms for each of the keys for the 'values' property.
  $label_term = 'rdfs:label';
  $genus_term = chado_get_semweb_term('organism', 'genus');
  $species_term = chado_get_semweb_term('organism', 'species');
  $infraspecific_name_term = chado_get_semweb_term('organism', 'infraspecific_name');
  $infraspecific_type_term = chado_get_semweb_term('organism', 'type_id');


  // Set the linker field appropriately.
  if ($field_table == 'biomaterial') {
    $linker_field = 'chado-biomaterial__taxon_id';
  }
  else {
    $linker_field = 'chado-' . $field_table . '__organism_id';
  }

  // Set some defaults for the empty record.
  $entity->{$field_name}['und'][0] = array(
    'value' => array(),
  );

  if ($record) {
    if ($field_table == 'biomaterial') {
      $organism = $record->taxon_id;
    }
    else {
      $organism = $record->organism_id;
    }
    $string = $settings['field_display_string'];
    $label = chado_replace_tokens($string, $organism);
    $entity->{$field_name}['und'][0]['value'] = array(
      $label_term => $label,
      $genus_term => $organism->genus,
      $species_term => $organism->species,
    );
    // The infraspecific fields were introduced in Chado v1.3.
    if (property_exists($organism, 'infraspecific_name')) {
      $entity->{$field_name}['und'][0]['value'][$infraspecific_type_term] = NULL;
      $entity->{$field_name}['und'][0]['value'][$infraspecific_name_term] = $organism->infraspecific_name;
      if ($organism->type_id) {
        $entity->{$field_name}['und'][0]['value'][$infraspecific_type_term] = $organism->type_id->name;
      }
    }
    $entity->{$field_name}['und'][0][$linker_field] = $organism->organism_id;

    // Is there a published entity for this organism?
    if (property_exists($record->{$field_column}, 'entity_id')) {
      $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
    }
  }
}