chado_views_handler_relationship_to_node.inc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Relationship handler that links a chado table to it's nodes by creating 2 joins.
  4. *
  5. * NOTE: This handler assumes if you are linking TABLEA to it's nodes that there is a
  6. * table named chado_TABLEA in the drupal schema with at least the following two fields:
  7. * nid and TABLEA_id.
  8. *
  9. * Definition items:
  10. * - base: The new base table this relationship will be adding. This does not
  11. * have to be a declared base table, but if there are no tables that
  12. * utilize this base table, it won't be very effective.
  13. * - base field: The field to use in the relationship; if left out this will be
  14. * assumed to be the primary field.
  15. * - label: The default label to provide for this relationship, which is
  16. * shown in parentheses next to any field/sort/filter/argument that uses
  17. * the relationship.
  18. */
  19. class chado_views_handler_relationship_to_node extends views_handler_relationship {
  20. function query() {
  21. $this->ensure_my_table();
  22. // The base table in chado
  23. $base_table = $this->definition['base table'];
  24. $base_field = $this->definition['base field'];
  25. // The drupal linking table
  26. $chado_table = 'chado_' . $base_table;
  27. // Need to remove the incorrectly added node join
  28. unset($this->query->table_queue['node'],
  29. $this->query->tables['stock']['node']);
  30. // First add base => chado_base join
  31. $def = array();
  32. $def['table'] = $chado_table;
  33. $def['field'] = $base_field;
  34. $def['left_table'] = $base_table;
  35. $def['left_field'] = $base_field;
  36. //$def['handler'] = 'views_handler_join_chado_aggregator';
  37. $join = new views_join();
  38. $join->definition = $def;
  39. $join->construct();
  40. $join->adjusted = TRUE;
  41. $alias = $base_table . '_' . $chado_table;
  42. $this->linker_alias = $this->query->add_relationship($alias, $join, $this->table);
  43. // Now add chado_base => node join
  44. $def = array();
  45. $def['table'] = 'node';
  46. $def['field'] = 'nid';
  47. $def['left_table'] = $this->linker_alias;
  48. $def['left_field'] = 'nid';
  49. //$def['handler'] = 'views_handler_join_chado_aggregator';
  50. $join = new views_join();
  51. $join->definition = $def;
  52. $join->construct();
  53. $join->adjusted = TRUE;
  54. if ($base_table == $this->view->base_table) {
  55. $alias = 'node';
  56. }
  57. else {
  58. $alias = $chado_table . '_node';
  59. }
  60. $this->alias = $this->query->add_relationship($alias, $join, 'node');
  61. }
  62. }