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