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