chado_stock.views.inc 2.9 KB

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