tripal_library.views.inc 11 KB

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