tripal_library.views.inc 11 KB

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