tripal_organism.views.inc 11 KB

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