tripal_chado.views.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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 for the creation of
  8. * 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. // $field_name = $field['field_name'];
  42. // $field_type = $field['type'];
  43. // // Currently, we only handle integration of chado fields with TripalEntity.
  44. // // @todo: extend this to work with other entities in the future.
  45. // if (isset($field['bundles']['TripalEntity']) AND isset($field['settings']['chado_column'])) {
  46. // // We currently don't support prop tables for views integration due
  47. // // in part to the multiple values but also b/c we can't indicate which
  48. // // type of property to show. Thus, instead of warning the user,
  49. // // we just won't integrate it at this time.
  50. // // @todo: Handle property fields.
  51. // if (preg_match('/prop$/', $field['settings']['chado_table'])) {
  52. // continue;
  53. // }
  54. // // Get some information about the chado table in order to make good
  55. // // default choices for handlers.
  56. // $table_desc = chado_get_schema($field['settings']['chado_table']);
  57. // $field_defn = $table_desc['fields'][ $field['settings']['chado_column'] ];
  58. // // We also need to know if this field is a foreign key.
  59. // $fk_defn = FALSE;
  60. // foreach ($table_desc['foreign keys'] as $details) {
  61. // foreach ($details['columns'] as $left_field => $right_field) {
  62. // if ($left_field == $field['settings']['chado_column']) {
  63. // $fk_defn = array(
  64. // 'left_table' => $field['settings']['chado_table'],
  65. // 'left_field' => $left_field,
  66. // 'right_table' => $details['table'],
  67. // 'right_field' => $right_field,
  68. // );
  69. // }
  70. // }
  71. // }
  72. // // Unfortunatly we can't use the field label since that is set at the
  73. // // instance level and fields are integrated at the field level (independant of bundle).
  74. // // Thus we will simply make the most readable and informative field name we can.
  75. // $data['tripal_entity'][$field_name]['title'] = ucfirst(str_replace('_',' ',$field['settings']['chado_table']))
  76. // . ': ' .ucfirst(str_replace('_',' ',$field['settings']['chado_column']));
  77. // // The help should be 'Appears in: TripalEntity: gene, organism'
  78. // // so that users know where they can use it. This requires a little extra work since all
  79. // // we have access to at this point is bio_data_2, bio_data_4 but since that's not very
  80. // // informative, extra work is worth it ;-).
  81. // $entity_info = entity_get_info('TripalEntity');
  82. // $bundle_labels = array();
  83. // foreach ($field['bundles']['TripalEntity'] as $bundle_id) {
  84. // $bundle_labels[] = $entity_info['bundles'][$bundle_id]['label'];
  85. // }
  86. // $data['tripal_entity'][$field_name]['help'] = 'Appears in: TripalEntity:' . implode(', ', $bundle_labels);
  87. // // Define the field.
  88. // $data['tripal_entity'][$field_name]['field']['chado_field'] = $field['settings']['chado_column'];
  89. // $data['tripal_entity'][$field_name]['field']['chado_table'] = $field['settings']['chado_table'];
  90. // $data['tripal_entity'][$field_name]['field']['field_name'] = $field['field_name'];
  91. // $data['tripal_entity'][$field_name]['field']['entity_table'] = 'tripal_entity';
  92. // $data['tripal_entity'][$field_name]['field']['entity_type'] = 'TripalEntity';
  93. // $data['tripal_entity'][$field_name]['field']['bundles'] = $field['bundles']['TripalEntity'];
  94. // $data['tripal_entity'][$field_name]['field']['handler'] = 'chado_views_handler_field';
  95. // $data['tripal_entity'][$field_name]['field']['click sortable'] = FALSE;
  96. // // Define the Filter.
  97. // $data['tripal_entity'][$field_name]['filter']['chado_field'] = $field['settings']['chado_column'];
  98. // $data['tripal_entity'][$field_name]['filter']['chado_table'] = $field['settings']['chado_table'];
  99. // $data['tripal_entity'][$field_name]['filter']['field_name'] = $field['field_name'];
  100. // $data['tripal_entity'][$field_name]['filter']['entity_table'] = 'tripal_entity';
  101. // $data['tripal_entity'][$field_name]['filter']['entity_type'] = 'TripalEntity';
  102. // $data['tripal_entity'][$field_name]['filter']['bundles'] = $field['bundles']['TripalEntity'];
  103. // $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_string';
  104. // // Define sorting.
  105. // $data['tripal_entity'][$field_name]['sort']['chado_field'] = $field['settings']['chado_column'];
  106. // $data['tripal_entity'][$field_name]['sort']['chado_table'] = $field['settings']['chado_table'];
  107. // $data['tripal_entity'][$field_name]['sort']['field_name'] = $field['field_name'];
  108. // $data['tripal_entity'][$field_name]['sort']['entity_table'] = 'tripal_entity';
  109. // $data['tripal_entity'][$field_name]['sort']['entity_type'] = 'TripalEntity';
  110. // $data['tripal_entity'][$field_name]['sort']['bundles'] = $field['bundles']['TripalEntity'];
  111. // $data['tripal_entity'][$field_name]['sort']['handler'] = 'chado_views_handler_sort';
  112. // // Specify special handlers.
  113. // if ($fk_defn) {
  114. // $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_fk';
  115. // $data['tripal_entity'][$field_name]['filter']['foreign_key'] = $fk_defn;
  116. // }
  117. // if ($field_defn['type'] == 'boolean') {
  118. // $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_boolean';
  119. // $data['tripal_entity'][$field_name]['filter']['label'] = $field['settings']['chado_column'];
  120. // $data['tripal_entity'][$field_name]['filter']['type'] = 'yes-no';
  121. // }
  122. // elseif ($field_defn['type'] == 'datetime') {
  123. // $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_date';
  124. // }
  125. // // Allow the fields to alter the default selections from above.
  126. // tripal_load_include_field_type($field_type);
  127. // if (preg_match('/^chado/', $field_type) and class_exists($field_type)) {
  128. // $field_obj = new $field_type($field);
  129. // $field_obj->views_data_alter($data['tripal_entity'][$field_name], $field, $entity_info);
  130. // }
  131. // }
  132. // }
  133. // }
  134. /**
  135. * Provides the data array for the tripal custom tables management
  136. *
  137. * @param $data
  138. * Previously generated tripal views data array
  139. * return
  140. * $data array with custom tables management described
  141. *
  142. * @ingroup tripal
  143. */
  144. function tripal_chado_views_data_custom_tables($data) {
  145. $data['tripal_custom_tables']['table']['group'] = t('Tripal Custom Tables');
  146. $data['tripal_custom_tables']['table']['base'] = array(
  147. 'field' => 'table_id', // This is the identifier field for the view.
  148. 'title' => t('Tripal Custom Tables'),
  149. 'help' => t('Custom Tables in Chado created by this Tripal Installation.'),
  150. 'weight' => 10,
  151. );
  152. // Table ID
  153. $data['tripal_custom_tables']['table_id'] = array(
  154. 'title' => t('Custom Table ID'),
  155. 'help' => t('Custom table primary key.'),
  156. 'field' => array(
  157. 'handler' => 'views_handler_field_numeric',
  158. 'click sortable' => TRUE,
  159. ),
  160. 'filter' => array(
  161. 'handler' => 'views_handler_filter_numeric',
  162. ),
  163. 'sort' => array(
  164. 'handler' => 'views_handler_sort',
  165. ),
  166. );
  167. // Table Name
  168. $data['tripal_custom_tables']['table_name'] = array(
  169. 'title' => t('Table Name'),
  170. 'help' => t('The name of the table in the database.'),
  171. 'field' => array(
  172. 'handler' => 'views_handler_field',
  173. 'click sortable' => TRUE, // This is use by the table display plugin.
  174. ),
  175. 'sort' => array(
  176. 'handler' => 'views_handler_sort',
  177. ),
  178. 'filter' => array(
  179. 'handler' => 'views_handler_filter_string',
  180. ),
  181. 'argument' => array(
  182. 'handler' => 'views_handler_argument_string',
  183. ),
  184. );
  185. // Schema
  186. $data['tripal_custom_tables']['schema'] = array(
  187. 'title' => t('Table Schema'),
  188. 'help' => t('The schema definition of the table.'),
  189. 'field' => array(
  190. 'handler' => 'views_handler_field',
  191. 'click sortable' => TRUE, // This is use by the table display plugin.
  192. ),
  193. 'sort' => array(
  194. 'handler' => 'views_handler_sort',
  195. ),
  196. 'filter' => array(
  197. 'handler' => 'views_handler_filter_string',
  198. ),
  199. 'argument' => array(
  200. 'handler' => 'views_handler_argument_string',
  201. ),
  202. );
  203. // Table ID
  204. $data['tripal_custom_tables']['mview_id'] = array(
  205. 'title' => t('Materialized View ID'),
  206. 'help' => t('Foreign key to tripal_mviews table for the materialized view.'),
  207. 'field' => array(
  208. 'handler' => 'views_handler_field_numeric',
  209. 'click sortable' => TRUE,
  210. ),
  211. 'filter' => array(
  212. 'handler' => 'views_handler_filter_numeric',
  213. ),
  214. 'sort' => array(
  215. 'handler' => 'views_handler_sort',
  216. ),
  217. );
  218. return $data;
  219. }
  220. /**
  221. * Provides the data array for the tripal custom tables management
  222. *
  223. * @param $data
  224. * Previously generated tripal views data array
  225. * return
  226. * $data array with custom tables management described
  227. *
  228. * @ingroup tripal
  229. */
  230. function tripal_chado_views_data_mviews($data) {
  231. $data['tripal_mviews']['table']['group'] = t('Tripal Materialized Views');
  232. $data['tripal_mviews']['table']['base'] = array(
  233. 'field' => 'mview_id', // This is the identifier field for the view.
  234. 'title' => t('Tripal Materialized Views'),
  235. 'help' => t('Materialized Views in Chado created by this Tripal Installation.'),
  236. 'weight' => 10,
  237. );
  238. // Implicit Join to Tripal Views
  239. $data['tripal_mviews']['table']['join'] = array(
  240. 'tripal_views' => array(
  241. 'left_field' => 'mview_id',
  242. 'field' => 'mview_id',
  243. ),
  244. );
  245. // Mview ID
  246. $data['tripal_mviews']['mview_id'] = array(
  247. 'title' => t('Materialized View ID'),
  248. 'help' => t('The primary key.'),
  249. 'field' => array(
  250. 'handler' => 'views_handler_field_numeric',
  251. 'click sortable' => TRUE,
  252. ),
  253. 'filter' => array(
  254. 'handler' => 'views_handler_filter_numeric',
  255. ),
  256. 'sort' => array(
  257. 'handler' => 'views_handler_sort',
  258. ),
  259. );
  260. // name
  261. $data['tripal_mviews']['name'] = array(
  262. 'title' => t('Name'),
  263. 'help' => t('Human-readable name of the materialized view.'),
  264. 'field' => array(
  265. 'handler' => 'views_handler_field',
  266. 'click sortable' => TRUE, // This is use by the table display plugin.
  267. ),
  268. 'sort' => array(
  269. 'handler' => 'views_handler_sort',
  270. ),
  271. 'filter' => array(
  272. 'handler' => 'views_handler_filter_string',
  273. ),
  274. 'argument' => array(
  275. 'handler' => 'views_handler_argument_string',
  276. ),
  277. );
  278. // modulename
  279. $data['tripal_mviews']['modulename'] = array(
  280. 'title' => t('Module Name'),
  281. 'help' => t('The module that created the materialized view.'),
  282. 'field' => array(
  283. 'handler' => 'views_handler_field',
  284. 'click sortable' => TRUE, // This is use by the table display plugin.
  285. ),
  286. 'sort' => array(
  287. 'handler' => 'views_handler_sort',
  288. ),
  289. 'filter' => array(
  290. 'handler' => 'views_handler_filter_string',
  291. ),
  292. 'argument' => array(
  293. 'handler' => 'views_handler_argument_string',
  294. ),
  295. );
  296. // mv_table
  297. $data['tripal_mviews']['mv_table'] = array(
  298. 'title' => t('Table'),
  299. 'help' => t('The database table the materialized view is stored in.'),
  300. 'field' => array(
  301. 'handler' => 'views_handler_field',
  302. 'click sortable' => TRUE, // This is use by the table display plugin.
  303. ),
  304. 'sort' => array(
  305. 'handler' => 'views_handler_sort',
  306. ),
  307. 'filter' => array(
  308. 'handler' => 'views_handler_filter_string',
  309. ),
  310. 'argument' => array(
  311. 'handler' => 'views_handler_argument_string',
  312. ),
  313. );
  314. // mv_specs
  315. $data['tripal_mviews']['mv_specs'] = array(
  316. 'title' => t('Specification'),
  317. 'help' => t('Materialized View Specification.'),
  318. 'field' => array(
  319. 'handler' => 'views_handler_field',
  320. 'click sortable' => TRUE, // This is use by the table display plugin.
  321. ),
  322. 'sort' => array(
  323. 'handler' => 'views_handler_sort',
  324. ),
  325. 'filter' => array(
  326. 'handler' => 'views_handler_filter_string',
  327. ),
  328. 'argument' => array(
  329. 'handler' => 'views_handler_argument_string',
  330. ),
  331. );
  332. // mv_schema
  333. $data['tripal_mviews']['mv_schema'] = array(
  334. 'title' => t('Schema'),
  335. 'help' => t('Schema definition for the materialized view table.'),
  336. 'field' => array(
  337. 'handler' => 'views_handler_field',
  338. 'click sortable' => TRUE, // This is use by the table display plugin.
  339. ),
  340. 'sort' => array(
  341. 'handler' => 'views_handler_sort',
  342. ),
  343. 'filter' => array(
  344. 'handler' => 'views_handler_filter_string',
  345. ),
  346. 'argument' => array(
  347. 'handler' => 'views_handler_argument_string',
  348. ),
  349. );
  350. // indexed
  351. $data['tripal_mviews']['indexed'] = array(
  352. 'title' => t('Indices'),
  353. 'help' => t('Any indices for this materialized view.'),
  354. 'field' => array(
  355. 'handler' => 'views_handler_field',
  356. 'click sortable' => TRUE, // This is use by the table display plugin.
  357. ),
  358. 'sort' => array(
  359. 'handler' => 'views_handler_sort',
  360. ),
  361. 'filter' => array(
  362. 'handler' => 'views_handler_filter_string',
  363. ),
  364. 'argument' => array(
  365. 'handler' => 'views_handler_argument_string',
  366. ),
  367. );
  368. // query
  369. $data['tripal_mviews']['query'] = array(
  370. 'title' => t('Query'),
  371. 'help' => t('The query used to populate the materialized view.'),
  372. 'field' => array(
  373. 'handler' => 'views_handler_field',
  374. 'click sortable' => TRUE, // This is use by the table display plugin.
  375. ),
  376. 'sort' => array(
  377. 'handler' => 'views_handler_sort',
  378. ),
  379. 'filter' => array(
  380. 'handler' => 'views_handler_filter_string',
  381. ),
  382. 'argument' => array(
  383. 'handler' => 'views_handler_argument_string',
  384. ),
  385. );
  386. // special_index
  387. $data['tripal_mviews']['special_index'] = array(
  388. 'title' => t('Special Index'),
  389. 'help' => t('Any special indices for the materialized view.'),
  390. 'field' => array(
  391. 'handler' => 'views_handler_field',
  392. 'click sortable' => TRUE, // This is use by the table display plugin.
  393. ),
  394. 'sort' => array(
  395. 'handler' => 'views_handler_sort',
  396. ),
  397. 'filter' => array(
  398. 'handler' => 'views_handler_filter_string',
  399. ),
  400. 'argument' => array(
  401. 'handler' => 'views_handler_argument_string',
  402. ),
  403. );
  404. // last_update
  405. $data['tripal_mviews']['last_update'] = array(
  406. 'title' => t('Updated'),
  407. 'help' => t('Date Last Updated.'),
  408. 'field' => array(
  409. 'handler' => 'views_handler_field_date',
  410. 'click sortable' => TRUE,
  411. ),
  412. 'sort' => array(
  413. 'handler' => 'views_handler_sort_date',
  414. ),
  415. 'filter' => array(
  416. 'handler' => 'views_handler_filter_date',
  417. ),
  418. );
  419. // status
  420. $data['tripal_mviews']['status'] = array(
  421. 'title' => t('Status'),
  422. 'help' => t('The status of the materialized view.'),
  423. 'field' => array(
  424. 'handler' => 'views_handler_field',
  425. 'click sortable' => TRUE, // This is use by the table display plugin.
  426. ),
  427. 'sort' => array(
  428. 'handler' => 'views_handler_sort',
  429. ),
  430. 'filter' => array(
  431. 'handler' => 'views_handler_filter_string',
  432. ),
  433. 'argument' => array(
  434. 'handler' => 'views_handler_argument_string',
  435. ),
  436. );
  437. // comment
  438. $data['tripal_mviews']['comment'] = array(
  439. 'title' => t('Description'),
  440. 'help' => t('Human-Readable Admin Description.'),
  441. 'field' => array(
  442. 'handler' => 'views_handler_field',
  443. 'click sortable' => TRUE, // This is use by the table display plugin.
  444. ),
  445. 'sort' => array(
  446. 'handler' => 'views_handler_sort',
  447. ),
  448. 'filter' => array(
  449. 'handler' => 'views_handler_filter_string',
  450. ),
  451. 'argument' => array(
  452. 'handler' => 'views_handler_argument_string',
  453. ),
  454. );
  455. return $data;
  456. }