tripal_organism.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. // Add in node relationships if chado is in the same db as drupal
  43. if (tripal_core_chado_schema_exists()) {
  44. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  45. foreach ($integrations as $integration) {
  46. tripal_views_integration_add_entry($integration);
  47. }
  48. }
  49. else {
  50. tripal_views_integration_add_entry($table_integration_array);
  51. }
  52. }
  53. }
  54. // Additional Tables
  55. $tables = array(
  56. 'organismprop',
  57. 'organism_dbxref'
  58. );
  59. foreach ($tables as $tablename) {
  60. if (!tripal_views_is_integrated($tablename, 9)) {
  61. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  62. tripal_views_integration_add_entry($table_integration_array);
  63. }
  64. }
  65. }
  66. return $data;
  67. }
  68. /**
  69. * Implements hook_views_handlers()
  70. * Purpose: Register all custom handlers with views
  71. * where a handler describes either "the type of field",
  72. * "how a field should be filtered", "how a field should be sorted"
  73. * @return: An array of handler definitions
  74. *
  75. * @ingroup tripal_organism_views
  76. */
  77. function tripal_organism_views_handlers() {
  78. return array(
  79. 'info' => array(
  80. 'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
  81. ),
  82. 'handlers' => array(
  83. 'views_handler_field_computed_organism_nid' => array(
  84. 'parent' => 'views_handler_field_numeric',
  85. ),
  86. 'views_handler_filter_organism_common_name' => array(
  87. 'parent' => 'views_handler_filter_string',
  88. ),
  89. ),
  90. );
  91. }
  92. /**
  93. * Implementation of hook_views_data_alter().
  94. */
  95. function tripal_organism_views_data_alter(&$data) {
  96. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  97. // Add featuer relationship to node
  98. $data['node']['organism_chado_nid'] = array(
  99. 'group' => 'Organism',
  100. 'title' => 'Organism Node',
  101. 'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
  102. 'real field' => 'nid',
  103. 'relationship' => array(
  104. 'handler' => 'views_handler_relationship',
  105. 'title' => t('Node => Chado'),
  106. 'label' => t('Node => Chado'),
  107. 'real field' => 'nid',
  108. 'base' => 'chado_organism',
  109. 'base field' => 'nid'
  110. ),
  111. );
  112. }
  113. }
  114. /**
  115. *
  116. * @ingroup tripal_organism_views
  117. */
  118. function tripal_organism_views_default_views() {
  119. $views = array();
  120. // Main default view
  121. $view = new view;
  122. $view->name = 'organism_listing';
  123. $view->description = 'A listing of all organism in chado';
  124. $view->tag = 'chado default';
  125. $view->base_table = 'organism';
  126. $view->core = 0;
  127. $view->api_version = '2';
  128. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  129. $handler = $view->new_display('default', 'Defaults', 'default');
  130. $handler->override_option('fields', array(
  131. 'common_name' => array(
  132. 'label' => 'Common Name',
  133. 'alter' => array(
  134. 'alter_text' => 0,
  135. 'text' => '',
  136. 'make_link' => 0,
  137. 'path' => '',
  138. 'link_class' => '',
  139. 'alt' => '',
  140. 'prefix' => '',
  141. 'suffix' => '',
  142. 'target' => '',
  143. 'help' => '',
  144. 'trim' => 0,
  145. 'max_length' => '',
  146. 'word_boundary' => 1,
  147. 'ellipsis' => 1,
  148. 'html' => 0,
  149. 'strip_tags' => 0,
  150. ),
  151. 'empty' => '',
  152. 'hide_empty' => 0,
  153. 'empty_zero' => 0,
  154. 'link_to_node' => 1,
  155. 'exclude' => 0,
  156. 'id' => 'common_name',
  157. 'table' => 'organism',
  158. 'field' => 'common_name',
  159. 'relationship' => 'none',
  160. ),
  161. 'genus' => array(
  162. 'label' => 'Genus',
  163. 'alter' => array(
  164. 'alter_text' => 0,
  165. 'text' => '',
  166. 'make_link' => 0,
  167. 'path' => '',
  168. 'link_class' => '',
  169. 'alt' => '',
  170. 'prefix' => '',
  171. 'suffix' => '',
  172. 'target' => '',
  173. 'help' => '',
  174. 'trim' => 0,
  175. 'max_length' => '',
  176. 'word_boundary' => 1,
  177. 'ellipsis' => 1,
  178. 'html' => 0,
  179. 'strip_tags' => 0,
  180. ),
  181. 'empty' => '',
  182. 'hide_empty' => 0,
  183. 'empty_zero' => 0,
  184. 'exclude' => 0,
  185. 'id' => 'genus',
  186. 'table' => 'organism',
  187. 'field' => 'genus',
  188. 'relationship' => 'none',
  189. ),
  190. 'species' => array(
  191. 'label' => 'Species',
  192. 'alter' => array(
  193. 'alter_text' => 0,
  194. 'text' => '',
  195. 'make_link' => 0,
  196. 'path' => '',
  197. 'link_class' => '',
  198. 'alt' => '',
  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. 'exclude' => 0,
  214. 'id' => 'species',
  215. 'table' => 'organism',
  216. 'field' => 'species',
  217. 'relationship' => 'none',
  218. ),
  219. 'abbreviation' => array(
  220. 'label' => 'Abbreviation',
  221. 'alter' => array(
  222. 'alter_text' => 0,
  223. 'text' => '',
  224. 'make_link' => 0,
  225. 'path' => '',
  226. 'link_class' => '',
  227. 'alt' => '',
  228. 'prefix' => '',
  229. 'suffix' => '',
  230. 'target' => '',
  231. 'help' => '',
  232. 'trim' => 0,
  233. 'max_length' => '',
  234. 'word_boundary' => 1,
  235. 'ellipsis' => 1,
  236. 'html' => 0,
  237. 'strip_tags' => 0,
  238. ),
  239. 'empty' => '',
  240. 'hide_empty' => 0,
  241. 'empty_zero' => 0,
  242. 'link_to_node' => 0,
  243. 'exclude' => 0,
  244. 'id' => 'abbreviation',
  245. 'table' => 'organism',
  246. 'field' => 'abbreviation',
  247. 'relationship' => 'none',
  248. ),
  249. ));
  250. $handler->override_option('sorts', array(
  251. 'genus' => array(
  252. 'order' => 'ASC',
  253. 'id' => 'genus',
  254. 'table' => 'organism',
  255. 'field' => 'genus',
  256. 'relationship' => 'none',
  257. ),
  258. 'species' => array(
  259. 'order' => 'ASC',
  260. 'id' => 'species',
  261. 'table' => 'organism',
  262. 'field' => 'species',
  263. 'relationship' => 'none',
  264. ),
  265. ));
  266. $handler->override_option('access', array(
  267. 'type' => 'perm',
  268. 'perm' => 'access chado_organism content',
  269. ));
  270. $handler->override_option('cache', array(
  271. 'type' => 'none',
  272. ));
  273. $handler->override_option('title', 'Organisms');
  274. $handler->override_option('empty', 'No organism currently in your chado database.');
  275. $handler->override_option('empty_format', '1');
  276. $handler->override_option('items_per_page', 0);
  277. $handler->override_option('style_plugin', 'table');
  278. $handler->override_option('style_options', array(
  279. 'grouping' => '',
  280. 'override' => 1,
  281. 'sticky' => 0,
  282. 'order' => 'asc',
  283. 'summary' => '',
  284. 'columns' => array(
  285. 'common_name' => 'common_name',
  286. 'genus' => 'genus',
  287. 'species' => 'species',
  288. 'abbreviation' => 'abbreviation',
  289. ),
  290. 'info' => array(
  291. 'common_name' => array(
  292. 'sortable' => 1,
  293. 'separator' => '',
  294. ),
  295. 'genus' => array(
  296. 'sortable' => 1,
  297. 'separator' => '',
  298. ),
  299. 'species' => array(
  300. 'sortable' => 1,
  301. 'separator' => '',
  302. ),
  303. 'abbreviation' => array(
  304. 'sortable' => 1,
  305. 'separator' => '',
  306. ),
  307. ),
  308. 'default' => '-1',
  309. ));
  310. $default_handler = $handler;
  311. $handler = $view->new_display('page', 'Page', 'page_1');
  312. $handler->override_option('path', 'chado/organisms');
  313. $handler->override_option('menu', array(
  314. 'type' => 'normal',
  315. 'title' => 'Organisms',
  316. 'description' => 'A biological organism.',
  317. 'weight' => '10',
  318. 'name' => 'navigation',
  319. ));
  320. $handler->override_option('tab_options', array(
  321. 'type' => 'none',
  322. 'title' => '',
  323. 'description' => '',
  324. 'weight' => 0,
  325. 'name' => 'navigation',
  326. ));
  327. // Add code specific to a local chado installation
  328. // NOTE: Edit $handler above to $default_handler for the default display
  329. if (tripal_core_chado_schema_exists()) {
  330. // Add nid field
  331. $fields = $view->get_items('field', 'default');
  332. $new_fields = array(
  333. 'nid' => array(
  334. 'label' => 'Nid',
  335. 'alter' => array(
  336. 'alter_text' => 0,
  337. 'text' => '',
  338. 'make_link' => 0,
  339. 'path' => '',
  340. 'absolute' => 0,
  341. 'link_class' => '',
  342. 'alt' => '',
  343. 'rel' => '',
  344. 'prefix' => '',
  345. 'suffix' => '',
  346. 'target' => '',
  347. 'help' => '',
  348. 'trim' => 0,
  349. 'max_length' => '',
  350. 'word_boundary' => 1,
  351. 'ellipsis' => 1,
  352. 'html' => 0,
  353. 'strip_tags' => 0,
  354. ),
  355. 'empty' => '',
  356. 'hide_empty' => 0,
  357. 'empty_zero' => 0,
  358. 'hide_alter_empty' => 1,
  359. 'link_to_node' => 0,
  360. 'exclude' => 1,
  361. 'id' => 'nid',
  362. 'table' => 'node',
  363. 'field' => 'nid',
  364. 'relationship' => 'none',
  365. )
  366. );
  367. $fields = $new_fields + $fields;
  368. // Change analysis.name to have a link to the node
  369. $fields['common_name']['alter']['make_link'] = 1;
  370. $fields['common_name']['alter']['path'] = 'node/[nid]';
  371. $default_handler->override_option('fields', $fields);
  372. // Only show records with published nodes
  373. $filters = $view->get_items('filter', 'default');
  374. $filters['status'] = array(
  375. 'operator' => '=',
  376. 'value' => '1',
  377. 'group' => '0',
  378. 'exposed' => FALSE,
  379. 'expose' => array(
  380. 'operator' => FALSE,
  381. 'label' => '',
  382. ),
  383. 'id' => 'status',
  384. 'table' => 'node',
  385. 'field' => 'status',
  386. 'relationship' => 'none',
  387. );
  388. $default_handler->override_option('filters', $filters);
  389. }
  390. $views[$view->name] = $view;
  391. return $views;
  392. }