TripalEntity.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * A class the controller will use for instantiating the TripalEntity entity.
  4. */
  5. class TripalEntity extends Entity {
  6. public function __construct($values = array(), $entity_type) {
  7. parent::__construct($values, $entity_type);
  8. // If we have an ID then this entity has been saved and it will
  9. // also therefore have a chado_entity record. We want to
  10. // load this record so it is always part of the entity object.
  11. if (property_exists($this, 'id') and $this->id) {
  12. $details = db_select('chado_entity', 'ce')
  13. ->fields('ce')
  14. ->condition('entity_id', $this->id)
  15. ->execute()
  16. ->fetchObject();
  17. // Add the chado entity details to the entity in case it's needed
  18. // downstream (e.g. in field widget construction).
  19. $this->chado_entity_id = $details->chado_entity_id;
  20. $this->chado_table = $details->data_table;
  21. $this->chado_field = $details->field;
  22. // Add in the record.
  23. $schema = chado_get_schema($this->chado_table);
  24. $pkey = $schema['primary key'][0];
  25. $this->chado_record_id = $details->record_id;
  26. $this->chado_record = chado_generate_var($this->chado_table, array($pkey =>+ $details->record_id));
  27. }
  28. // If we do not have an ID then we need to do a few queries to get
  29. // information about the chado table this entity maps to.
  30. else {
  31. // Use the cvterm_id to look up the base table for this term. We find
  32. // the base table by looking in the term_usage table for the mapping.
  33. $sel_values = array(
  34. 'term_id' => array(
  35. 'cvterm_id' => $this->cvterm_id,
  36. ),
  37. );
  38. $term_usage = chado_generate_var('tripal_term_usage', $sel_values, array('return_array' => 1));
  39. // For each table that uses this term, insert the field recursively
  40. foreach ($term_usage as $usage) {
  41. $this->chado_table = $usage->data_table;
  42. $this->chado_field = $usage->field;
  43. }
  44. }
  45. }
  46. protected function defaultLabel() {
  47. return $this->title;
  48. }
  49. protected function defaultUri() {
  50. return array('path' => 'BioData/' . $this->id);
  51. }
  52. }