TripalEntity.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. $bundle_id = $this->bundle;
  9. $bundle = db_select('tripal_bundle', 'tb')
  10. ->fields('tb')
  11. ->condition('bundle', $bundle_id)
  12. ->execute()
  13. ->fetchObject();
  14. $data = unserialize($bundle->data);
  15. $this->chado_table = $data['data_table'];
  16. $this->chado_field = $data['field'];
  17. // If we have an ID then this entity has been saved and it will
  18. // also therefore have a chado_entity record. We want to
  19. // load this record so it is always part of the entity object.
  20. if (property_exists($this, 'id') and $this->id) {
  21. $details = db_select('chado_entity', 'ce')
  22. ->fields('ce')
  23. ->condition('entity_id', $this->id)
  24. ->execute()
  25. ->fetchObject();
  26. // Add the chado entity details to the entity in case it's needed
  27. // downstream (e.g. in field widget construction).
  28. $this->chado_entity_id = $details->chado_entity_id;
  29. // Add in the record.
  30. $schema = chado_get_schema($this->chado_table);
  31. $pkey = $schema['primary key'][0];
  32. $this->chado_record_id = $details->record_id;
  33. $this->chado_record = chado_generate_var($this->chado_table, array($pkey =>+ $details->record_id));
  34. }
  35. }
  36. protected function defaultLabel() {
  37. return $this->title;
  38. }
  39. protected function defaultUri() {
  40. return array('path' => 'TripalEntity/' . $this->id);
  41. }
  42. }