chado_stock.views.inc 2.9 KB

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