tripal_organism.views.inc 10 KB

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