template.node_join.views.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*************************************************************************
  3. * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
  4. *
  5. * - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
  6. * (ie: If you want to join features to their drupal nodes then XXX=feature)
  7. *
  8. * NOTE: Creating the table definition file is not enough. You also need to call the
  9. * retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
  10. * by adding the following line:
  11. * $data = array_merge($data, retrieve_XXX_views_data());
  12. * to the function and including the file directly above the function (blow the function
  13. * header by adding:
  14. * require_once('views/XXX.views.inc');
  15. *
  16. * REMOVE THIS COMMENT IN THE COPY!
  17. */
  18. /**
  19. * @file
  20. * This file defines the data array for a given chado table. This array
  21. * is merged into a larger array containing definitions of all tables associated
  22. * with this module in:
  23. * @see tripal_genetic.views.inc --in tripal_genetic_views_data()
  24. *
  25. * Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table.
  26. * This file simply defines this linking table and joins the three tables together.
  27. * No modification of XXX.views.inc is needed.
  28. *
  29. * Documentation on views integration can be found at
  30. * http://views2.logrus.com/doc/html/index.html.
  31. */
  32. /**
  33. * Purpose: this function returns the portion of the data array
  34. * which describes the chado_XXX drupal table, it's fields and any joins between it
  35. * and other tables
  36. * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
  37. *
  38. * The main need for description of this table to views is to join chado data with drupal nodes
  39. *
  40. */
  41. function retrieve_chado_XXX_views_data() {
  42. global $db_url;
  43. $data = array();
  44. // if the chado database is not local to the drupal database
  45. // then we need to set the database name. This should always
  46. // be 'chado'.
  47. if (is_array($db_url) and array_key_exists('chado', $db_url)) {
  48. // return empty data array b/c if chado is external then no join to the nodetable can be made
  49. return $data;
  50. }
  51. //Basic table definition-----------------------------------
  52. $data['chado_XXX']['table'] = array(
  53. 'field' => 'nid',
  54. );
  55. //Relationship Definitions---------------------------------
  56. // Note: No joins need to be made from $data['XXX']['table']
  57. // Join the chado_XXX table to XXX
  58. $data['chado_XXX']['table']['join']['XXX'] = array(
  59. 'left_field' => 'XXX_id',
  60. 'field' => 'XXX_id',
  61. );
  62. // Join the node table to chado_XXX
  63. $data['node']['table']['join']['chado_XXX'] = array(
  64. 'left_field' => 'nid',
  65. 'field' => 'nid',
  66. );
  67. // Join the node table to XXX
  68. $data['node']['table']['join']['XXX'] = array(
  69. 'left_table' => 'chado_XXX',
  70. 'left_field' => 'nid',
  71. 'field' => 'nid',
  72. );
  73. return $data;
  74. }