tripal_organism.views.inc 12 KB

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