chado_library.views.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Purpose: this function returns the portion of the data array
  5. * which describes the chado_library drupal table, it's fields and any joins between it and other tables
  6. * @see tripal_library_views_data() --in tripal_library.views.inc
  7. *
  8. * The main need for description of this table to views is to join chado data with drupal nodes
  9. *
  10. * @ingroup tripal_library_views
  11. */
  12. function retrieve_chado_library_views_data() {
  13. global $db_url;
  14. $data = array();
  15. // if the chado database is not local to the drupal database
  16. // then we need to set the database name. This should always
  17. // be 'chado'.
  18. if (is_array($db_url) and array_key_exists('chado', $db_url)) {
  19. // return empty data array b/c if chado is external then no join to the nodetable can be made
  20. return $data;
  21. }
  22. // Basic table definition
  23. $data['chado_library']['table'] = array(
  24. 'field' => 'nid',
  25. 'group' => 'Chado Library'
  26. );
  27. $data['chado_library']['nid'] = array(
  28. 'title' => t('Library Node ID'),
  29. 'help' => t('The node ID for this library'),
  30. 'field' => array(
  31. 'handler' => 'views_handler_field_numeric',
  32. 'click sortable' => TRUE,
  33. ),
  34. 'filter' => array(
  35. 'handler' => 'views_handler_filter_numeric',
  36. ),
  37. 'sort' => array(
  38. 'handler' => 'views_handler_sort',
  39. ),
  40. );
  41. // Note: No joins need to be made from $data['library']['table']
  42. // Join the chado library table to library
  43. $data['chado_library']['table']['join']['library'] = array(
  44. 'left_field' => 'library_id',
  45. 'field' => 'library_id',
  46. );
  47. // Join the node table to chado library
  48. $data['node']['table']['join']['chado_library'] = array(
  49. 'left_field' => 'nid',
  50. 'field' => 'nid',
  51. );
  52. // Join the node table to library
  53. $data['node']['table']['join']['library'] = array(
  54. 'left_table' => 'chado_library',
  55. 'left_field' => 'nid',
  56. 'field' => 'nid',
  57. );
  58. // Add relationship between chado_library and library
  59. $data['chado_library']['library_nid'] = array(
  60. 'group' => 'Library',
  61. 'title' => 'Library Node',
  62. 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
  63. 'real field' => 'library_id',
  64. 'relationship' => array(
  65. 'handler' => 'views_handler_relationship',
  66. 'title' => t('Chado => Library'),
  67. 'label' => t('Chado => Library'),
  68. 'real field' => 'library_id',
  69. 'base' => 'library',
  70. 'base field' => 'library_id'
  71. ),
  72. );
  73. // Add node relationship to library
  74. $data['chado_library']['library_chado_nid'] = array(
  75. 'group' => 'Library',
  76. 'title' => 'Library Node',
  77. 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
  78. 'real field' => 'nid',
  79. 'relationship' => array(
  80. 'handler' => 'views_handler_relationship',
  81. 'title' => t('Chado => Node'),
  82. 'label' => t('Chado => Node'),
  83. 'real field' => 'nid',
  84. 'base' => 'node',
  85. 'base field' => 'nid'
  86. ),
  87. );
  88. return $data;
  89. }