tripal_analysis.views.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal analysis tables. Supplementary functions can be found in
  6. * ./views/
  7. *
  8. * Documentation on views integration can be found at
  9. * http://views2.logrus.com/doc/html/index.html.
  10. */
  11. /**
  12. * @defgroup tripal_analysis_views Analysis Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_analysis
  15. */
  16. /**
  17. * Implements hook_views_data()
  18. *
  19. * Purpose: Describe chado/tripal tables & fields to views
  20. *
  21. * @return: a data array which follows the structure outlined in the
  22. * views2 documentation for this hook. Essentially, it's an array of table
  23. * definitions keyed by chado/tripal table name. Each table definition
  24. * includes basic details about the table, fields in that table and
  25. * relationships between that table and others (joins)
  26. *
  27. * @ingroup tripal_analysis_views
  28. */
  29. function tripal_analysis_views_data() {
  30. $data = array();
  31. if (module_exists('tripal_views')) {
  32. // Base Table: Analysis
  33. $tablename = 'analysis';
  34. if (!tripal_views_is_integrated($tablename, 9)) {
  35. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  36. // Make table-specific modifications
  37. $table_integration_array['fields']['program']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  38. $table_integration_array['fields']['algorithm']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  39. tripal_views_integration_add_entry($table_integration_array);
  40. }
  41. $tables = array(
  42. 'analysisfeature',
  43. 'analysisprop'
  44. );
  45. foreach ($tables as $tablename) {
  46. if (!tripal_views_is_integrated($tablename, 9)) {
  47. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  48. tripal_views_integration_add_entry($table_integration_array);
  49. }
  50. }
  51. }
  52. return $data;
  53. }
  54. /**
  55. * Implements hook_views_handlers()
  56. *
  57. * Purpose: Register all custom handlers with views
  58. * where a handler describes either "the type of field",
  59. * "how a field should be filtered", "how a field should be sorted"
  60. *
  61. * @return
  62. * An array of handler definitions
  63. *
  64. * @ingroup tripal_analysis_views
  65. */
  66. function tripal_analysis_views_views_handlers() {
  67. return array(
  68. 'info' => array(
  69. 'path' => drupal_get_path('module', 'tripal_analysis') . '/views/handlers',
  70. ),
  71. 'handlers' => array(
  72. 'views_handler_field_computed_analysis_nid' => array(
  73. 'parent' => 'views_handler_field_numeric',
  74. ),
  75. 'views_handler_field_readable_date' => array(
  76. 'parent' => 'views_handler_field',
  77. ),
  78. ),
  79. );
  80. }
  81. /**
  82. * Implementation of hook_views_data_alter().
  83. */
  84. function tripal_analysis_views_data_alter(&$data) {
  85. if (!(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  86. // Add featuer relationship to node
  87. $data['node']['analysis_chado_nid'] = array(
  88. 'group' => 'Analysis',
  89. 'title' => 'Analysis Node',
  90. 'help' => 'Links Chado analysis Fields/Data to the Nodes in the current View.',
  91. 'real field' => 'nid',
  92. 'relationship' => array(
  93. 'handler' => 'views_handler_relationship',
  94. 'title' => t('Node => Chado'),
  95. 'label' => t('Node => Chado'),
  96. 'real field' => 'nid',
  97. 'base' => 'chado_analysis',
  98. 'base field' => 'nid'
  99. ),
  100. );
  101. }
  102. }
  103. /**
  104. * Implements hook_views_default_views().
  105. *
  106. * @ingroup tripal_analysis_views
  107. */
  108. function tripal_analysis_views_default_views() {
  109. $views = array();
  110. // Main default view
  111. $view = new view;
  112. $view->name = 'analysis_listing';
  113. $view->description = 'A default listing of analyses provided by Tripal';
  114. $view->tag = 'chado default';
  115. $view->base_table = 'analysis';
  116. $view->core = 0;
  117. $view->api_version = '2';
  118. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  119. $handler = $view->new_display('default', 'Defaults', 'default');
  120. $handler->override_option('fields', array(
  121. 'name' => array(
  122. 'label' => 'Name',
  123. 'alter' => array(
  124. 'alter_text' => 0,
  125. 'text' => '',
  126. 'make_link' => 0,
  127. 'path' => '',
  128. 'absolute' => 0,
  129. 'link_class' => '',
  130. 'alt' => '',
  131. 'rel' => '',
  132. 'prefix' => '',
  133. 'suffix' => '',
  134. 'target' => '',
  135. 'help' => '',
  136. 'trim' => 0,
  137. 'max_length' => '',
  138. 'word_boundary' => 1,
  139. 'ellipsis' => 1,
  140. 'html' => 0,
  141. 'strip_tags' => 0,
  142. ),
  143. 'empty' => '',
  144. 'hide_empty' => 0,
  145. 'empty_zero' => 0,
  146. 'hide_alter_empty' => 1,
  147. 'type' => 'separator',
  148. 'separator' => ', ',
  149. 'exclude' => 0,
  150. 'link_to_node' => 1,
  151. 'id' => 'name',
  152. 'table' => 'analysis',
  153. 'field' => 'name',
  154. 'relationship' => 'none',
  155. ),
  156. 'program' => array(
  157. 'label' => 'Program',
  158. 'alter' => array(
  159. 'alter_text' => 0,
  160. 'text' => '',
  161. 'make_link' => 0,
  162. 'path' => '',
  163. 'absolute' => 0,
  164. 'link_class' => '',
  165. 'alt' => '',
  166. 'rel' => '',
  167. 'prefix' => '',
  168. 'suffix' => '',
  169. 'target' => '',
  170. 'help' => '',
  171. 'trim' => 0,
  172. 'max_length' => '',
  173. 'word_boundary' => 1,
  174. 'ellipsis' => 1,
  175. 'html' => 0,
  176. 'strip_tags' => 0,
  177. ),
  178. 'empty' => '',
  179. 'hide_empty' => 0,
  180. 'empty_zero' => 0,
  181. 'hide_alter_empty' => 1,
  182. 'exclude' => 0,
  183. 'id' => 'program',
  184. 'table' => 'analysis',
  185. 'field' => 'program',
  186. 'relationship' => 'none',
  187. ),
  188. 'sourcename' => array(
  189. 'label' => 'Source',
  190. 'alter' => array(
  191. 'alter_text' => 0,
  192. 'text' => '',
  193. 'make_link' => 0,
  194. 'path' => '',
  195. 'absolute' => 0,
  196. 'link_class' => '',
  197. 'alt' => '',
  198. 'rel' => '',
  199. 'prefix' => '',
  200. 'suffix' => '',
  201. 'target' => '',
  202. 'help' => '',
  203. 'trim' => 0,
  204. 'max_length' => '',
  205. 'word_boundary' => 1,
  206. 'ellipsis' => 1,
  207. 'html' => 0,
  208. 'strip_tags' => 0,
  209. ),
  210. 'empty' => '',
  211. 'hide_empty' => 0,
  212. 'empty_zero' => 0,
  213. 'hide_alter_empty' => 1,
  214. 'exclude' => 0,
  215. 'id' => 'sourcename',
  216. 'table' => 'analysis',
  217. 'field' => 'sourcename',
  218. 'relationship' => 'none',
  219. ),
  220. 'timeexecuted' => array(
  221. 'label' => 'Time Executed',
  222. 'alter' => array(
  223. 'alter_text' => 0,
  224. 'text' => '',
  225. 'make_link' => 0,
  226. 'path' => '',
  227. 'absolute' => 0,
  228. 'link_class' => '',
  229. 'alt' => '',
  230. 'rel' => '',
  231. 'prefix' => '',
  232. 'suffix' => '',
  233. 'target' => '',
  234. 'help' => '',
  235. 'trim' => 0,
  236. 'max_length' => '',
  237. 'word_boundary' => 1,
  238. 'ellipsis' => 1,
  239. 'html' => 0,
  240. 'strip_tags' => 0,
  241. ),
  242. 'empty' => '',
  243. 'hide_empty' => 0,
  244. 'empty_zero' => 0,
  245. 'hide_alter_empty' => 1,
  246. 'date_format' => 'custom',
  247. 'custom_date_format' => 'F j, Y',
  248. 'exclude' => 0,
  249. 'id' => 'timeexecuted',
  250. 'table' => 'analysis',
  251. 'field' => 'timeexecuted',
  252. 'override' => array(
  253. 'button' => 'Override',
  254. ),
  255. 'relationship' => 'none',
  256. ),
  257. ));
  258. $handler->override_option('filters', array(
  259. 'search_results' => array(
  260. 'operator' => '=',
  261. 'value' => '',
  262. 'group' => '0',
  263. 'exposed' => FALSE,
  264. 'expose' => array(
  265. 'operator' => FALSE,
  266. 'label' => '',
  267. ),
  268. 'id' => 'search_results',
  269. 'table' => 'views',
  270. 'field' => 'search_results',
  271. 'relationship' => 'none',
  272. 'apply_button' => 'Show ',
  273. 'no_results_text' => 'Click "Show" to see a list of all analysis matching the entered criteria. If you leave a any of the criteria blank then the analysis will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all analysis will be listed.',
  274. ),
  275. 'program' => array(
  276. 'operator' => '=',
  277. 'value' => array(),
  278. 'group' => '0',
  279. 'exposed' => TRUE,
  280. 'expose' => array(
  281. 'use_operator' => 0,
  282. 'operator' => 'program_op',
  283. 'identifier' => 'program',
  284. 'label' => 'Program',
  285. 'remember' => 0,
  286. ),
  287. 'case' => 1,
  288. 'id' => 'program',
  289. 'table' => 'analysis',
  290. 'field' => 'program',
  291. 'relationship' => 'none',
  292. 'values_form_type' => 'select',
  293. 'multiple' => 1,
  294. 'optional' => 0,
  295. 'agg' => array(
  296. 'records_with' => 1,
  297. 'aggregates_with' => 0,
  298. ),
  299. ),
  300. 'timeexecuted' => array(
  301. 'operator' => '>',
  302. 'value' => array(
  303. 'type' => 'date',
  304. 'value' => '',
  305. 'min' => '',
  306. 'max' => '',
  307. ),
  308. 'group' => '0',
  309. 'exposed' => TRUE,
  310. 'expose' => array(
  311. 'use_operator' => 1,
  312. 'operator' => 'timeexecuted_op',
  313. 'identifier' => 'timeexecuted',
  314. 'label' => 'Time Executed',
  315. 'optional' => 1,
  316. 'remember' => 0,
  317. ),
  318. 'id' => 'timeexecuted',
  319. 'table' => 'analysis',
  320. 'field' => 'timeexecuted',
  321. 'relationship' => 'none',
  322. 'agg' => array(
  323. 'records_with' => 1,
  324. 'aggregates_with' => 0,
  325. ),
  326. ),
  327. 'name' => array(
  328. 'operator' => 'contains',
  329. 'value' => '',
  330. 'group' => '0',
  331. 'exposed' => TRUE,
  332. 'expose' => array(
  333. 'use_operator' => 0,
  334. 'operator' => 'name_op',
  335. 'identifier' => 'name',
  336. 'label' => 'Name Contains',
  337. 'bef_filter_description' => '',
  338. 'remember' => 0,
  339. ),
  340. 'case' => 0,
  341. 'id' => 'name',
  342. 'table' => 'analysis',
  343. 'field' => 'name',
  344. 'relationship' => 'none',
  345. 'values_form_type' => 'textfield',
  346. 'multiple' => 0,
  347. 'optional' => 0,
  348. ),
  349. 'sourcename' => array(
  350. 'operator' => 'contains',
  351. 'value' => '',
  352. 'group' => '0',
  353. 'exposed' => TRUE,
  354. 'expose' => array(
  355. 'use_operator' => 0,
  356. 'operator' => 'sourcename_op',
  357. 'identifier' => 'sourcename',
  358. 'label' => 'Source Contains',
  359. 'bef_filter_description' => '',
  360. 'remember' => 0,
  361. ),
  362. 'case' => 0,
  363. 'id' => 'sourcename',
  364. 'table' => 'analysis',
  365. 'field' => 'sourcename',
  366. 'relationship' => 'none',
  367. ),
  368. ));
  369. $handler->override_option('access', array(
  370. 'type' => 'perm',
  371. 'perm' => 'access chado_analysis content',
  372. ));
  373. $handler->override_option('cache', array(
  374. 'type' => 'none',
  375. ));
  376. $handler->override_option('title', 'Analysis');
  377. $handler->override_option('header', 'Click "Show" to see a list of all analysis matching the entered criteria. If you leave a any of the criteria blank then the analysis will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all analysis will be listed.');
  378. $handler->override_option('header_format', '2');
  379. $handler->override_option('header_empty', 1);
  380. $handler->override_option('empty', 'No analysis match the supplied criteria.');
  381. $handler->override_option('empty_format', '1');
  382. $handler->override_option('items_per_page', 50);
  383. $handler->override_option('use_pager', '1');
  384. $handler->override_option('style_plugin', 'table');
  385. $handler->override_option('style_options', array(
  386. 'grouping' => '',
  387. 'override' => 1,
  388. 'sticky' => 0,
  389. 'order' => 'asc',
  390. 'summary' => '',
  391. 'columns' => array(
  392. 'name' => 'name',
  393. 'program' => 'program',
  394. 'sourcename' => 'sourcename',
  395. 'num_features' => 'num_features',
  396. 'timeexecuted' => 'timeexecuted',
  397. ),
  398. 'info' => array(
  399. 'name' => array(
  400. 'sortable' => 1,
  401. 'separator' => '',
  402. ),
  403. 'program' => array(
  404. 'sortable' => 1,
  405. 'separator' => '',
  406. ),
  407. 'sourcename' => array(
  408. 'sortable' => 1,
  409. 'separator' => '',
  410. ),
  411. 'num_features' => array(
  412. 'separator' => '',
  413. ),
  414. 'timeexecuted' => array(
  415. 'sortable' => 1,
  416. 'separator' => '',
  417. ),
  418. ),
  419. 'default' => 'name',
  420. ));
  421. $handler = $view->new_display('page', 'Page', 'page_1');
  422. $handler->override_option('path', 'chado/analyses');
  423. $handler->override_option('menu', array(
  424. 'type' => 'normal',
  425. 'title' => 'Analyses',
  426. 'description' => 'An analysis is a particular type of a computational analysis; it may be a blast of one sequence against another, or an all by all blast, or a different kind of analysis altogether. It is a single unit of computation.',
  427. 'weight' => '10',
  428. 'name' => 'navigation',
  429. ));
  430. $handler->override_option('tab_options', array(
  431. 'type' => 'none',
  432. 'title' => '',
  433. 'description' => '',
  434. 'weight' => 0,
  435. 'name' => 'navigation',
  436. ));
  437. $views[$view->name] = $view;
  438. return $views;
  439. }