chado_views_handler_relationship_to_node.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 & chado_table join
  28. unset($this->query->table_queue['node'],
  29. $this->query->tables['stock']['node'],
  30. $this->query->table_queue[$chado_table],
  31. $this->query->tables['stock'][$chado_table]);
  32. // First add base => chado_base join
  33. $def = array();
  34. $def['table'] = $chado_table;
  35. $def['field'] = $base_field;
  36. $def['left_table'] = $base_table;
  37. $def['left_field'] = $base_field;
  38. //$def['handler'] = 'views_handler_join_chado_aggregator';
  39. $join = new views_join();
  40. $join->definition = $def;
  41. $join->construct();
  42. $join->adjusted = TRUE;
  43. $alias = $base_table . '_' . $chado_table;
  44. $this->linker_alias = $this->query->add_relationship($alias, $join, $this->table);
  45. // Now add chado_base => node join
  46. $def = array();
  47. $def['table'] = 'node';
  48. $def['field'] = 'nid';
  49. $def['left_table'] = $this->linker_alias;
  50. $def['left_field'] = 'nid';
  51. //$def['handler'] = 'views_handler_join_chado_aggregator';
  52. $join = new views_join();
  53. $join->definition = $def;
  54. $join->construct();
  55. $join->adjusted = TRUE;
  56. if ($base_table == $this->view->base_table) {
  57. $alias = 'node';
  58. }
  59. else {
  60. $alias = $chado_table . '_node';
  61. }
  62. $this->alias = $this->query->add_relationship($alias, $join, 'node');
  63. }
  64. }