tripal_organism.views.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal organism 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_organism_views Organism Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_organism
  15. */
  16. /**
  17. * Implements hook_views_data()
  18. * Purpose: Describe chado/tripal tables & fields to views
  19. * @return: a data array which follows the structure outlined in the
  20. * views2 documentation for this hook. Essentially, it's an array of table
  21. * definitions keyed by chado/tripal table name. Each table definition
  22. * includes basic details about the table, fields in that table and
  23. * relationships between that table and others (joins)
  24. *
  25. * @ingroup tripal_organism_views
  26. */
  27. function tripal_organism_views_data() {
  28. $data = array();
  29. if (module_exists('tripal_views')) {
  30. // Base Table
  31. $tables = array(
  32. 'organism'
  33. );
  34. foreach ($tables as $tablename) {
  35. $priority = 9;
  36. // check to see if the table is integrated. If it is then integrate it's
  37. // corresponding 'chado_[table]' table.
  38. if (!tripal_views_is_integrated($tablename, $priority)) {
  39. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  40. // Add specialty handlers
  41. $table_integration_array['fields']['common_name']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  42. $table_integration_array['fields']['genus']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  43. $table_integration_array['fields']['species']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  44. $table_integration_array['fields']['abbreviation']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  45. // Add in node relationships if chado is in the same db as drupal
  46. if (tripal_core_chado_schema_exists()) {
  47. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  48. foreach ($integrations as $integration) {
  49. tripal_views_integration_add_entry($integration);
  50. }
  51. }
  52. else {
  53. tripal_views_integration_add_entry($table_integration_array);
  54. }
  55. }
  56. }
  57. // Additional Tables
  58. $tables = array(
  59. 'organismprop',
  60. 'organism_dbxref'
  61. );
  62. foreach ($tables as $tablename) {
  63. $priority = 9;
  64. if (!tripal_views_is_integrated($tablename, $priority)) {
  65. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  66. tripal_views_integration_add_entry($table_integration_array);
  67. }
  68. }
  69. }
  70. return $data;
  71. }
  72. /**
  73. * Implements hook_views_handlers()
  74. * Purpose: Register all custom handlers with views
  75. * where a handler describes either "the type of field",
  76. * "how a field should be filtered", "how a field should be sorted"
  77. * @return: An array of handler definitions
  78. *
  79. * @ingroup tripal_organism_views
  80. */
  81. function tripal_organism_views_handlers() {
  82. return array(
  83. 'info' => array(
  84. 'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
  85. ),
  86. 'handlers' => array(
  87. 'views_handler_field_computed_organism_nid' => array(
  88. 'parent' => 'views_handler_field_numeric',
  89. ),
  90. 'views_handler_filter_organism_common_name' => array(
  91. 'parent' => 'views_handler_filter_string',
  92. ),
  93. ),
  94. );
  95. }
  96. /**
  97. * Implementation of hook_views_data_alter().
  98. */
  99. function tripal_organism_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']['organism_chado_nid'] = array(
  103. 'group' => 'Organism',
  104. 'title' => 'Organism Node',
  105. 'help' => 'Links Chado Organism 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_organism',
  113. 'base field' => 'nid'
  114. ),
  115. );
  116. }
  117. }
  118. /**
  119. *
  120. * @ingroup tripal_organism_views
  121. */
  122. function tripal_organism_views_default_views() {
  123. $views = array();
  124. if (!module_exists('tripal_views')) {
  125. return $views;
  126. }
  127. // Main default view
  128. $view = new view;
  129. $view->name = 'organism_listing';
  130. $view->description = 'A listing of all organism in chado';
  131. $view->tag = 'chado default';
  132. $view->base_table = 'organism';
  133. $view->core = 0;
  134. $view->api_version = '2';
  135. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  136. $handler = $view->new_display('default', 'Defaults', 'default');
  137. $handler->override_option('fields', array(
  138. 'common_name' => array(
  139. 'label' => 'Common Name',
  140. 'alter' => array(
  141. 'alter_text' => 0,
  142. 'text' => '',
  143. 'make_link' => 0,
  144. 'path' => '',
  145. 'link_class' => '',
  146. 'alt' => '',
  147. 'prefix' => '',
  148. 'suffix' => '',
  149. 'target' => '',
  150. 'help' => '',
  151. 'trim' => 0,
  152. 'max_length' => '',
  153. 'word_boundary' => 1,
  154. 'ellipsis' => 1,
  155. 'html' => 0,
  156. 'strip_tags' => 0,
  157. ),
  158. 'empty' => '',
  159. 'hide_empty' => 0,
  160. 'empty_zero' => 0,
  161. 'link_to_node' => 1,
  162. 'exclude' => 0,
  163. 'id' => 'common_name',
  164. 'table' => 'organism',
  165. 'field' => 'common_name',
  166. 'relationship' => 'none',
  167. ),
  168. 'genus' => array(
  169. 'label' => 'Genus',
  170. 'alter' => array(
  171. 'alter_text' => 0,
  172. 'text' => '',
  173. 'make_link' => 0,
  174. 'path' => '',
  175. 'link_class' => '',
  176. 'alt' => '',
  177. 'prefix' => '',
  178. 'suffix' => '',
  179. 'target' => '',
  180. 'help' => '',
  181. 'trim' => 0,
  182. 'max_length' => '',
  183. 'word_boundary' => 1,
  184. 'ellipsis' => 1,
  185. 'html' => 0,
  186. 'strip_tags' => 0,
  187. ),
  188. 'empty' => '',
  189. 'hide_empty' => 0,
  190. 'empty_zero' => 0,
  191. 'exclude' => 0,
  192. 'id' => 'genus',
  193. 'table' => 'organism',
  194. 'field' => 'genus',
  195. 'relationship' => 'none',
  196. ),
  197. 'species' => array(
  198. 'label' => 'Species',
  199. 'alter' => array(
  200. 'alter_text' => 0,
  201. 'text' => '',
  202. 'make_link' => 0,
  203. 'path' => '',
  204. 'link_class' => '',
  205. 'alt' => '',
  206. 'prefix' => '',
  207. 'suffix' => '',
  208. 'target' => '',
  209. 'help' => '',
  210. 'trim' => 0,
  211. 'max_length' => '',
  212. 'word_boundary' => 1,
  213. 'ellipsis' => 1,
  214. 'html' => 0,
  215. 'strip_tags' => 0,
  216. ),
  217. 'empty' => '',
  218. 'hide_empty' => 0,
  219. 'empty_zero' => 0,
  220. 'exclude' => 0,
  221. 'id' => 'species',
  222. 'table' => 'organism',
  223. 'field' => 'species',
  224. 'relationship' => 'none',
  225. ),
  226. 'abbreviation' => array(
  227. 'label' => 'Abbreviation',
  228. 'alter' => array(
  229. 'alter_text' => 0,
  230. 'text' => '',
  231. 'make_link' => 0,
  232. 'path' => '',
  233. 'link_class' => '',
  234. 'alt' => '',
  235. 'prefix' => '',
  236. 'suffix' => '',
  237. 'target' => '',
  238. 'help' => '',
  239. 'trim' => 0,
  240. 'max_length' => '',
  241. 'word_boundary' => 1,
  242. 'ellipsis' => 1,
  243. 'html' => 0,
  244. 'strip_tags' => 0,
  245. ),
  246. 'empty' => '',
  247. 'hide_empty' => 0,
  248. 'empty_zero' => 0,
  249. 'link_to_node' => 0,
  250. 'exclude' => 0,
  251. 'id' => 'abbreviation',
  252. 'table' => 'organism',
  253. 'field' => 'abbreviation',
  254. 'relationship' => 'none',
  255. ),
  256. ));
  257. $handler->override_option('sorts', array(
  258. 'genus' => array(
  259. 'order' => 'ASC',
  260. 'id' => 'genus',
  261. 'table' => 'organism',
  262. 'field' => 'genus',
  263. 'relationship' => 'none',
  264. ),
  265. 'species' => array(
  266. 'order' => 'ASC',
  267. 'id' => 'species',
  268. 'table' => 'organism',
  269. 'field' => 'species',
  270. 'relationship' => 'none',
  271. ),
  272. ));
  273. $handler->override_option('access', array(
  274. 'type' => 'perm',
  275. 'perm' => 'access chado_organism content',
  276. ));
  277. $handler->override_option('cache', array(
  278. 'type' => 'none',
  279. ));
  280. $handler->override_option('title', 'Organisms');
  281. $handler->override_option('empty', 'No organisms matched the supplied criteria.');
  282. $handler->override_option('empty_format', '1');
  283. $handler->override_option('items_per_page', 0);
  284. $handler->override_option('style_plugin', 'table');
  285. $handler->override_option('style_options', array(
  286. 'grouping' => '',
  287. 'override' => 1,
  288. 'sticky' => 0,
  289. 'order' => 'asc',
  290. 'summary' => '',
  291. 'columns' => array(
  292. 'common_name' => 'common_name',
  293. 'genus' => 'genus',
  294. 'species' => 'species',
  295. 'abbreviation' => 'abbreviation',
  296. ),
  297. 'info' => array(
  298. 'common_name' => array(
  299. 'sortable' => 1,
  300. 'separator' => '',
  301. ),
  302. 'genus' => array(
  303. 'sortable' => 1,
  304. 'separator' => '',
  305. ),
  306. 'species' => array(
  307. 'sortable' => 1,
  308. 'separator' => '',
  309. ),
  310. 'abbreviation' => array(
  311. 'sortable' => 1,
  312. 'separator' => '',
  313. ),
  314. ),
  315. 'default' => '-1',
  316. ));
  317. $default_handler = $handler;
  318. $handler = $view->new_display('page', 'Page', 'page_1');
  319. $handler->override_option('path', 'chado/organisms');
  320. $handler->override_option('menu', array(
  321. 'type' => 'normal',
  322. 'title' => 'Organisms',
  323. 'description' => 'A biological organism.',
  324. 'weight' => '10',
  325. 'name' => 'navigation',
  326. ));
  327. $handler->override_option('tab_options', array(
  328. 'type' => 'none',
  329. 'title' => '',
  330. 'description' => '',
  331. 'weight' => 0,
  332. 'name' => 'navigation',
  333. ));
  334. // Add code specific to a local chado installation
  335. // NOTE: Edit $handler above to $default_handler for the default display
  336. if (tripal_core_chado_schema_exists()) {
  337. // Add nid field
  338. $fields = $view->get_items('field', 'default');
  339. $new_fields = array(
  340. 'nid' => array(
  341. 'label' => 'Nid',
  342. 'alter' => array(
  343. 'alter_text' => 0,
  344. 'text' => '',
  345. 'make_link' => 0,
  346. 'path' => '',
  347. 'absolute' => 0,
  348. 'link_class' => '',
  349. 'alt' => '',
  350. 'rel' => '',
  351. 'prefix' => '',
  352. 'suffix' => '',
  353. 'target' => '',
  354. 'help' => '',
  355. 'trim' => 0,
  356. 'max_length' => '',
  357. 'word_boundary' => 1,
  358. 'ellipsis' => 1,
  359. 'html' => 0,
  360. 'strip_tags' => 0,
  361. ),
  362. 'empty' => '',
  363. 'hide_empty' => 0,
  364. 'empty_zero' => 0,
  365. 'hide_alter_empty' => 1,
  366. 'link_to_node' => 0,
  367. 'exclude' => 1,
  368. 'id' => 'nid',
  369. 'table' => 'node',
  370. 'field' => 'nid',
  371. 'relationship' => 'none',
  372. )
  373. );
  374. $fields = $new_fields + $fields;
  375. // Adds organism => Node relationship
  376. $default_handler->override_option('relationships', array(
  377. 'nid' => array(
  378. 'label' => 'Organism to Node',
  379. 'required' => 0,
  380. 'id' => 'nid',
  381. 'table' => 'chado_organism',
  382. 'field' => 'nid',
  383. 'relationship' => 'none',
  384. ),
  385. ));
  386. // Change analysis.name to have a link to the node
  387. $fields['common_name']['alter']['make_link'] = 1;
  388. $fields['common_name']['alter']['path'] = 'node/[nid]';
  389. $default_handler->override_option('fields', $fields);
  390. // Only show records with published nodes
  391. $filters = $view->get_items('filter', 'default');
  392. $filters['status'] = array(
  393. 'operator' => '=',
  394. 'value' => '1',
  395. 'group' => '0',
  396. 'exposed' => FALSE,
  397. 'expose' => array(
  398. 'operator' => FALSE,
  399. 'label' => '',
  400. ),
  401. 'id' => 'status',
  402. 'table' => 'node',
  403. 'field' => 'status',
  404. 'relationship' => 'none',
  405. );
  406. $default_handler->override_option('filters', $filters);
  407. }
  408. $views[$view->name] = $view;
  409. return $views;
  410. }