chado_stock.views.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Node',
  27. );
  28. // Note: No joins need to be made from $data['stock']['table']
  29. // Join the chado stock table to stock
  30. $data['chado_stock']['table']['join']['stock'] = array(
  31. 'left_field' => 'stock_id',
  32. 'field' => 'stock_id',
  33. );
  34. // Join the node table to chado stock
  35. $data['node']['table']['join']['chado_stock'] = array(
  36. 'left_field' => 'nid',
  37. 'field' => 'nid',
  38. );
  39. // Join the node table to stock
  40. $data['node']['table']['join']['stock'] = array(
  41. 'left_table' => 'chado_stock',
  42. 'left_field' => 'nid',
  43. 'field' => 'nid',
  44. );
  45. // Add relationship between chado_stock and stock
  46. $data['chado_stock']['stock_nid'] = array(
  47. 'group' => 'Stock',
  48. 'title' => 'Stock Node',
  49. 'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
  50. 'real field' => 'stock_id',
  51. 'relationship' => array(
  52. 'handler' => 'views_handler_relationship',
  53. 'title' => t('Chado => Stock'),
  54. 'label' => t('Chado => Stock'),
  55. 'real field' => 'stock_id',
  56. 'base' => 'stock',
  57. 'base field' => 'stock_id'
  58. ),
  59. );
  60. // Add node relationship to stock
  61. $data['chado_stock']['stock_chado_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' => 'nid',
  66. 'relationship' => array(
  67. 'handler' => 'views_handler_relationship',
  68. 'title' => t('Chado => Node'),
  69. 'label' => t('Chado => Node'),
  70. 'real field' => 'nid',
  71. 'base' => 'node',
  72. 'base field' => 'nid'
  73. ),
  74. );
  75. return $data;
  76. }