tripal_organism.views.inc 10 KB

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