chado_views_handler_relationship_to_node.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // First add base => chado_base join
  23. $def = array();
  24. $def['table'] = 'chado_' . $this->table;
  25. $def['field'] = $this->field;
  26. $def['left_table'] = $this->table;
  27. $def['left_field'] = $this->field;
  28. //$def['handler'] = 'views_handler_join_chado_aggregator';
  29. $join = new views_join();
  30. $join->definition = $def;
  31. $join->construct();
  32. $join->adjusted = TRUE;
  33. $this->linker_alias = $this->query->add_relationship('stock_chado_stock', $join, $this->table);
  34. // Now add chado_base => node join
  35. $def = array();
  36. $def['table'] = 'node';
  37. $def['field'] = 'nid';
  38. $def['left_table'] = $this->linker_alias;
  39. $def['left_field'] = 'nid';
  40. //$def['handler'] = 'views_handler_join_chado_aggregator';
  41. $join = new views_join();
  42. $join->definition = $def;
  43. $join->construct();
  44. $join->adjusted = TRUE;
  45. $this->alias = $this->query->add_relationship('chado_stock_node', $join, 'node');
  46. }
  47. }