TripalTerm.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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->urlprefix = 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->namespace, $this->accession);
  25. $this->details = $term_details;
  26. if ($term_details and $term_details['definition']) {
  27. $this->definition = $term_details['definition'];
  28. $this->urlprefix = $term_details['urlprefix'];
  29. }
  30. }
  31. }
  32. }
  33. protected function defaultLabel() {
  34. return $this->name;
  35. }
  36. protected function defaultUri() {
  37. $vocab = 'TODO';
  38. return array('path' => '/vocabulary/' . $vocab . '/term/' . $this->id);
  39. }
  40. public function getDefinition() {
  41. return '';
  42. }
  43. }