views_handler_field_cvterm_name.inc 2.3 KB

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