tripal_chado.views.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /**
  3. * @file
  4. * Integrates many of the core database tables with drupal views
  5. */
  6. /**
  7. * Describe various Tripal Core systems to Views
  8. * for the creation of administrative views.
  9. *
  10. * @ingroup tripal
  11. */
  12. function tripal_chado_views_data() {
  13. $data = array();
  14. // Custom Tables Management
  15. $data = tripal_chado_views_data_custom_tables($data);
  16. // Materialized Views Management
  17. $data = tripal_chado_views_data_mviews($data);
  18. return $data;
  19. }
  20. /**
  21. * Implements hook_views_data_alter().
  22. */
  23. function tripal_chado_views_data_alter(&$data) {
  24. // Adds integration for chado-based fields.
  25. tripal_chado_add_field_views_data($data);
  26. return $data;
  27. }
  28. /**
  29. * Adds integration for chado-based fields.
  30. *
  31. * We can't use hook_field_view_data since this only works when the
  32. * storage engine is of type 'field_sql_storage' and of course,
  33. * ours is not. Thus we create our own implementation of field_views_data()
  34. * for our storage engine.
  35. */
  36. function tripal_chado_add_field_views_data(&$data) {
  37. foreach (field_info_fields() as $field) {
  38. if ($field['storage']['type'] != 'field_chado_storage') {
  39. continue;
  40. }
  41. // Currently, we only handle integration of chado fields with TripalEntity.
  42. // @todo: extend this to work with other entities in the future.
  43. if (isset($field['bundles']['TripalEntity']) AND isset($field['settings']['chado_column'])) {
  44. // We currently don't support prop tables for views integration due
  45. // in part to the multiple values but also b/c we can't indicate which
  46. // type of property to show. Thus, instead of warning the user,
  47. // we just won't integrate it at this time.
  48. // @todo: Handle property fields.
  49. if (preg_match('/prop$/', $field['settings']['chado_table'])) {
  50. continue;
  51. }
  52. // Unfortunatly we can't use the field label since that is set at the
  53. // instance level and fields are integrated at the field level (independant of bundle).
  54. // Thus we will simply make the most readable and informative field name we can.
  55. $data['tripal_entity'][ $field['field_name'] ]['title'] = ucfirst(str_replace('_',' ',$field['settings']['chado_table']))
  56. . ' ' .ucfirst(str_replace('_',' ',$field['settings']['chado_column']));
  57. // The help should be 'Appears in: TripalEntity: bio-data_1, bio-data_2'
  58. // so that users know where they can use it.
  59. $data['tripal_entity'][ $field['field_name'] ]['help'] = 'Appears in: TripalEntity:' . implode(',', $field['bundles']['TripalEntity']);
  60. // Finally we define the field.
  61. $data['tripal_entity'][ $field['field_name'] ]['field']['chado_field'] = $field['settings']['chado_column'];
  62. $data['tripal_entity'][ $field['field_name'] ]['field']['chado_table'] = $field['settings']['chado_table'];
  63. $data['tripal_entity'][ $field['field_name'] ]['field']['field_name'] = $field['field_name'];
  64. $data['tripal_entity'][ $field['field_name'] ]['field']['entity_table'] = 'tripal_entity';
  65. $data['tripal_entity'][ $field['field_name'] ]['field']['entity_type'] = 'TripalEntity';
  66. $data['tripal_entity'][ $field['field_name'] ]['field']['bundles'] = $field['bundles']['TripalEntity'];
  67. $data['tripal_entity'][ $field['field_name'] ]['field']['handler'] = 'chado_views_handler_field';
  68. $data['tripal_entity'][ $field['field_name'] ]['field']['click sortable'] = FALSE;
  69. }
  70. }
  71. }
  72. /**
  73. * Provides the data array for the tripal custom tables management
  74. *
  75. * @param $data
  76. * Previously generated tripal views data array
  77. * return
  78. * $data array with custom tables management described
  79. *
  80. * @ingroup tripal
  81. */
  82. function tripal_chado_views_data_custom_tables($data) {
  83. $data['tripal_custom_tables']['table']['group'] = t('Tripal Custom Tables');
  84. $data['tripal_custom_tables']['table']['base'] = array(
  85. 'field' => 'table_id', // This is the identifier field for the view.
  86. 'title' => t('Tripal Custom Tables'),
  87. 'help' => t('Custom Tables in Chado created by this Tripal Installation.'),
  88. 'weight' => 10,
  89. );
  90. // Table ID
  91. $data['tripal_custom_tables']['table_id'] = array(
  92. 'title' => t('Custom Table ID'),
  93. 'help' => t('Custom table primary key.'),
  94. 'field' => array(
  95. 'handler' => 'views_handler_field_numeric',
  96. 'click sortable' => TRUE,
  97. ),
  98. 'filter' => array(
  99. 'handler' => 'views_handler_filter_numeric',
  100. ),
  101. 'sort' => array(
  102. 'handler' => 'views_handler_sort',
  103. ),
  104. );
  105. // Table Name
  106. $data['tripal_custom_tables']['table_name'] = array(
  107. 'title' => t('Table Name'),
  108. 'help' => t('The name of the table in the database.'),
  109. 'field' => array(
  110. 'handler' => 'views_handler_field',
  111. 'click sortable' => TRUE, // This is use by the table display plugin.
  112. ),
  113. 'sort' => array(
  114. 'handler' => 'views_handler_sort',
  115. ),
  116. 'filter' => array(
  117. 'handler' => 'views_handler_filter_string',
  118. ),
  119. 'argument' => array(
  120. 'handler' => 'views_handler_argument_string',
  121. ),
  122. );
  123. // Schema
  124. $data['tripal_custom_tables']['schema'] = array(
  125. 'title' => t('Table Schema'),
  126. 'help' => t('The schema definition of the table.'),
  127. 'field' => array(
  128. 'handler' => 'views_handler_field',
  129. 'click sortable' => TRUE, // This is use by the table display plugin.
  130. ),
  131. 'sort' => array(
  132. 'handler' => 'views_handler_sort',
  133. ),
  134. 'filter' => array(
  135. 'handler' => 'views_handler_filter_string',
  136. ),
  137. 'argument' => array(
  138. 'handler' => 'views_handler_argument_string',
  139. ),
  140. );
  141. // Table ID
  142. $data['tripal_custom_tables']['mview_id'] = array(
  143. 'title' => t('Materialized View ID'),
  144. 'help' => t('Foreign key to tripal_mviews table for the materialized view.'),
  145. 'field' => array(
  146. 'handler' => 'views_handler_field_numeric',
  147. 'click sortable' => TRUE,
  148. ),
  149. 'filter' => array(
  150. 'handler' => 'views_handler_filter_numeric',
  151. ),
  152. 'sort' => array(
  153. 'handler' => 'views_handler_sort',
  154. ),
  155. );
  156. return $data;
  157. }
  158. /**
  159. * Provides the data array for the tripal custom tables management
  160. *
  161. * @param $data
  162. * Previously generated tripal views data array
  163. * return
  164. * $data array with custom tables management described
  165. *
  166. * @ingroup tripal
  167. */
  168. function tripal_chado_views_data_mviews($data) {
  169. $data['tripal_mviews']['table']['group'] = t('Tripal Materialized Views');
  170. $data['tripal_mviews']['table']['base'] = array(
  171. 'field' => 'mview_id', // This is the identifier field for the view.
  172. 'title' => t('Tripal Materialized Views'),
  173. 'help' => t('Materialized Views in Chado created by this Tripal Installation.'),
  174. 'weight' => 10,
  175. );
  176. // Implicit Join to Tripal Views
  177. $data['tripal_mviews']['table']['join'] = array(
  178. 'tripal_views' => array(
  179. 'left_field' => 'mview_id',
  180. 'field' => 'mview_id',
  181. ),
  182. );
  183. // Mview ID
  184. $data['tripal_mviews']['mview_id'] = array(
  185. 'title' => t('Materialized View ID'),
  186. 'help' => t('The primary key.'),
  187. 'field' => array(
  188. 'handler' => 'views_handler_field_numeric',
  189. 'click sortable' => TRUE,
  190. ),
  191. 'filter' => array(
  192. 'handler' => 'views_handler_filter_numeric',
  193. ),
  194. 'sort' => array(
  195. 'handler' => 'views_handler_sort',
  196. ),
  197. );
  198. // name
  199. $data['tripal_mviews']['name'] = array(
  200. 'title' => t('Name'),
  201. 'help' => t('Human-readable name of the materialized view.'),
  202. 'field' => array(
  203. 'handler' => 'views_handler_field',
  204. 'click sortable' => TRUE, // This is use by the table display plugin.
  205. ),
  206. 'sort' => array(
  207. 'handler' => 'views_handler_sort',
  208. ),
  209. 'filter' => array(
  210. 'handler' => 'views_handler_filter_string',
  211. ),
  212. 'argument' => array(
  213. 'handler' => 'views_handler_argument_string',
  214. ),
  215. );
  216. // modulename
  217. $data['tripal_mviews']['modulename'] = array(
  218. 'title' => t('Module Name'),
  219. 'help' => t('The module that created the materialized view.'),
  220. 'field' => array(
  221. 'handler' => 'views_handler_field',
  222. 'click sortable' => TRUE, // This is use by the table display plugin.
  223. ),
  224. 'sort' => array(
  225. 'handler' => 'views_handler_sort',
  226. ),
  227. 'filter' => array(
  228. 'handler' => 'views_handler_filter_string',
  229. ),
  230. 'argument' => array(
  231. 'handler' => 'views_handler_argument_string',
  232. ),
  233. );
  234. // mv_table
  235. $data['tripal_mviews']['mv_table'] = array(
  236. 'title' => t('Table'),
  237. 'help' => t('The database table the materialized view is stored in.'),
  238. 'field' => array(
  239. 'handler' => 'views_handler_field',
  240. 'click sortable' => TRUE, // This is use by the table display plugin.
  241. ),
  242. 'sort' => array(
  243. 'handler' => 'views_handler_sort',
  244. ),
  245. 'filter' => array(
  246. 'handler' => 'views_handler_filter_string',
  247. ),
  248. 'argument' => array(
  249. 'handler' => 'views_handler_argument_string',
  250. ),
  251. );
  252. // mv_specs
  253. $data['tripal_mviews']['mv_specs'] = array(
  254. 'title' => t('Specification'),
  255. 'help' => t('Materialized View Specification.'),
  256. 'field' => array(
  257. 'handler' => 'views_handler_field',
  258. 'click sortable' => TRUE, // This is use by the table display plugin.
  259. ),
  260. 'sort' => array(
  261. 'handler' => 'views_handler_sort',
  262. ),
  263. 'filter' => array(
  264. 'handler' => 'views_handler_filter_string',
  265. ),
  266. 'argument' => array(
  267. 'handler' => 'views_handler_argument_string',
  268. ),
  269. );
  270. // mv_schema
  271. $data['tripal_mviews']['mv_schema'] = array(
  272. 'title' => t('Schema'),
  273. 'help' => t('Schema definition for the materialized view table.'),
  274. 'field' => array(
  275. 'handler' => 'views_handler_field',
  276. 'click sortable' => TRUE, // This is use by the table display plugin.
  277. ),
  278. 'sort' => array(
  279. 'handler' => 'views_handler_sort',
  280. ),
  281. 'filter' => array(
  282. 'handler' => 'views_handler_filter_string',
  283. ),
  284. 'argument' => array(
  285. 'handler' => 'views_handler_argument_string',
  286. ),
  287. );
  288. // indexed
  289. $data['tripal_mviews']['indexed'] = array(
  290. 'title' => t('Indices'),
  291. 'help' => t('Any indices for this materialized view.'),
  292. 'field' => array(
  293. 'handler' => 'views_handler_field',
  294. 'click sortable' => TRUE, // This is use by the table display plugin.
  295. ),
  296. 'sort' => array(
  297. 'handler' => 'views_handler_sort',
  298. ),
  299. 'filter' => array(
  300. 'handler' => 'views_handler_filter_string',
  301. ),
  302. 'argument' => array(
  303. 'handler' => 'views_handler_argument_string',
  304. ),
  305. );
  306. // query
  307. $data['tripal_mviews']['query'] = array(
  308. 'title' => t('Query'),
  309. 'help' => t('The query used to populate the materialized view.'),
  310. 'field' => array(
  311. 'handler' => 'views_handler_field',
  312. 'click sortable' => TRUE, // This is use by the table display plugin.
  313. ),
  314. 'sort' => array(
  315. 'handler' => 'views_handler_sort',
  316. ),
  317. 'filter' => array(
  318. 'handler' => 'views_handler_filter_string',
  319. ),
  320. 'argument' => array(
  321. 'handler' => 'views_handler_argument_string',
  322. ),
  323. );
  324. // special_index
  325. $data['tripal_mviews']['special_index'] = array(
  326. 'title' => t('Special Index'),
  327. 'help' => t('Any special indices for the materialized view.'),
  328. 'field' => array(
  329. 'handler' => 'views_handler_field',
  330. 'click sortable' => TRUE, // This is use by the table display plugin.
  331. ),
  332. 'sort' => array(
  333. 'handler' => 'views_handler_sort',
  334. ),
  335. 'filter' => array(
  336. 'handler' => 'views_handler_filter_string',
  337. ),
  338. 'argument' => array(
  339. 'handler' => 'views_handler_argument_string',
  340. ),
  341. );
  342. // last_update
  343. $data['tripal_mviews']['last_update'] = array(
  344. 'title' => t('Updated'),
  345. 'help' => t('Date Last Updated.'),
  346. 'field' => array(
  347. 'handler' => 'views_handler_field_date',
  348. 'click sortable' => TRUE,
  349. ),
  350. 'sort' => array(
  351. 'handler' => 'views_handler_sort_date',
  352. ),
  353. 'filter' => array(
  354. 'handler' => 'views_handler_filter_date',
  355. ),
  356. );
  357. // status
  358. $data['tripal_mviews']['status'] = array(
  359. 'title' => t('Status'),
  360. 'help' => t('The status of the materialized view.'),
  361. 'field' => array(
  362. 'handler' => 'views_handler_field',
  363. 'click sortable' => TRUE, // This is use by the table display plugin.
  364. ),
  365. 'sort' => array(
  366. 'handler' => 'views_handler_sort',
  367. ),
  368. 'filter' => array(
  369. 'handler' => 'views_handler_filter_string',
  370. ),
  371. 'argument' => array(
  372. 'handler' => 'views_handler_argument_string',
  373. ),
  374. );
  375. // comment
  376. $data['tripal_mviews']['comment'] = array(
  377. 'title' => t('Description'),
  378. 'help' => t('Human-Readable Admin Description.'),
  379. 'field' => array(
  380. 'handler' => 'views_handler_field',
  381. 'click sortable' => TRUE, // This is use by the table display plugin.
  382. ),
  383. 'sort' => array(
  384. 'handler' => 'views_handler_sort',
  385. ),
  386. 'filter' => array(
  387. 'handler' => 'views_handler_filter_string',
  388. ),
  389. 'argument' => array(
  390. 'handler' => 'views_handler_argument_string',
  391. ),
  392. );
  393. return $data;
  394. }