tripal_organism.views.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. if (!tripal_views_is_integrated($tablename, 9)) {
  36. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  37. // Add specialty handlers
  38. $table_integration_array['fields']['common_name']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  39. $table_integration_array['fields']['genus']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  40. $table_integration_array['fields']['species']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  41. $table_integration_array['fields']['abbreviation']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
  42. tripal_views_integration_add_entry($table_integration_array);
  43. }
  44. }
  45. // Additional Tables
  46. $tables = array(
  47. 'organismprop',
  48. 'organism_dbxref'
  49. );
  50. foreach ($tables as $tablename) {
  51. if (!tripal_views_is_integrated($tablename, 9)) {
  52. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  53. tripal_views_integration_add_entry($table_integration_array);
  54. }
  55. }
  56. }
  57. return $data;
  58. }
  59. /**
  60. * Implements hook_views_handlers()
  61. * Purpose: Register all custom handlers with views
  62. * where a handler describes either "the type of field",
  63. * "how a field should be filtered", "how a field should be sorted"
  64. * @return: An array of handler definitions
  65. *
  66. * @ingroup tripal_organism_views
  67. */
  68. function tripal_organism_views_handlers() {
  69. return array(
  70. 'info' => array(
  71. 'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
  72. ),
  73. 'handlers' => array(
  74. 'views_handler_field_computed_organism_nid' => array(
  75. 'parent' => 'views_handler_field_numeric',
  76. ),
  77. 'views_handler_filter_organism_common_name' => array(
  78. 'parent' => 'views_handler_filter_string',
  79. ),
  80. ),
  81. );
  82. }
  83. /**
  84. * Implementation of hook_views_data_alter().
  85. */
  86. function tripal_organism_views_data_alter(&$data) {
  87. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  88. // Add featuer relationship to node
  89. $data['node']['organism_chado_nid'] = array(
  90. 'group' => 'Organism',
  91. 'title' => 'Organism Node',
  92. 'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
  93. 'real field' => 'nid',
  94. 'relationship' => array(
  95. 'handler' => 'views_handler_relationship',
  96. 'title' => t('Node => Chado'),
  97. 'label' => t('Node => Chado'),
  98. 'real field' => 'nid',
  99. 'base' => 'chado_organism',
  100. 'base field' => 'nid'
  101. ),
  102. );
  103. }
  104. }
  105. /**
  106. *
  107. * @ingroup tripal_organism_views
  108. */
  109. function tripal_organism_views_default_views() {
  110. $views = array();
  111. // Main default view
  112. $view = new view;
  113. $view->name = 'organism_listing';
  114. $view->description = 'A listing of all organism in chado';
  115. $view->tag = 'chado default';
  116. $view->base_table = 'organism';
  117. $view->core = 0;
  118. $view->api_version = '2';
  119. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  120. $handler = $view->new_display('default', 'Defaults', 'default');
  121. $handler->override_option('fields', array(
  122. 'common_name' => array(
  123. 'label' => 'Common Name',
  124. 'alter' => array(
  125. 'alter_text' => 0,
  126. 'text' => '',
  127. 'make_link' => 0,
  128. 'path' => '',
  129. 'link_class' => '',
  130. 'alt' => '',
  131. 'prefix' => '',
  132. 'suffix' => '',
  133. 'target' => '',
  134. 'help' => '',
  135. 'trim' => 0,
  136. 'max_length' => '',
  137. 'word_boundary' => 1,
  138. 'ellipsis' => 1,
  139. 'html' => 0,
  140. 'strip_tags' => 0,
  141. ),
  142. 'empty' => '',
  143. 'hide_empty' => 0,
  144. 'empty_zero' => 0,
  145. 'link_to_node' => 1,
  146. 'exclude' => 0,
  147. 'id' => 'common_name',
  148. 'table' => 'organism',
  149. 'field' => 'common_name',
  150. 'relationship' => 'none',
  151. ),
  152. 'genus' => array(
  153. 'label' => 'Genus',
  154. 'alter' => array(
  155. 'alter_text' => 0,
  156. 'text' => '',
  157. 'make_link' => 0,
  158. 'path' => '',
  159. 'link_class' => '',
  160. 'alt' => '',
  161. 'prefix' => '',
  162. 'suffix' => '',
  163. 'target' => '',
  164. 'help' => '',
  165. 'trim' => 0,
  166. 'max_length' => '',
  167. 'word_boundary' => 1,
  168. 'ellipsis' => 1,
  169. 'html' => 0,
  170. 'strip_tags' => 0,
  171. ),
  172. 'empty' => '',
  173. 'hide_empty' => 0,
  174. 'empty_zero' => 0,
  175. 'exclude' => 0,
  176. 'id' => 'genus',
  177. 'table' => 'organism',
  178. 'field' => 'genus',
  179. 'relationship' => 'none',
  180. ),
  181. 'species' => array(
  182. 'label' => 'Species',
  183. 'alter' => array(
  184. 'alter_text' => 0,
  185. 'text' => '',
  186. 'make_link' => 0,
  187. 'path' => '',
  188. 'link_class' => '',
  189. 'alt' => '',
  190. 'prefix' => '',
  191. 'suffix' => '',
  192. 'target' => '',
  193. 'help' => '',
  194. 'trim' => 0,
  195. 'max_length' => '',
  196. 'word_boundary' => 1,
  197. 'ellipsis' => 1,
  198. 'html' => 0,
  199. 'strip_tags' => 0,
  200. ),
  201. 'empty' => '',
  202. 'hide_empty' => 0,
  203. 'empty_zero' => 0,
  204. 'exclude' => 0,
  205. 'id' => 'species',
  206. 'table' => 'organism',
  207. 'field' => 'species',
  208. 'relationship' => 'none',
  209. ),
  210. 'abbreviation' => array(
  211. 'label' => 'Abbreviation',
  212. 'alter' => array(
  213. 'alter_text' => 0,
  214. 'text' => '',
  215. 'make_link' => 0,
  216. 'path' => '',
  217. 'link_class' => '',
  218. 'alt' => '',
  219. 'prefix' => '',
  220. 'suffix' => '',
  221. 'target' => '',
  222. 'help' => '',
  223. 'trim' => 0,
  224. 'max_length' => '',
  225. 'word_boundary' => 1,
  226. 'ellipsis' => 1,
  227. 'html' => 0,
  228. 'strip_tags' => 0,
  229. ),
  230. 'empty' => '',
  231. 'hide_empty' => 0,
  232. 'empty_zero' => 0,
  233. 'link_to_node' => 0,
  234. 'exclude' => 0,
  235. 'id' => 'abbreviation',
  236. 'table' => 'organism',
  237. 'field' => 'abbreviation',
  238. 'relationship' => 'none',
  239. ),
  240. ));
  241. $handler->override_option('sorts', array(
  242. 'genus' => array(
  243. 'order' => 'ASC',
  244. 'id' => 'genus',
  245. 'table' => 'organism',
  246. 'field' => 'genus',
  247. 'relationship' => 'none',
  248. ),
  249. 'species' => array(
  250. 'order' => 'ASC',
  251. 'id' => 'species',
  252. 'table' => 'organism',
  253. 'field' => 'species',
  254. 'relationship' => 'none',
  255. ),
  256. ));
  257. $handler->override_option('access', array(
  258. 'type' => 'perm',
  259. 'perm' => 'access chado_organism content',
  260. ));
  261. $handler->override_option('cache', array(
  262. 'type' => 'none',
  263. ));
  264. $handler->override_option('title', 'Organisms');
  265. $handler->override_option('empty', 'No organism currently in your chado database.');
  266. $handler->override_option('empty_format', '1');
  267. $handler->override_option('items_per_page', 0);
  268. $handler->override_option('style_plugin', 'table');
  269. $handler->override_option('style_options', array(
  270. 'grouping' => '',
  271. 'override' => 1,
  272. 'sticky' => 0,
  273. 'order' => 'asc',
  274. 'summary' => '',
  275. 'columns' => array(
  276. 'common_name' => 'common_name',
  277. 'genus' => 'genus',
  278. 'species' => 'species',
  279. 'abbreviation' => 'abbreviation',
  280. ),
  281. 'info' => array(
  282. 'common_name' => array(
  283. 'sortable' => 1,
  284. 'separator' => '',
  285. ),
  286. 'genus' => array(
  287. 'sortable' => 1,
  288. 'separator' => '',
  289. ),
  290. 'species' => array(
  291. 'sortable' => 1,
  292. 'separator' => '',
  293. ),
  294. 'abbreviation' => array(
  295. 'sortable' => 1,
  296. 'separator' => '',
  297. ),
  298. ),
  299. 'default' => '-1',
  300. ));
  301. $handler = $view->new_display('page', 'Page', 'page_1');
  302. $handler->override_option('path', 'chado/organisms');
  303. $handler->override_option('menu', array(
  304. 'type' => 'normal',
  305. 'title' => 'Organisms',
  306. 'description' => 'A biological organism.',
  307. 'weight' => '10',
  308. 'name' => 'navigation',
  309. ));
  310. $handler->override_option('tab_options', array(
  311. 'type' => 'none',
  312. 'title' => '',
  313. 'description' => '',
  314. 'weight' => 0,
  315. 'name' => 'navigation',
  316. ));
  317. $views[$view->name] = $view;
  318. return $views;
  319. }