chado_project.views.inc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * This file defines the data array for a given chado table. This array
  5. * is merged into a larger array containing definitions of all tables associated
  6. * with this module in:
  7. * @see tripal_project.views.inc --in tripal_project_views_data()
  8. *
  9. * Note: All chado tables are joined to their drupal nodes through the chado_project linking table.
  10. * This file simply defines this linking table and joins the three tables together.
  11. * No modification of project.views.inc is needed.
  12. *
  13. * Documentation on views integration can be found at
  14. * http://views2.logrus.com/doc/html/index.html.
  15. */
  16. /**
  17. * Purpose: this function returns the portion of the data array
  18. * which describes the chado_project drupal table, it's fields and any joins between it
  19. * and other tables
  20. * @see tripal_project_views_data() --in tripal_project.views.inc
  21. *
  22. * The main need for description of this table to views is to join chado data with drupal nodes
  23. *
  24. */
  25. function retrieve_chado_project_views_data() {
  26. global $db_url;
  27. $data = array();
  28. // if the chado database is not local to the drupal database
  29. // then we need to set the database name. This should always
  30. // be 'chado'.
  31. if (is_array($db_url) and array_key_exists('chado', $db_url)) {
  32. // return empty data array b/c if chado is external then no join to the nodetable can be made
  33. return $data;
  34. }
  35. //Basic table definition-----------------------------------
  36. $data['chado_project']['table'] = array(
  37. 'field' => 'nid',
  38. );
  39. //Relationship Definitions---------------------------------
  40. // Note: No joins need to be made from $data['project']['table']
  41. // Join the chado_project table to project
  42. $data['chado_project']['table']['join']['project'] = array(
  43. 'left_field' => 'project_id',
  44. 'field' => 'project_id',
  45. );
  46. // Join the node table to chado_project
  47. $data['node']['table']['join']['chado_project'] = array(
  48. 'left_field' => 'nid',
  49. 'field' => 'nid',
  50. );
  51. // Join the node table to project
  52. $data['node']['table']['join']['project'] = array(
  53. 'left_table' => 'chado_project',
  54. 'left_field' => 'nid',
  55. 'field' => 'nid',
  56. );
  57. // Add relationship between chado_project and project
  58. $data['chado_project']['project_nid'] = array(
  59. 'group' => 'project',
  60. 'title' => 'Project Node',
  61. 'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
  62. 'real field' => 'project_id',
  63. 'relationship' => array(
  64. 'handler' => 'views_handler_relationship',
  65. 'title' => t('Chado => Project'),
  66. 'label' => t('Chado => Project'),
  67. 'real field' => 'project_id',
  68. 'base' => 'project',
  69. 'base field' => 'project_id'
  70. ),
  71. );
  72. // Add node relationship to project
  73. $data['chado_project']['project_chado_nid'] = array(
  74. 'group' => 'project',
  75. 'title' => 'Project Node',
  76. 'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
  77. 'real field' => 'nid',
  78. 'relationship' => array(
  79. 'handler' => 'views_handler_relationship',
  80. 'title' => t('Chado => Node'),
  81. 'label' => t('Chado => Node'),
  82. 'real field' => 'nid',
  83. 'base' => 'node',
  84. 'base field' => 'nid'
  85. ),
  86. );
  87. return $data;
  88. }