tripal_analysis.views.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. // get the setup with the lightest priority. That's the table
  35. // that currently integrated with views.
  36. $priority = 9;
  37. // check to see if the table is integrated. If it is then integrate it's
  38. // corresponding 'chado_[table]' table.
  39. if (!tripal_views_is_integrated($tablename, $priority)) {
  40. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  41. // Make table-specific modifications
  42. $table_integration_array['fields']['program']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  43. $table_integration_array['fields']['algorithm']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  44. // Add in node relationships if chado is in the same db as drupal
  45. if (tripal_core_chado_schema_exists()) {
  46. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  47. foreach ($integrations as $integration) {
  48. tripal_views_integration_add_entry($integration);
  49. }
  50. }
  51. else {
  52. tripal_views_integration_add_entry($table_integration_array);
  53. }
  54. }
  55. $tables = array(
  56. 'analysisfeature',
  57. 'analysisprop'
  58. );
  59. foreach ($tables as $tablename) {
  60. $priority = 9;
  61. if (!tripal_views_is_integrated($tablename, $priority)) {
  62. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  63. tripal_views_integration_add_entry($table_integration_array);
  64. }
  65. }
  66. }
  67. return $data;
  68. }
  69. /**
  70. * Implements hook_views_handlers()
  71. *
  72. * Purpose: Register all custom handlers with views
  73. * where a handler describes either "the type of field",
  74. * "how a field should be filtered", "how a field should be sorted"
  75. *
  76. * @return
  77. * An array of handler definitions
  78. *
  79. * @ingroup tripal_analysis_views
  80. */
  81. function tripal_analysis_views_views_handlers() {
  82. return array(
  83. 'info' => array(
  84. 'path' => drupal_get_path('module', 'tripal_analysis') . '/views/handlers',
  85. ),
  86. 'handlers' => array(
  87. 'views_handler_field_computed_analysis_nid' => array(
  88. 'parent' => 'views_handler_field_numeric',
  89. ),
  90. 'views_handler_field_readable_date' => array(
  91. 'parent' => 'views_handler_field',
  92. ),
  93. ),
  94. );
  95. }
  96. /**
  97. * Implementation of hook_views_data_alter().
  98. */
  99. function tripal_analysis_views_data_alter(&$data) {
  100. if (!(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  101. // Add featuer relationship to node
  102. $data['node']['analysis_chado_nid'] = array(
  103. 'group' => 'Analysis',
  104. 'title' => 'Analysis Node',
  105. 'help' => 'Links Chado analysis Fields/Data to the Nodes in the current View.',
  106. 'real field' => 'nid',
  107. 'relationship' => array(
  108. 'handler' => 'views_handler_relationship',
  109. 'title' => t('Node => Chado'),
  110. 'label' => t('Node => Chado'),
  111. 'real field' => 'nid',
  112. 'base' => 'chado_analysis',
  113. 'base field' => 'nid'
  114. ),
  115. );
  116. }
  117. }
  118. /**
  119. * Implements hook_views_default_views().
  120. *
  121. * @ingroup tripal_analysis_views
  122. */
  123. function tripal_analysis_views_default_views() {
  124. $views = array();
  125. if (!module_exists('tripal_views')) {
  126. return $views;
  127. }
  128. // Main default view
  129. $view = new view;
  130. $view->name = 'analysis_listing';
  131. $view->description = 'A default listing of analyses provided by Tripal';
  132. $view->tag = 'chado default';
  133. $view->base_table = 'analysis';
  134. $view->core = 0;
  135. $view->api_version = '2';
  136. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  137. $handler = $view->new_display('default', 'Defaults', 'default');
  138. $handler->override_option('fields', array(
  139. 'name' => array(
  140. 'label' => 'Name',
  141. 'alter' => array(
  142. 'alter_text' => 0,
  143. 'text' => '',
  144. 'make_link' => 0,
  145. 'path' => '',
  146. 'absolute' => 0,
  147. 'link_class' => '',
  148. 'alt' => '',
  149. 'rel' => '',
  150. 'prefix' => '',
  151. 'suffix' => '',
  152. 'target' => '',
  153. 'help' => '',
  154. 'trim' => 0,
  155. 'max_length' => '',
  156. 'word_boundary' => 1,
  157. 'ellipsis' => 1,
  158. 'html' => 0,
  159. 'strip_tags' => 0,
  160. ),
  161. 'empty' => '',
  162. 'hide_empty' => 0,
  163. 'empty_zero' => 0,
  164. 'hide_alter_empty' => 1,
  165. 'type' => 'separator',
  166. 'separator' => ', ',
  167. 'exclude' => 0,
  168. 'link_to_node' => 1,
  169. 'id' => 'name',
  170. 'table' => 'analysis',
  171. 'field' => 'name',
  172. 'relationship' => 'none',
  173. ),
  174. 'program' => array(
  175. 'label' => 'Program',
  176. 'alter' => array(
  177. 'alter_text' => 0,
  178. 'text' => '',
  179. 'make_link' => 0,
  180. 'path' => '',
  181. 'absolute' => 0,
  182. 'link_class' => '',
  183. 'alt' => '',
  184. 'rel' => '',
  185. 'prefix' => '',
  186. 'suffix' => '',
  187. 'target' => '',
  188. 'help' => '',
  189. 'trim' => 0,
  190. 'max_length' => '',
  191. 'word_boundary' => 1,
  192. 'ellipsis' => 1,
  193. 'html' => 0,
  194. 'strip_tags' => 0,
  195. ),
  196. 'empty' => '',
  197. 'hide_empty' => 0,
  198. 'empty_zero' => 0,
  199. 'hide_alter_empty' => 1,
  200. 'exclude' => 0,
  201. 'id' => 'program',
  202. 'table' => 'analysis',
  203. 'field' => 'program',
  204. 'relationship' => 'none',
  205. ),
  206. 'sourcename' => array(
  207. 'label' => 'Source',
  208. 'alter' => array(
  209. 'alter_text' => 0,
  210. 'text' => '',
  211. 'make_link' => 0,
  212. 'path' => '',
  213. 'absolute' => 0,
  214. 'link_class' => '',
  215. 'alt' => '',
  216. 'rel' => '',
  217. 'prefix' => '',
  218. 'suffix' => '',
  219. 'target' => '',
  220. 'help' => '',
  221. 'trim' => 0,
  222. 'max_length' => '',
  223. 'word_boundary' => 1,
  224. 'ellipsis' => 1,
  225. 'html' => 0,
  226. 'strip_tags' => 0,
  227. ),
  228. 'empty' => '',
  229. 'hide_empty' => 0,
  230. 'empty_zero' => 0,
  231. 'hide_alter_empty' => 1,
  232. 'exclude' => 0,
  233. 'id' => 'sourcename',
  234. 'table' => 'analysis',
  235. 'field' => 'sourcename',
  236. 'relationship' => 'none',
  237. ),
  238. 'timeexecuted' => array(
  239. 'label' => 'Time Executed',
  240. 'alter' => array(
  241. 'alter_text' => 0,
  242. 'text' => '',
  243. 'make_link' => 0,
  244. 'path' => '',
  245. 'absolute' => 0,
  246. 'link_class' => '',
  247. 'alt' => '',
  248. 'rel' => '',
  249. 'prefix' => '',
  250. 'suffix' => '',
  251. 'target' => '',
  252. 'help' => '',
  253. 'trim' => 0,
  254. 'max_length' => '',
  255. 'word_boundary' => 1,
  256. 'ellipsis' => 1,
  257. 'html' => 0,
  258. 'strip_tags' => 0,
  259. ),
  260. 'empty' => '',
  261. 'hide_empty' => 0,
  262. 'empty_zero' => 0,
  263. 'hide_alter_empty' => 1,
  264. 'date_format' => 'custom',
  265. 'custom_date_format' => 'F j, Y',
  266. 'exclude' => 0,
  267. 'id' => 'timeexecuted',
  268. 'table' => 'analysis',
  269. 'field' => 'timeexecuted',
  270. 'override' => array(
  271. 'button' => 'Override',
  272. ),
  273. 'relationship' => 'none',
  274. ),
  275. ));
  276. $handler->override_option('filters', array(
  277. 'search_results' => array(
  278. 'operator' => '=',
  279. 'value' => '',
  280. 'group' => '0',
  281. 'exposed' => FALSE,
  282. 'expose' => array(
  283. 'operator' => FALSE,
  284. 'label' => '',
  285. ),
  286. 'id' => 'search_results',
  287. 'table' => 'views',
  288. 'field' => 'search_results',
  289. 'relationship' => 'none',
  290. 'apply_button' => 'Show ',
  291. '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.',
  292. ),
  293. 'program' => array(
  294. 'operator' => '=',
  295. 'value' => '',
  296. 'group' => '0',
  297. 'exposed' => TRUE,
  298. 'expose' => array(
  299. 'use_operator' => 0,
  300. 'operator' => 'program_op',
  301. 'identifier' => 'program',
  302. 'label' => 'Program',
  303. 'remember' => 0,
  304. ),
  305. 'case' => 1,
  306. 'id' => 'program',
  307. 'table' => 'analysis',
  308. 'field' => 'program',
  309. 'relationship' => 'none',
  310. 'values_form_type' => 'select',
  311. 'multiple' => 1,
  312. 'optional' => 0,
  313. 'agg' => array(
  314. 'records_with' => 1,
  315. 'aggregates_with' => 0,
  316. ),
  317. ),
  318. 'timeexecuted' => array(
  319. 'operator' => '>',
  320. 'value' => array(
  321. 'type' => 'date',
  322. 'value' => '',
  323. 'min' => '',
  324. 'max' => '',
  325. ),
  326. 'group' => '0',
  327. 'exposed' => TRUE,
  328. 'expose' => array(
  329. 'use_operator' => 1,
  330. 'operator' => 'timeexecuted_op',
  331. 'identifier' => 'timeexecuted',
  332. 'label' => 'Time Executed',
  333. 'optional' => 1,
  334. 'remember' => 0,
  335. ),
  336. 'id' => 'timeexecuted',
  337. 'table' => 'analysis',
  338. 'field' => 'timeexecuted',
  339. 'relationship' => 'none',
  340. 'agg' => array(
  341. 'records_with' => 1,
  342. 'aggregates_with' => 0,
  343. ),
  344. ),
  345. 'name' => array(
  346. 'operator' => '~',
  347. 'value' => '',
  348. 'group' => '0',
  349. 'exposed' => TRUE,
  350. 'expose' => array(
  351. 'use_operator' => 0,
  352. 'operator' => 'name_op',
  353. 'identifier' => 'name',
  354. 'label' => 'Name Contains',
  355. 'bef_filter_description' => '',
  356. 'remember' => 0,
  357. ),
  358. 'case' => 0,
  359. 'id' => 'name',
  360. 'table' => 'analysis',
  361. 'field' => 'name',
  362. 'relationship' => 'none',
  363. 'values_form_type' => 'textfield',
  364. 'multiple' => 0,
  365. 'optional' => 0,
  366. ),
  367. 'sourcename' => array(
  368. 'operator' => '~',
  369. 'value' => '',
  370. 'group' => '0',
  371. 'exposed' => TRUE,
  372. 'expose' => array(
  373. 'use_operator' => 0,
  374. 'operator' => 'sourcename_op',
  375. 'identifier' => 'sourcename',
  376. 'label' => 'Source Contains',
  377. 'bef_filter_description' => '',
  378. 'remember' => 0,
  379. ),
  380. 'case' => 0,
  381. 'id' => 'sourcename',
  382. 'table' => 'analysis',
  383. 'field' => 'sourcename',
  384. 'relationship' => 'none',
  385. ),
  386. ));
  387. $handler->override_option('access', array(
  388. 'type' => 'perm',
  389. 'perm' => 'access chado_analysis content',
  390. ));
  391. $handler->override_option('cache', array(
  392. 'type' => 'none',
  393. ));
  394. $handler->override_option('title', 'Analysis');
  395. $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.');
  396. $handler->override_option('header_format', '2');
  397. $handler->override_option('header_empty', 1);
  398. $handler->override_option('empty', 'No analyses match the supplied criteria.');
  399. $handler->override_option('empty_format', '1');
  400. $handler->override_option('items_per_page', 50);
  401. $handler->override_option('use_pager', '1');
  402. $handler->override_option('style_plugin', 'table');
  403. $handler->override_option('style_options', array(
  404. 'grouping' => '',
  405. 'override' => 1,
  406. 'sticky' => 0,
  407. 'order' => 'asc',
  408. 'summary' => '',
  409. 'columns' => array(
  410. 'name' => 'name',
  411. 'program' => 'program',
  412. 'sourcename' => 'sourcename',
  413. 'num_features' => 'num_features',
  414. 'timeexecuted' => 'timeexecuted',
  415. ),
  416. 'info' => array(
  417. 'name' => array(
  418. 'sortable' => 1,
  419. 'separator' => '',
  420. ),
  421. 'program' => array(
  422. 'sortable' => 1,
  423. 'separator' => '',
  424. ),
  425. 'sourcename' => array(
  426. 'sortable' => 1,
  427. 'separator' => '',
  428. ),
  429. 'num_features' => array(
  430. 'separator' => '',
  431. ),
  432. 'timeexecuted' => array(
  433. 'sortable' => 1,
  434. 'separator' => '',
  435. ),
  436. ),
  437. 'default' => 'name',
  438. ));
  439. // this is needed so that fields/filters can be added to the default display later
  440. $default_handler = $handler;
  441. $handler = $view->new_display('page', 'Page', 'page_1');
  442. $handler->override_option('path', 'chado/analyses');
  443. $handler->override_option('menu', array(
  444. 'type' => 'normal',
  445. 'title' => 'Analyses',
  446. '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.',
  447. 'weight' => '10',
  448. 'name' => 'navigation',
  449. ));
  450. $handler->override_option('tab_options', array(
  451. 'type' => 'none',
  452. 'title' => '',
  453. 'description' => '',
  454. 'weight' => 0,
  455. 'name' => 'navigation',
  456. ));
  457. // Add code specific to a local chado installation
  458. // NOTE: Edit $handler above to $default_handler for the default display
  459. if (tripal_core_chado_schema_exists()) {
  460. // Add nid field
  461. $fields = $view->get_items('field', 'default');
  462. $new_fields = array(
  463. 'nid' => array(
  464. 'label' => 'Nid',
  465. 'alter' => array(
  466. 'alter_text' => 0,
  467. 'text' => '',
  468. 'make_link' => 0,
  469. 'path' => '',
  470. 'absolute' => 0,
  471. 'link_class' => '',
  472. 'alt' => '',
  473. 'rel' => '',
  474. 'prefix' => '',
  475. 'suffix' => '',
  476. 'target' => '',
  477. 'help' => '',
  478. 'trim' => 0,
  479. 'max_length' => '',
  480. 'word_boundary' => 1,
  481. 'ellipsis' => 1,
  482. 'html' => 0,
  483. 'strip_tags' => 0,
  484. ),
  485. 'empty' => '',
  486. 'hide_empty' => 0,
  487. 'empty_zero' => 0,
  488. 'hide_alter_empty' => 1,
  489. 'link_to_node' => 0,
  490. 'exclude' => 1,
  491. 'id' => 'nid',
  492. 'table' => 'node',
  493. 'field' => 'nid',
  494. 'relationship' => 'none',
  495. )
  496. );
  497. $fields = $new_fields + $fields;
  498. // Adds analysis => Node relationship
  499. $default_handler->override_option('relationships', array(
  500. 'nid' => array(
  501. 'label' => 'Analysis to Node',
  502. 'required' => 0,
  503. 'id' => 'nid',
  504. 'table' => 'chado_analysis',
  505. 'field' => 'nid',
  506. 'relationship' => 'none',
  507. ),
  508. ));
  509. // Change analysis.name to have a link to the node
  510. $fields['name']['link_to_node'] = 1;
  511. $default_handler->override_option('fields', $fields);
  512. // Only show records with published nodes
  513. /**
  514. $filters = $view->get_items('filter', 'default');
  515. $filters['status'] = array(
  516. 'operator' => '=',
  517. 'value' => '1',
  518. 'group' => '0',
  519. 'exposed' => FALSE,
  520. 'expose' => array(
  521. 'operator' => FALSE,
  522. 'label' => '',
  523. ),
  524. 'id' => 'status',
  525. 'table' => 'node',
  526. 'field' => 'status',
  527. 'relationship' => 'none',
  528. );
  529. $default_handler->override_option('filters', $filters);
  530. */
  531. }
  532. $views[$view->name] = $view;
  533. return $views;
  534. }