chado_views_handler_relationship_to_node.inc 2.5 KB

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