tripal_chado.views.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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: gene, organism'
  58. // so that users know where they can use it. This requires a little extra work since all
  59. // we have access to at this point is bio-data_2, bio-data_4 but since that's not very
  60. // informative, extra work is worth it ;-).
  61. $entity_info = entity_get_info('TripalEntity');
  62. $bundle_labels = array();
  63. foreach ($field['bundles']['TripalEntity'] as $bundle_id) {
  64. $bundle_labels[] = $entity_info['bundles'][$bundle_id]['label'];
  65. }
  66. $data['tripal_entity'][ $field['field_name'] ]['help'] = 'Appears in: TripalEntity:' . implode(', ', $bundle_labels);
  67. // Finally we define the field.
  68. $data['tripal_entity'][ $field['field_name'] ]['field']['chado_field'] = $field['settings']['chado_column'];
  69. $data['tripal_entity'][ $field['field_name'] ]['field']['chado_table'] = $field['settings']['chado_table'];
  70. $data['tripal_entity'][ $field['field_name'] ]['field']['field_name'] = $field['field_name'];
  71. $data['tripal_entity'][ $field['field_name'] ]['field']['entity_table'] = 'tripal_entity';
  72. $data['tripal_entity'][ $field['field_name'] ]['field']['entity_type'] = 'TripalEntity';
  73. $data['tripal_entity'][ $field['field_name'] ]['field']['bundles'] = $field['bundles']['TripalEntity'];
  74. $data['tripal_entity'][ $field['field_name'] ]['field']['handler'] = 'chado_views_handler_field';
  75. $data['tripal_entity'][ $field['field_name'] ]['field']['click sortable'] = FALSE;
  76. }
  77. }
  78. }
  79. /**
  80. * Provides the data array for the tripal custom tables management
  81. *
  82. * @param $data
  83. * Previously generated tripal views data array
  84. * return
  85. * $data array with custom tables management described
  86. *
  87. * @ingroup tripal
  88. */
  89. function tripal_chado_views_data_custom_tables($data) {
  90. $data['tripal_custom_tables']['table']['group'] = t('Tripal Custom Tables');
  91. $data['tripal_custom_tables']['table']['base'] = array(
  92. 'field' => 'table_id', // This is the identifier field for the view.
  93. 'title' => t('Tripal Custom Tables'),
  94. 'help' => t('Custom Tables in Chado created by this Tripal Installation.'),
  95. 'weight' => 10,
  96. );
  97. // Table ID
  98. $data['tripal_custom_tables']['table_id'] = array(
  99. 'title' => t('Custom Table ID'),
  100. 'help' => t('Custom table primary key.'),
  101. 'field' => array(
  102. 'handler' => 'views_handler_field_numeric',
  103. 'click sortable' => TRUE,
  104. ),
  105. 'filter' => array(
  106. 'handler' => 'views_handler_filter_numeric',
  107. ),
  108. 'sort' => array(
  109. 'handler' => 'views_handler_sort',
  110. ),
  111. );
  112. // Table Name
  113. $data['tripal_custom_tables']['table_name'] = array(
  114. 'title' => t('Table Name'),
  115. 'help' => t('The name of the table in the database.'),
  116. 'field' => array(
  117. 'handler' => 'views_handler_field',
  118. 'click sortable' => TRUE, // This is use by the table display plugin.
  119. ),
  120. 'sort' => array(
  121. 'handler' => 'views_handler_sort',
  122. ),
  123. 'filter' => array(
  124. 'handler' => 'views_handler_filter_string',
  125. ),
  126. 'argument' => array(
  127. 'handler' => 'views_handler_argument_string',
  128. ),
  129. );
  130. // Schema
  131. $data['tripal_custom_tables']['schema'] = array(
  132. 'title' => t('Table Schema'),
  133. 'help' => t('The schema definition of the table.'),
  134. 'field' => array(
  135. 'handler' => 'views_handler_field',
  136. 'click sortable' => TRUE, // This is use by the table display plugin.
  137. ),
  138. 'sort' => array(
  139. 'handler' => 'views_handler_sort',
  140. ),
  141. 'filter' => array(
  142. 'handler' => 'views_handler_filter_string',
  143. ),
  144. 'argument' => array(
  145. 'handler' => 'views_handler_argument_string',
  146. ),
  147. );
  148. // Table ID
  149. $data['tripal_custom_tables']['mview_id'] = array(
  150. 'title' => t('Materialized View ID'),
  151. 'help' => t('Foreign key to tripal_mviews table for the materialized view.'),
  152. 'field' => array(
  153. 'handler' => 'views_handler_field_numeric',
  154. 'click sortable' => TRUE,
  155. ),
  156. 'filter' => array(
  157. 'handler' => 'views_handler_filter_numeric',
  158. ),
  159. 'sort' => array(
  160. 'handler' => 'views_handler_sort',
  161. ),
  162. );
  163. return $data;
  164. }
  165. /**
  166. * Provides the data array for the tripal custom tables management
  167. *
  168. * @param $data
  169. * Previously generated tripal views data array
  170. * return
  171. * $data array with custom tables management described
  172. *
  173. * @ingroup tripal
  174. */
  175. function tripal_chado_views_data_mviews($data) {
  176. $data['tripal_mviews']['table']['group'] = t('Tripal Materialized Views');
  177. $data['tripal_mviews']['table']['base'] = array(
  178. 'field' => 'mview_id', // This is the identifier field for the view.
  179. 'title' => t('Tripal Materialized Views'),
  180. 'help' => t('Materialized Views in Chado created by this Tripal Installation.'),
  181. 'weight' => 10,
  182. );
  183. // Implicit Join to Tripal Views
  184. $data['tripal_mviews']['table']['join'] = array(
  185. 'tripal_views' => array(
  186. 'left_field' => 'mview_id',
  187. 'field' => 'mview_id',
  188. ),
  189. );
  190. // Mview ID
  191. $data['tripal_mviews']['mview_id'] = array(
  192. 'title' => t('Materialized View ID'),
  193. 'help' => t('The primary key.'),
  194. 'field' => array(
  195. 'handler' => 'views_handler_field_numeric',
  196. 'click sortable' => TRUE,
  197. ),
  198. 'filter' => array(
  199. 'handler' => 'views_handler_filter_numeric',
  200. ),
  201. 'sort' => array(
  202. 'handler' => 'views_handler_sort',
  203. ),
  204. );
  205. // name
  206. $data['tripal_mviews']['name'] = array(
  207. 'title' => t('Name'),
  208. 'help' => t('Human-readable name of the materialized view.'),
  209. 'field' => array(
  210. 'handler' => 'views_handler_field',
  211. 'click sortable' => TRUE, // This is use by the table display plugin.
  212. ),
  213. 'sort' => array(
  214. 'handler' => 'views_handler_sort',
  215. ),
  216. 'filter' => array(
  217. 'handler' => 'views_handler_filter_string',
  218. ),
  219. 'argument' => array(
  220. 'handler' => 'views_handler_argument_string',
  221. ),
  222. );
  223. // modulename
  224. $data['tripal_mviews']['modulename'] = array(
  225. 'title' => t('Module Name'),
  226. 'help' => t('The module that created the materialized view.'),
  227. 'field' => array(
  228. 'handler' => 'views_handler_field',
  229. 'click sortable' => TRUE, // This is use by the table display plugin.
  230. ),
  231. 'sort' => array(
  232. 'handler' => 'views_handler_sort',
  233. ),
  234. 'filter' => array(
  235. 'handler' => 'views_handler_filter_string',
  236. ),
  237. 'argument' => array(
  238. 'handler' => 'views_handler_argument_string',
  239. ),
  240. );
  241. // mv_table
  242. $data['tripal_mviews']['mv_table'] = array(
  243. 'title' => t('Table'),
  244. 'help' => t('The database table the materialized view is stored in.'),
  245. 'field' => array(
  246. 'handler' => 'views_handler_field',
  247. 'click sortable' => TRUE, // This is use by the table display plugin.
  248. ),
  249. 'sort' => array(
  250. 'handler' => 'views_handler_sort',
  251. ),
  252. 'filter' => array(
  253. 'handler' => 'views_handler_filter_string',
  254. ),
  255. 'argument' => array(
  256. 'handler' => 'views_handler_argument_string',
  257. ),
  258. );
  259. // mv_specs
  260. $data['tripal_mviews']['mv_specs'] = array(
  261. 'title' => t('Specification'),
  262. 'help' => t('Materialized View Specification.'),
  263. 'field' => array(
  264. 'handler' => 'views_handler_field',
  265. 'click sortable' => TRUE, // This is use by the table display plugin.
  266. ),
  267. 'sort' => array(
  268. 'handler' => 'views_handler_sort',
  269. ),
  270. 'filter' => array(
  271. 'handler' => 'views_handler_filter_string',
  272. ),
  273. 'argument' => array(
  274. 'handler' => 'views_handler_argument_string',
  275. ),
  276. );
  277. // mv_schema
  278. $data['tripal_mviews']['mv_schema'] = array(
  279. 'title' => t('Schema'),
  280. 'help' => t('Schema definition for the materialized view table.'),
  281. 'field' => array(
  282. 'handler' => 'views_handler_field',
  283. 'click sortable' => TRUE, // This is use by the table display plugin.
  284. ),
  285. 'sort' => array(
  286. 'handler' => 'views_handler_sort',
  287. ),
  288. 'filter' => array(
  289. 'handler' => 'views_handler_filter_string',
  290. ),
  291. 'argument' => array(
  292. 'handler' => 'views_handler_argument_string',
  293. ),
  294. );
  295. // indexed
  296. $data['tripal_mviews']['indexed'] = array(
  297. 'title' => t('Indices'),
  298. 'help' => t('Any indices for this materialized view.'),
  299. 'field' => array(
  300. 'handler' => 'views_handler_field',
  301. 'click sortable' => TRUE, // This is use by the table display plugin.
  302. ),
  303. 'sort' => array(
  304. 'handler' => 'views_handler_sort',
  305. ),
  306. 'filter' => array(
  307. 'handler' => 'views_handler_filter_string',
  308. ),
  309. 'argument' => array(
  310. 'handler' => 'views_handler_argument_string',
  311. ),
  312. );
  313. // query
  314. $data['tripal_mviews']['query'] = array(
  315. 'title' => t('Query'),
  316. 'help' => t('The query used to populate the materialized view.'),
  317. 'field' => array(
  318. 'handler' => 'views_handler_field',
  319. 'click sortable' => TRUE, // This is use by the table display plugin.
  320. ),
  321. 'sort' => array(
  322. 'handler' => 'views_handler_sort',
  323. ),
  324. 'filter' => array(
  325. 'handler' => 'views_handler_filter_string',
  326. ),
  327. 'argument' => array(
  328. 'handler' => 'views_handler_argument_string',
  329. ),
  330. );
  331. // special_index
  332. $data['tripal_mviews']['special_index'] = array(
  333. 'title' => t('Special Index'),
  334. 'help' => t('Any special indices for the materialized view.'),
  335. 'field' => array(
  336. 'handler' => 'views_handler_field',
  337. 'click sortable' => TRUE, // This is use by the table display plugin.
  338. ),
  339. 'sort' => array(
  340. 'handler' => 'views_handler_sort',
  341. ),
  342. 'filter' => array(
  343. 'handler' => 'views_handler_filter_string',
  344. ),
  345. 'argument' => array(
  346. 'handler' => 'views_handler_argument_string',
  347. ),
  348. );
  349. // last_update
  350. $data['tripal_mviews']['last_update'] = array(
  351. 'title' => t('Updated'),
  352. 'help' => t('Date Last Updated.'),
  353. 'field' => array(
  354. 'handler' => 'views_handler_field_date',
  355. 'click sortable' => TRUE,
  356. ),
  357. 'sort' => array(
  358. 'handler' => 'views_handler_sort_date',
  359. ),
  360. 'filter' => array(
  361. 'handler' => 'views_handler_filter_date',
  362. ),
  363. );
  364. // status
  365. $data['tripal_mviews']['status'] = array(
  366. 'title' => t('Status'),
  367. 'help' => t('The status of the materialized view.'),
  368. 'field' => array(
  369. 'handler' => 'views_handler_field',
  370. 'click sortable' => TRUE, // This is use by the table display plugin.
  371. ),
  372. 'sort' => array(
  373. 'handler' => 'views_handler_sort',
  374. ),
  375. 'filter' => array(
  376. 'handler' => 'views_handler_filter_string',
  377. ),
  378. 'argument' => array(
  379. 'handler' => 'views_handler_argument_string',
  380. ),
  381. );
  382. // comment
  383. $data['tripal_mviews']['comment'] = array(
  384. 'title' => t('Description'),
  385. 'help' => t('Human-Readable Admin Description.'),
  386. 'field' => array(
  387. 'handler' => 'views_handler_field',
  388. 'click sortable' => TRUE, // This is use by the table display plugin.
  389. ),
  390. 'sort' => array(
  391. 'handler' => 'views_handler_sort',
  392. ),
  393. 'filter' => array(
  394. 'handler' => 'views_handler_filter_string',
  395. ),
  396. 'argument' => array(
  397. 'handler' => 'views_handler_argument_string',
  398. ),
  399. );
  400. return $data;
  401. }