TripalTerm.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // Get the term description from the storage backend
  12. $this->definition = '';
  13. // TODO: we need some sort of administrative interface that lets the user
  14. // switch to the desired vocabulary type. For now, we'll just use the
  15. // first one in the list.
  16. $stores = module_invoke_all('vocab_storage_info');
  17. if (is_array($stores) and count($stores) > 0) {
  18. $keys = array_keys($stores);
  19. $module = $stores[$keys[0]]['module'];
  20. $function = $module . '_vocab_get_term';
  21. if (function_exists($function)) {
  22. $term_details = $function($vocab->namespace, $this->accession);
  23. $this->details = $term_details;
  24. if ($term_details and $term_details['definition']) {
  25. $this->definition = $term_details['definition'];
  26. }
  27. }
  28. }
  29. }
  30. protected function defaultLabel() {
  31. return $this->name;
  32. }
  33. protected function defaultUri() {
  34. $vocab = 'TODO';
  35. return array('path' => '/vocabulary/' . $vocab . '/term/' . $this->id);
  36. }
  37. public function getDefinition() {
  38. return '';
  39. }
  40. }