tripal_views_integration.views.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. function tripal_views_integration_views_data(){
  3. //this gets rebuild on cache clear
  4. /*
  5. * note on fields: the handlers must be able to handle the type of the field
  6. * may be an issue without validation of data entry:
  7. * how the user associated fields with which handlers.
  8. */
  9. /*
  10. $data['go_count_organism']['table']['group'] = t('go count organism');
  11. $data['go_count_organism']['table']['base'] = array(
  12. 'field' => 'cvterm_id',
  13. 'title' => t('go count organism table'),
  14. 'help' => t("go count organism table contains mview data."), //garbage explanation for now
  15. );
  16. $data['go_count_organism']['cvname'] = array(
  17. 'title' => t('cvname text field'),
  18. 'help' => t(' text field.'),
  19. 'field' => array(
  20. 'handler' => 'views_handler_field',
  21. 'click sortable' => TRUE,
  22. ),
  23. 'sort' => array(
  24. 'handler' => 'views_handler_sort',
  25. ),
  26. 'filter' => array(
  27. 'handler' => 'views_handler_filter_string',
  28. ),
  29. 'argument' => array(
  30. 'handler' => 'views_handler_argument_string',
  31. ),
  32. );
  33. $data['go_count_organism']['cvterm_id'] = array(
  34. 'title' => t('cvterm_id numeric field'),
  35. 'help' => t(' numeric field.'),
  36. 'field' => array(
  37. 'handler' => 'views_handler_field_numeric',
  38. 'click sortable' => TRUE,
  39. ),
  40. 'filter' => array(
  41. 'handler' => 'views_handler_filter_numeric',
  42. ),
  43. 'sort' => array(
  44. 'handler' => 'views_handler_sort',
  45. ),
  46. );
  47. $data['go_count_organism']['organism_id'] = array(
  48. 'title' => t('organism_id numeric field'),
  49. 'help' => t(' numeric field.'),
  50. 'field' => array(
  51. 'handler' => 'views_handler_field_numeric',
  52. 'click sortable' => TRUE,
  53. ),
  54. 'filter' => array(
  55. 'handler' => 'views_handler_filter_numeric',
  56. ),
  57. 'sort' => array(
  58. 'handler' => 'views_handler_sort',
  59. ),
  60. );
  61. $data['go_count_organism']['feature_count'] = array(
  62. 'title' => t('feature_count numeric field'),
  63. 'help' => t(' numeric field.'),
  64. 'field' => array(
  65. 'handler' => 'views_handler_field_numeric',
  66. 'click sortable' => TRUE,
  67. ),
  68. 'filter' => array(
  69. 'handler' => 'views_handler_filter_numeric',
  70. ),
  71. 'sort' => array(
  72. 'handler' => 'views_handler_sort',
  73. ),
  74. );
  75. $data['organism']['table']['join']['go_count_organism'] = array(
  76. 'left_field' => 'organism_id',
  77. 'field' => 'organism_id',
  78. );
  79. */
  80. $tvi_query = db_query('SELECT * FROM public.tripal_views_integration');
  81. //tvi = tripal_views_integration
  82. while($tvi_row = db_fetch_object($tvi_query)){
  83. //ids we'll use for queries
  84. $setup_id = $tvi_row->setup_id;
  85. $mview_id = $tvi_row->mview_id;
  86. //let's get the name of the table
  87. $mview_table = db_fetch_object(db_query("SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = '$mview_id';"));
  88. //use name from above and description from $tvi_row
  89. $data[$mview_table->name]['table']['group'] = t($tvi_row->description);
  90. //TODO: this need to be a base table! so need logic to figure out the primary key of this table, on the fly
  91. $data[$mview_table->name]['table']['base'] = array(
  92. 'title' => t($tvi_row->name),
  93. 'help' => t($tvi_row->description), //garbage explanation for now
  94. );
  95. //let's add fields
  96. //tmj = tripal_mviews_join
  97. $tmj_query = db_query("SELECT * FROM public.tripal_mviews_join WHERE setup_id = '$setup_id'");
  98. $i = 0;
  99. while($tmj_row = db_fetch_object($tmj_query)){
  100. $column_name = $tmj_row->view_column;
  101. $handlers = db_fetch_object(db_query("SELECT handler_filter, handler_field FROM {tripal_views_handlers} WHERE setup_id = '$setup_id' AND column_name = '$column_name';"));
  102. //handlers would be used $handlers->handler_filter, $handlers->handler_field etc, thuogh may need to include new ones in this query or do select *
  103. //let's use handlers we retrieved from above
  104. $data[$mview_table->name][$tmj_row->view_column] = array(
  105. 'title' => t($tmj_row->view_column),
  106. 'help' => t("**"),
  107. 'field' => array(
  108. 'handler' => 'views_handler_field',
  109. 'click sortable' => TRUE,
  110. ),
  111. 'sort' => array(
  112. 'handler' => 'views_handler_sort',
  113. ),
  114. 'filter' => array(
  115. 'handler' => 'views_handler_filter_string',
  116. ),
  117. 'argument' => array(
  118. 'handler' => 'views_handler_argument_string',
  119. ),
  120. );
  121. //TODO: get join info here per mview field
  122. $chado_join_field = $tmj_row->chado_table_join;
  123. $chado_join_column = $tmj_row->chado_column;
  124. $join_column = $tmj_row->view_column;
  125. $data[$chado_join_field]['table']['join'][$mview_table->name] = array(
  126. // Index this array by the table name to which this table refers.
  127. // 'left_field' is the primary key in the referenced table.
  128. // 'field' is the foreign key in this table.
  129. 'left_field' => $join_column,
  130. 'field' => $chado_join_column,
  131. );
  132. $i++;
  133. }
  134. }
  135. dpm("in tripal_views_integration file", 'dpm');
  136. dpm($data, 'data');
  137. return $data;
  138. }