tripal_library.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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, 10)) {
  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, 10)) {
  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. // List all cvterms based on cv
  107. $view = new view;
  108. $view->name = 'all_libraries';
  109. $view->description = 'A listing of all libraries';
  110. $view->tag = 'chado';
  111. $view->view_php = '';
  112. $view->base_table = 'library';
  113. $view->is_cacheable = FALSE;
  114. $view->api_version = 2;
  115. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  116. $handler = $view->new_display('default', 'Defaults', 'default');
  117. $handler->override_option('fields', array(
  118. 'uniquename' => array(
  119. 'label' => 'Unique Name',
  120. 'alter' => array(
  121. 'alter_text' => 0,
  122. 'text' => '',
  123. 'make_link' => 0,
  124. 'path' => '',
  125. 'link_class' => '',
  126. 'alt' => '',
  127. 'prefix' => '',
  128. 'suffix' => '',
  129. 'target' => '',
  130. 'help' => '',
  131. 'trim' => 0,
  132. 'max_length' => '',
  133. 'word_boundary' => 1,
  134. 'ellipsis' => 1,
  135. 'html' => 0,
  136. 'strip_tags' => 0,
  137. ),
  138. 'empty' => '',
  139. 'hide_empty' => 0,
  140. 'empty_zero' => 0,
  141. 'link_to_node' => 1,
  142. 'exclude' => 0,
  143. 'id' => 'uniquename',
  144. 'table' => 'library',
  145. 'field' => 'uniquename',
  146. 'relationship' => 'none',
  147. ),
  148. 'name_1' => array(
  149. 'label' => 'Name',
  150. 'alter' => array(
  151. 'alter_text' => 0,
  152. 'text' => '',
  153. 'make_link' => 0,
  154. 'path' => '',
  155. 'link_class' => '',
  156. 'alt' => '',
  157. 'prefix' => '',
  158. 'suffix' => '',
  159. 'target' => '',
  160. 'help' => '',
  161. 'trim' => 0,
  162. 'max_length' => '',
  163. 'word_boundary' => 1,
  164. 'ellipsis' => 1,
  165. 'html' => 0,
  166. 'strip_tags' => 0,
  167. ),
  168. 'empty' => '',
  169. 'hide_empty' => 0,
  170. 'empty_zero' => 0,
  171. 'link_to_node' => 1,
  172. 'exclude' => 0,
  173. 'id' => 'name_1',
  174. 'table' => 'library',
  175. 'field' => 'name',
  176. 'relationship' => 'none',
  177. ),
  178. 'common_name' => array(
  179. 'label' => 'Organism',
  180. 'alter' => array(
  181. 'alter_text' => 0,
  182. 'text' => '',
  183. 'make_link' => 0,
  184. 'path' => '',
  185. 'link_class' => '',
  186. 'alt' => '',
  187. 'prefix' => '',
  188. 'suffix' => '',
  189. 'target' => '',
  190. 'help' => '',
  191. 'trim' => 0,
  192. 'max_length' => '',
  193. 'word_boundary' => 1,
  194. 'ellipsis' => 1,
  195. 'html' => 0,
  196. 'strip_tags' => 0,
  197. ),
  198. 'empty' => '',
  199. 'hide_empty' => 0,
  200. 'empty_zero' => 0,
  201. 'link_to_node' => 1,
  202. 'exclude' => 0,
  203. 'id' => 'common_name',
  204. 'table' => 'organism',
  205. 'field' => 'common_name',
  206. 'relationship' => 'none',
  207. ),
  208. 'name' => array(
  209. 'label' => 'Type',
  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' => 'name',
  233. 'table' => 'cvterm',
  234. 'field' => 'name',
  235. 'relationship' => 'none',
  236. ),
  237. 'is_obsolete' => array(
  238. 'label' => 'Is Obsolete?',
  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. 'type' => 'yes-no',
  261. 'not' => 0,
  262. 'exclude' => 0,
  263. 'id' => 'is_obsolete',
  264. 'table' => 'library',
  265. 'field' => 'is_obsolete',
  266. 'relationship' => 'none',
  267. ),
  268. 'num_features' => array(
  269. 'label' => 'Number of Features',
  270. 'alter' => array(
  271. 'alter_text' => 0,
  272. 'text' => '',
  273. 'make_link' => 0,
  274. 'path' => '',
  275. 'link_class' => '',
  276. 'alt' => '',
  277. 'prefix' => '',
  278. 'suffix' => '',
  279. 'target' => '',
  280. 'help' => '',
  281. 'trim' => 0,
  282. 'max_length' => '',
  283. 'word_boundary' => 1,
  284. 'ellipsis' => 1,
  285. 'html' => 0,
  286. 'strip_tags' => 0,
  287. ),
  288. 'empty' => '',
  289. 'hide_empty' => 0,
  290. 'empty_zero' => 0,
  291. 'exclude' => 0,
  292. 'id' => 'num_features',
  293. 'table' => 'library',
  294. 'field' => 'num_features',
  295. 'relationship' => 'none',
  296. ),
  297. ));
  298. $handler->override_option('filters', array(
  299. 'common_name' => array(
  300. 'operator' => '=',
  301. 'value' => 'All',
  302. 'group' => '0',
  303. 'exposed' => TRUE,
  304. 'expose' => array(
  305. 'use_operator' => 0,
  306. 'operator' => 'common_name_op',
  307. 'identifier' => 'organism_common_name',
  308. 'label' => 'Organism',
  309. 'optional' => 1,
  310. 'remember' => 0,
  311. ),
  312. 'case' => 1,
  313. 'id' => 'common_name',
  314. 'table' => 'organism',
  315. 'field' => 'common_name',
  316. 'relationship' => 'none',
  317. ),
  318. ));
  319. $handler->override_option('access', array(
  320. 'type' => 'perm',
  321. 'perm' => 'access chado_library content',
  322. ));
  323. $handler->override_option('cache', array(
  324. 'type' => 'none',
  325. ));
  326. $handler->override_option('title', 'Libraries');
  327. $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.');
  328. $handler->override_option('empty_format', '1');
  329. $handler->override_option('use_pager', '1');
  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. 'name' => 'name',
  338. 'timeaccessioned' => 'timeaccessioned',
  339. 'timelastmodified' => 'timelastmodified',
  340. 'is_obsolete' => 'is_obsolete',
  341. 'name_1' => 'name_1',
  342. 'uniquename' => 'uniquename',
  343. 'common_name' => 'common_name',
  344. 'num_libraries' => 'num_libraries',
  345. ),
  346. 'info' => array(
  347. 'name' => array(
  348. 'sortable' => 0,
  349. 'separator' => '',
  350. ),
  351. 'timeaccessioned' => array(
  352. 'sortable' => 0,
  353. 'separator' => '',
  354. ),
  355. 'timelastmodified' => array(
  356. 'sortable' => 0,
  357. 'separator' => '',
  358. ),
  359. 'is_obsolete' => array(
  360. 'sortable' => 0,
  361. 'separator' => '',
  362. ),
  363. 'name_1' => array(
  364. 'sortable' => 0,
  365. 'separator' => '',
  366. ),
  367. 'uniquename' => array(
  368. 'sortable' => 0,
  369. 'separator' => '',
  370. ),
  371. 'common_name' => array(
  372. 'sortable' => 0,
  373. 'separator' => '',
  374. ),
  375. 'num_libraries' => array(
  376. 'separator' => '',
  377. ),
  378. ),
  379. 'default' => '-1',
  380. ));
  381. $handler = $view->new_display('page', 'Page', 'page_1');
  382. $handler->override_option('path', 'libraries');
  383. $handler->override_option('menu', array(
  384. 'type' => 'normal',
  385. 'title' => 'Sequence Libraries',
  386. 'description' => '',
  387. 'weight' => '0',
  388. 'name' => 'primary-links',
  389. ));
  390. $handler->override_option('tab_options', array(
  391. 'type' => 'none',
  392. 'title' => '',
  393. 'description' => '',
  394. 'weight' => 0,
  395. 'name' => 'navigation',
  396. ));
  397. $views[$view->name] = $view;
  398. return $views;
  399. }