tripal_library.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. 'agg' => array(
  296. 'records_with' => 1,
  297. 'aggregates_with' => 1,
  298. ),
  299. ),
  300. 'type_id' => array(
  301. 'operator' => '=',
  302. 'value' => array(),
  303. 'group' => '0',
  304. 'exposed' => TRUE,
  305. 'expose' => array(
  306. 'use_operator' => 0,
  307. 'operator' => 'type_id_op',
  308. 'identifier' => 'type_id',
  309. 'label' => 'Type',
  310. 'remember' => 0,
  311. ),
  312. 'case' => 1,
  313. 'id' => 'type_id',
  314. 'table' => 'library',
  315. 'field' => 'type_id',
  316. 'relationship' => 'none',
  317. 'values_form_type' => 'select',
  318. 'multiple' => 1,
  319. 'optional' => 0,
  320. 'show_all' => 0,
  321. 'agg' => array(
  322. 'records_with' => 1,
  323. 'aggregates_with' => 0,
  324. ),
  325. ),
  326. ));
  327. $handler->override_option('access', array(
  328. 'type' => 'perm',
  329. 'perm' => 'access chado_library content',
  330. ));
  331. $handler->override_option('cache', array(
  332. 'type' => 'none',
  333. ));
  334. $handler->override_option('title', 'Libraries');
  335. $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.');
  336. $handler->override_option('header_format', '2');
  337. $handler->override_option('header_empty', 0);
  338. $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.');
  339. $handler->override_option('empty_format', '1');
  340. $handler->override_option('items_per_page', 50);
  341. $handler->override_option('use_pager', '1');
  342. $handler->override_option('style_plugin', 'table');
  343. $handler->override_option('style_options', array(
  344. 'grouping' => '',
  345. 'override' => 1,
  346. 'sticky' => 0,
  347. 'order' => 'asc',
  348. 'summary' => '',
  349. 'columns' => array(
  350. 'uniquename' => 'uniquename',
  351. 'name_1' => 'name_1',
  352. 'common_name' => 'common_name',
  353. 'name' => 'name',
  354. 'is_obsolete' => 'is_obsolete',
  355. ),
  356. 'info' => array(
  357. 'uniquename' => array(
  358. 'sortable' => 1,
  359. 'separator' => '',
  360. ),
  361. 'name_1' => array(
  362. 'sortable' => 1,
  363. 'separator' => '',
  364. ),
  365. 'common_name' => array(
  366. 'sortable' => 1,
  367. 'separator' => '',
  368. ),
  369. 'name' => array(
  370. 'sortable' => 1,
  371. 'separator' => '',
  372. ),
  373. 'is_obsolete' => array(
  374. 'sortable' => 1,
  375. 'separator' => '',
  376. ),
  377. ),
  378. 'default' => 'uniquename',
  379. ));
  380. $handler = $view->new_display('page', 'Page', 'page_1');
  381. $handler->override_option('path', 'chado/libraries');
  382. $handler->override_option('menu', array(
  383. 'type' => 'normal',
  384. 'title' => 'Libraries',
  385. 'description' => 'A library is a collection of features of a given type. For example, a cDNA or BAC clone library.',
  386. 'weight' => '10',
  387. 'name' => 'navigation',
  388. ));
  389. $handler->override_option('tab_options', array(
  390. 'type' => 'none',
  391. 'title' => '',
  392. 'description' => '',
  393. 'weight' => 0,
  394. 'name' => 'navigation',
  395. ));
  396. $views[$view->name] = $view;
  397. return $views;
  398. }