tripal_library.views.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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_library_views Library Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_library
  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_library_views
  26. */
  27. function tripal_library_views_data() {
  28. $data = array();
  29. if (module_exists('tripal_views')) {
  30. $tables = array(
  31. 'library'
  32. );
  33. foreach ($tables as $tablename) {
  34. if (!tripal_views_is_integrated($tablename, 9)) {
  35. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  36. tripal_views_integration_add_entry($table_integration_array);
  37. }
  38. }
  39. $tables = array(
  40. 'library_cvterm',
  41. 'library_feature',
  42. 'library_pub',
  43. 'library_synonym',
  44. 'libraryprop'
  45. );
  46. foreach ($tables as $tablename) {
  47. if (!tripal_views_is_integrated($tablename, 9)) {
  48. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  49. tripal_views_integration_add_entry($table_integration_array);
  50. }
  51. }
  52. }
  53. return $data;
  54. }
  55. /*************************************************************************
  56. * Implements hook_views_handlers()
  57. * Purpose: Register all custom handlers with views
  58. * where a handler describes either "the type of field",
  59. * "how a field should be filtered", "how a field should be sorted"
  60. * @return: An array of handler definitions
  61. *
  62. * @ingroup tripal_library_views
  63. */
  64. function tripal_library_views_handlers() {
  65. return array(
  66. 'info' => array(
  67. 'path' => drupal_get_path('module', 'tripal_library') . '/views/handlers',
  68. ),
  69. 'handlers' => array(
  70. 'views_handler_field_computed_library_nid' => array(
  71. 'parent' => 'views_handler_field_numeric',
  72. ),
  73. ),
  74. );
  75. }
  76. /**
  77. * Implementation of hook_views_data_alter().
  78. */
  79. function tripal_library_views_data_alter(&$data) {
  80. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  81. // Add featuer relationship to node
  82. $data['node']['library_chado_nid'] = array(
  83. 'group' => 'Library',
  84. 'title' => 'Library Node',
  85. 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
  86. 'real field' => 'nid',
  87. 'relationship' => array(
  88. 'handler' => 'views_handler_relationship',
  89. 'title' => t('Node => Chado'),
  90. 'label' => t('Node => Chado'),
  91. 'real field' => 'nid',
  92. 'base' => 'chado_library',
  93. 'base field' => 'nid'
  94. ),
  95. );
  96. }
  97. }
  98. /**
  99. *
  100. *
  101. * @ingroup tripal_library_views
  102. */
  103. function tripal_library_views_default_views() {
  104. $views = array();
  105. // Main default view
  106. $view = new view;
  107. $view->name = 'library_listing';
  108. $view->description = 'A listing of all libraries';
  109. $view->tag = 'chado default';
  110. $view->base_table = 'library';
  111. $view->core = 0;
  112. $view->api_version = '2';
  113. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  114. $handler = $view->new_display('default', 'Defaults', 'default');
  115. $handler->override_option('fields', array(
  116. 'uniquename' => array(
  117. 'label' => 'Unique Name',
  118. 'alter' => array(
  119. 'alter_text' => 0,
  120. 'text' => '',
  121. 'make_link' => 0,
  122. 'path' => '',
  123. 'link_class' => '',
  124. 'alt' => '',
  125. 'prefix' => '',
  126. 'suffix' => '',
  127. 'target' => '',
  128. 'help' => '',
  129. 'trim' => 0,
  130. 'max_length' => '',
  131. 'word_boundary' => 1,
  132. 'ellipsis' => 1,
  133. 'html' => 0,
  134. 'strip_tags' => 0,
  135. ),
  136. 'empty' => '',
  137. 'hide_empty' => 0,
  138. 'empty_zero' => 0,
  139. 'link_to_node' => 1,
  140. 'exclude' => 0,
  141. 'id' => 'uniquename',
  142. 'table' => 'library',
  143. 'field' => 'uniquename',
  144. 'relationship' => 'none',
  145. ),
  146. 'name_1' => array(
  147. 'label' => 'Name',
  148. 'alter' => array(
  149. 'alter_text' => 0,
  150. 'text' => '',
  151. 'make_link' => 0,
  152. 'path' => '',
  153. 'link_class' => '',
  154. 'alt' => '',
  155. 'prefix' => '',
  156. 'suffix' => '',
  157. 'target' => '',
  158. 'help' => '',
  159. 'trim' => 0,
  160. 'max_length' => '',
  161. 'word_boundary' => 1,
  162. 'ellipsis' => 1,
  163. 'html' => 0,
  164. 'strip_tags' => 0,
  165. ),
  166. 'empty' => '',
  167. 'hide_empty' => 0,
  168. 'empty_zero' => 0,
  169. 'link_to_node' => 1,
  170. 'exclude' => 0,
  171. 'id' => 'name_1',
  172. 'table' => 'library',
  173. 'field' => 'name',
  174. 'relationship' => 'none',
  175. ),
  176. 'common_name' => array(
  177. 'label' => 'Organism',
  178. 'alter' => array(
  179. 'alter_text' => 0,
  180. 'text' => '',
  181. 'make_link' => 0,
  182. 'path' => '',
  183. 'link_class' => '',
  184. 'alt' => '',
  185. 'prefix' => '',
  186. 'suffix' => '',
  187. 'target' => '',
  188. 'help' => '',
  189. 'trim' => 0,
  190. 'max_length' => '',
  191. 'word_boundary' => 1,
  192. 'ellipsis' => 1,
  193. 'html' => 0,
  194. 'strip_tags' => 0,
  195. ),
  196. 'empty' => '',
  197. 'hide_empty' => 0,
  198. 'empty_zero' => 0,
  199. 'link_to_node' => 1,
  200. 'exclude' => 0,
  201. 'id' => 'common_name',
  202. 'table' => 'organism',
  203. 'field' => 'common_name',
  204. 'relationship' => 'none',
  205. ),
  206. 'name' => array(
  207. 'label' => 'Type',
  208. 'alter' => array(
  209. 'alter_text' => 0,
  210. 'text' => '',
  211. 'make_link' => 0,
  212. 'path' => '',
  213. 'link_class' => '',
  214. 'alt' => '',
  215. 'prefix' => '',
  216. 'suffix' => '',
  217. 'target' => '',
  218. 'help' => '',
  219. 'trim' => 0,
  220. 'max_length' => '',
  221. 'word_boundary' => 1,
  222. 'ellipsis' => 1,
  223. 'html' => 0,
  224. 'strip_tags' => 0,
  225. ),
  226. 'empty' => '',
  227. 'hide_empty' => 0,
  228. 'empty_zero' => 0,
  229. 'exclude' => 0,
  230. 'id' => 'name',
  231. 'table' => 'cvterm',
  232. 'field' => 'name',
  233. 'relationship' => 'none',
  234. ),
  235. 'is_obsolete' => array(
  236. 'label' => 'Is Obsolete?',
  237. 'alter' => array(
  238. 'alter_text' => 0,
  239. 'text' => '',
  240. 'make_link' => 0,
  241. 'path' => '',
  242. 'link_class' => '',
  243. 'alt' => '',
  244. 'prefix' => '',
  245. 'suffix' => '',
  246. 'target' => '',
  247. 'help' => '',
  248. 'trim' => 0,
  249. 'max_length' => '',
  250. 'word_boundary' => 1,
  251. 'ellipsis' => 1,
  252. 'html' => 0,
  253. 'strip_tags' => 0,
  254. ),
  255. 'empty' => '',
  256. 'hide_empty' => 0,
  257. 'empty_zero' => 0,
  258. 'type' => 'yes-no',
  259. 'not' => 0,
  260. 'exclude' => 0,
  261. 'id' => 'is_obsolete',
  262. 'table' => 'library',
  263. 'field' => 'is_obsolete',
  264. 'relationship' => 'none',
  265. ),
  266. ));
  267. $handler->override_option('sorts', array(
  268. 'name' => array(
  269. 'id' => 'name',
  270. 'table' => 'library',
  271. 'field' => 'name',
  272. ),
  273. ));
  274. $handler->override_option('filters', array(
  275. 'common_name' => array(
  276. 'operator' => '=',
  277. 'value' => array(),
  278. 'group' => '0',
  279. 'exposed' => TRUE,
  280. 'expose' => array(
  281. 'use_operator' => 0,
  282. 'operator' => 'common_name_op',
  283. 'identifier' => 'organism_common_name',
  284. 'label' => 'Organism',
  285. 'remember' => 0,
  286. ),
  287. 'case' => 1,
  288. 'id' => 'common_name',
  289. 'table' => 'organism',
  290. 'field' => 'common_name',
  291. 'relationship' => 'none',
  292. 'values_form_type' => 'select',
  293. 'multiple' => 1,
  294. 'optional' => 0,
  295. ),
  296. 'type_id' => array(
  297. 'operator' => '=',
  298. 'value' => '',
  299. 'group' => '0',
  300. 'exposed' => TRUE,
  301. 'expose' => array(
  302. 'use_operator' => 0,
  303. 'operator' => 'type_id_op',
  304. 'identifier' => 'type_id',
  305. 'label' => 'Type',
  306. 'remember' => 0,
  307. ),
  308. 'case' => 1,
  309. 'id' => 'type_id',
  310. 'table' => 'library',
  311. 'field' => 'type_id',
  312. 'relationship' => 'none',
  313. 'values_form_type' => 'select',
  314. 'multiple' => 1,
  315. 'optional' => 0,
  316. 'show_all' => 0,
  317. 'agg' => array(
  318. 'records_with' => 1,
  319. 'aggregates_with' => 0,
  320. ),
  321. ),
  322. 'search_results' => array(
  323. 'operator' => '=',
  324. 'value' => '',
  325. 'group' => '0',
  326. 'exposed' => FALSE,
  327. 'expose' => array(
  328. 'operator' => FALSE,
  329. 'label' => '',
  330. ),
  331. 'id' => 'search_results',
  332. 'table' => 'views',
  333. 'field' => 'search_results',
  334. 'relationship' => 'none',
  335. 'apply_button' => 'Show',
  336. 'no_results_text' => 'Click "Show" to see a list of all libraries matching the entered criteria. If you leave a any of the criteria blank then the libraries will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all libraries will be listed.',
  337. ),
  338. ));
  339. $handler->override_option('access', array(
  340. 'type' => 'perm',
  341. 'perm' => 'access chado_library content',
  342. ));
  343. $handler->override_option('cache', array(
  344. 'type' => 'none',
  345. ));
  346. $handler->override_option('title', 'Libraries');
  347. $handler->override_option('header', 'Click "Show" to see a list of all libraries matching the entered criteria. If you leave a any of the criteria blank then the libraries will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all libraries will be listed.');
  348. $handler->override_option('header_format', '2');
  349. $handler->override_option('header_empty', 0);
  350. $handler->override_option('empty', 'There are no libraries matching the current criteria. If you think there should be, check that all chado libraries are sync\'d with your website.');
  351. $handler->override_option('empty_format', '1');
  352. $handler->override_option('items_per_page', 50);
  353. $handler->override_option('use_pager', '1');
  354. $handler->override_option('style_plugin', 'table');
  355. $handler->override_option('style_options', array(
  356. 'grouping' => '',
  357. 'override' => 1,
  358. 'sticky' => 0,
  359. 'order' => 'asc',
  360. 'summary' => '',
  361. 'columns' => array(
  362. 'uniquename' => 'uniquename',
  363. 'name_1' => 'name_1',
  364. 'common_name' => 'common_name',
  365. 'name' => 'name',
  366. 'is_obsolete' => 'is_obsolete',
  367. ),
  368. 'info' => array(
  369. 'uniquename' => array(
  370. 'sortable' => 1,
  371. 'separator' => '',
  372. ),
  373. 'name_1' => array(
  374. 'sortable' => 1,
  375. 'separator' => '',
  376. ),
  377. 'common_name' => array(
  378. 'sortable' => 1,
  379. 'separator' => '',
  380. ),
  381. 'name' => array(
  382. 'sortable' => 1,
  383. 'separator' => '',
  384. ),
  385. 'is_obsolete' => array(
  386. 'sortable' => 1,
  387. 'separator' => '',
  388. ),
  389. ),
  390. 'default' => 'uniquename',
  391. ));
  392. $handler = $view->new_display('page', 'Page', 'page_1');
  393. $handler->override_option('path', 'libraries');
  394. $handler->override_option('menu', array(
  395. 'type' => 'normal',
  396. 'title' => 'Sequence Libraries',
  397. 'description' => '',
  398. 'weight' => '0',
  399. 'name' => 'primary-links',
  400. ));
  401. $handler->override_option('tab_options', array(
  402. 'type' => 'none',
  403. 'title' => '',
  404. 'description' => '',
  405. 'weight' => 0,
  406. 'name' => 'navigation',
  407. ));
  408. $views[$view->name] = $view;
  409. return $views;
  410. }