TripalTerm.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * A class the controller will use for instantiating the TripalTerm entity.
  4. */
  5. class TripalTerm extends Entity {
  6. public function __construct($values = array()) {
  7. parent::__construct($values, 'TripalTerm');
  8. // Get the vocabulary for this term
  9. $vocab = entity_load('TripalVocab', array('id' => $this->vocab_id));
  10. $vocab = reset($vocab);
  11. $this->vocab = $vocab;
  12. // Get the term description from the storage backend
  13. $this->definition = NULL;
  14. $this->url = NULL;
  15. // TODO: we need some sort of administrative interface that lets the user
  16. // switch to the desired vocabulary type. For now, we'll just use the
  17. // first one in the list.
  18. $stores = module_invoke_all('vocab_storage_info');
  19. if (is_array($stores) and count($stores) > 0) {
  20. $keys = array_keys($stores);
  21. $module = $stores[$keys[0]]['module'];
  22. $function = $module . '_vocab_get_term';
  23. if (function_exists($function)) {
  24. $term_details = $function($vocab->vocabulary, $this->accession);
  25. if ($term_details) {
  26. // $this->details = $term_details;
  27. if ($term_details and $term_details['definition']) {
  28. $this->definition = $term_details['definition'];
  29. $this->url = $term_details['url'];
  30. }
  31. }
  32. }
  33. }
  34. }
  35. protected function defaultLabel() {
  36. return $this->name;
  37. }
  38. protected function defaultUri() {
  39. $vocab = 'TODO';
  40. return array('path' => '/vocabulary/' . $vocab . '/term/' . $this->id);
  41. }
  42. // Getters //
  43. public function getName() {
  44. return $this->name;
  45. }
  46. public function getAccession() {
  47. return $this->name;
  48. }
  49. public function getDefinition() {
  50. return $this->definition;
  51. }
  52. public function getURL() {
  53. return $this->url;
  54. }
  55. public function getVocab() {
  56. return $this->vocab;
  57. }
  58. public function getID() {
  59. return $this->id;
  60. }
  61. }