tripal_views_integration.views.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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('Mview ' . $tvi_row->name);
  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. 'group' => t($tvi_row->name),
  93. 'title' => t($tvi_row->name),
  94. 'help' => t($tvi_row->description),
  95. );
  96. //let's add fields
  97. //tmj = tripal_mviews_join
  98. $tmj_query = db_query("SELECT * FROM public.tripal_mviews_join WHERE setup_id = '$setup_id'");
  99. $i = 0;
  100. while($tmj_row = db_fetch_object($tmj_query)){
  101. $column_name = $tmj_row->view_column;
  102. $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';"));
  103. //handlers would be used $handlers->handler_filter, $handlers->handler_field etc, thuogh may need to include new ones in this query or do select *
  104. //let's use handlers we retrieved from above
  105. $data[$mview_table->name][$tmj_row->view_column] = array(
  106. 'title' => t($tmj_row->view_column),
  107. 'help' => t("**"),
  108. 'field' => array(
  109. 'handler' => 'views_handler_field',
  110. 'click sortable' => TRUE,
  111. ),
  112. 'sort' => array(
  113. 'handler' => 'views_handler_sort',
  114. ),
  115. 'filter' => array(
  116. 'handler' => 'views_handler_filter_string',
  117. ),
  118. 'argument' => array(
  119. 'handler' => 'views_handler_argument_string',
  120. ),
  121. );
  122. //TODO: get join info here per mview field
  123. $chado_join_field = $tmj_row->chado_table_join;
  124. $chado_join_column = $tmj_row->chado_column;
  125. $join_column = $tmj_row->view_column;
  126. $data["$chado_join_field"]['table']['join']["$mview_table->name"] = array(
  127. // Index this array by the table name to which this table refers.
  128. // 'left_field' is the primary key in the referenced table.
  129. // 'field' is the foreign key in this table.
  130. 'left_field' => $join_column,
  131. 'field' => $chado_join_column,
  132. );
  133. $i++;
  134. }
  135. }
  136. return $data;
  137. }