views_handler_field_cvterm_name.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup views_field_handlers
  5. * @ingroup tripal_core
  6. */
  7. class views_handler_field_cvterm_name extends views_handler_field {
  8. /**
  9. * Add join to the cvterm table and cvterm.name field to the query
  10. */
  11. function query() {
  12. // if this table isn't a base table
  13. // if it is this can be done by describing a join between base table and cvterm
  14. if (!preg_match('/^' . $this->view->base_table . '$/', $this->table)) {
  15. //Want to add join: LEFT JOIN cvterm nd_experimentprop_cvterm ON nd_experimentprop.type_id = nd_experimentprop_cvterm.cvterm_id
  16. //===============================================================
  17. $this->query->ensure_table($this->table);
  18. // add to table_queue--------------------------------------------
  19. $cvterm_join['table'] = 'cvterm';
  20. $cvterm_join['num'] = 1;
  21. $cvterm_join['alias'] = $this->table . '_cvterm';
  22. $cvterm_join['relationship'] = $this->table;
  23. $cvterm_join['join'] = clone($this->query->table_queue[$this->table]['join']);
  24. $cvterm_join['join']->table = 'cvterm';
  25. $cvterm_join['join']->field = 'cvterm_id';
  26. $cvterm_join['join']->left_table = $this->table;
  27. $cvterm_join['join']->left_field = 'type_id';
  28. $cvterm_join['join']->definition['table'] = 'cvterm';
  29. $cvterm_join['join']->definition['field'] = 'cvterm_id';
  30. $cvterm_join['join']->definition['left_table'] = $this->table;
  31. $cvterm_join['join']->definition['left_field'] = 'type_id';
  32. $this->query->table_queue[$cvterm_join['alias']] = $cvterm_join;
  33. // add to table--------------------------------------------------
  34. $this->query->tables[$this->view->base_table][$this->table . '_cvterm'] = array(
  35. 'count' => 1,
  36. 'alias' => $this->table . '_cvterm',
  37. );
  38. //Want to add field: nd_experimentprop_cvterm.name as nd_experimentprop_type
  39. //===============================================================
  40. $field_alias = $this->table . '_cvterm_name';
  41. $this->query->add_field($this->table . '_cvterm', 'name');
  42. $this->add_additional_fields();
  43. $this->aliases['name'] = $field_alias;
  44. }
  45. }
  46. /**
  47. * Ensure that the type/cvterm name is rendered
  48. */
  49. function render($values) {
  50. return $values->{$this->aliases['name']};
  51. }
  52. }