chado_feature.views.inc 2.9 KB

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