tripal_cv.views.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal db 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_cv_views Controlled Vocabulary Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_cv
  15. */
  16. /**
  17. * Implements hook_views_data()
  18. *
  19. * Purpose: Describe chado/tripal tables & fields to views
  20. *
  21. * @return
  22. * 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_cv_views
  29. */
  30. function tripal_cv_views_data() {
  31. $data = array();
  32. if (module_exists('tripal_views')) {
  33. // Base Tables
  34. $tables = array(
  35. 'cv',
  36. 'cvterm'
  37. );
  38. foreach ($tables as $tablename) {
  39. if (!tripal_views_is_integrated($tablename, 10)) {
  40. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
  41. tripal_views_integration_add_entry($table_integration_array);
  42. }
  43. }
  44. // Additional Tables
  45. $tables = array(
  46. 'cvterm_dbxref',
  47. 'cvterm_relationship',
  48. 'cvtermpath',
  49. 'cvtermprop',
  50. 'cvtermsynonym'
  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. *
  64. * Purpose: Register all custom handlers with views
  65. * where a handler describes either "the type of field",
  66. * "how a field should be filtered", "how a field should be sorted"
  67. *
  68. * @return: An array of handler definitions
  69. *
  70. * @ingroup tripal_cv_views
  71. */
  72. function tripal_cv_views_handlers() {
  73. return array(
  74. 'info' => array(
  75. 'path' => drupal_get_path('module', 'tripal_cv') . '/views/handlers',
  76. ),
  77. 'handlers' => array(
  78. 'views_handler_field_tf_boolean' => array(
  79. 'parent' => 'views_handler_field',
  80. ),
  81. ),
  82. );
  83. }
  84. /**
  85. *
  86. * @ingroup tripal_cv_views
  87. */
  88. function tripal_cv_views_default_views () {
  89. $views = array();
  90. // Main default view
  91. // List all cvterms based on cv
  92. $view = new view;
  93. $view->name = 'all_cvterms';
  94. $view->description = 'A listing of all controlled vocabulary terms filtered by controlled vocabulary';
  95. $view->tag = 'chado';
  96. $view->view_php = '';
  97. $view->base_table = 'cvterm';
  98. $view->is_cacheable = FALSE;
  99. $view->api_version = 2;
  100. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  101. $handler = $view->new_display('default', 'Defaults', 'default');
  102. $handler->override_option('fields', array(
  103. 'name' => array(
  104. 'label' => 'Name',
  105. 'alter' => array(
  106. 'alter_text' => 0,
  107. 'text' => '',
  108. 'make_link' => 0,
  109. 'path' => '',
  110. 'link_class' => '',
  111. 'alt' => '',
  112. 'prefix' => '',
  113. 'suffix' => '',
  114. 'target' => '',
  115. 'help' => '',
  116. 'trim' => 0,
  117. 'max_length' => '',
  118. 'word_boundary' => 1,
  119. 'ellipsis' => 1,
  120. 'html' => 0,
  121. 'strip_tags' => 0,
  122. ),
  123. 'empty' => '',
  124. 'hide_empty' => 0,
  125. 'empty_zero' => 0,
  126. 'exclude' => 0,
  127. 'id' => 'name',
  128. 'table' => 'cvterm',
  129. 'field' => 'name',
  130. 'relationship' => 'none',
  131. ),
  132. 'definition' => array(
  133. 'label' => 'Definition',
  134. 'alter' => array(
  135. 'alter_text' => 0,
  136. 'text' => '',
  137. 'make_link' => 0,
  138. 'path' => '',
  139. 'link_class' => '',
  140. 'alt' => '',
  141. 'prefix' => '',
  142. 'suffix' => '',
  143. 'target' => '',
  144. 'help' => '',
  145. 'trim' => 0,
  146. 'max_length' => '',
  147. 'word_boundary' => 1,
  148. 'ellipsis' => 1,
  149. 'html' => 0,
  150. 'strip_tags' => 0,
  151. ),
  152. 'empty' => '',
  153. 'hide_empty' => 0,
  154. 'empty_zero' => 0,
  155. 'exclude' => 0,
  156. 'id' => 'definition',
  157. 'table' => 'cvterm',
  158. 'field' => 'definition',
  159. 'relationship' => 'none',
  160. ),
  161. 'is_obsolete' => array(
  162. 'label' => 'Is Obsolete',
  163. 'alter' => array(
  164. 'alter_text' => 0,
  165. 'text' => '',
  166. 'make_link' => 0,
  167. 'path' => '',
  168. 'link_class' => '',
  169. 'alt' => '',
  170. 'prefix' => '',
  171. 'suffix' => '',
  172. 'target' => '',
  173. 'help' => '',
  174. 'trim' => 0,
  175. 'max_length' => '',
  176. 'word_boundary' => 1,
  177. 'ellipsis' => 1,
  178. 'html' => 0,
  179. 'strip_tags' => 0,
  180. ),
  181. 'empty' => '',
  182. 'hide_empty' => 0,
  183. 'empty_zero' => 0,
  184. 'type' => 'yes-no',
  185. 'not' => 0,
  186. 'exclude' => 0,
  187. 'id' => 'is_obsolete',
  188. 'table' => 'cvterm',
  189. 'field' => 'is_obsolete',
  190. 'relationship' => 'none',
  191. ),
  192. 'is_relationshiptype' => array(
  193. 'label' => 'Is Relationship',
  194. 'alter' => array(
  195. 'alter_text' => 0,
  196. 'text' => '',
  197. 'make_link' => 0,
  198. 'path' => '',
  199. 'link_class' => '',
  200. 'alt' => '',
  201. 'prefix' => '',
  202. 'suffix' => '',
  203. 'target' => '',
  204. 'help' => '',
  205. 'trim' => 0,
  206. 'max_length' => '',
  207. 'word_boundary' => 1,
  208. 'ellipsis' => 1,
  209. 'html' => 0,
  210. 'strip_tags' => 0,
  211. ),
  212. 'empty' => '',
  213. 'hide_empty' => 0,
  214. 'empty_zero' => 0,
  215. 'type' => 'yes-no',
  216. 'not' => 0,
  217. 'exclude' => 0,
  218. 'id' => 'is_relationshiptype',
  219. 'table' => 'cvterm',
  220. 'field' => 'is_relationshiptype',
  221. 'relationship' => 'none',
  222. ),
  223. 'accession_link' => array(
  224. 'label' => 'Accession Link',
  225. 'alter' => array(
  226. 'alter_text' => 0,
  227. 'text' => '',
  228. 'make_link' => 0,
  229. 'path' => '',
  230. 'link_class' => '',
  231. 'alt' => '',
  232. 'prefix' => '',
  233. 'suffix' => '',
  234. 'target' => '',
  235. 'help' => '',
  236. 'trim' => 0,
  237. 'max_length' => '',
  238. 'word_boundary' => 1,
  239. 'ellipsis' => 1,
  240. 'html' => 0,
  241. 'strip_tags' => 0,
  242. ),
  243. 'empty' => '',
  244. 'hide_empty' => 0,
  245. 'empty_zero' => 0,
  246. 'exclude' => 0,
  247. 'id' => 'accession_link',
  248. 'table' => 'dbxref',
  249. 'field' => 'accession_link',
  250. 'relationship' => 'none',
  251. ),
  252. ));
  253. $handler->override_option('filters', array(
  254. 'name' => array(
  255. 'operator' => '=',
  256. 'value' => '<select cv>',
  257. 'group' => '0',
  258. 'exposed' => TRUE,
  259. 'expose' => array(
  260. 'use_operator' => 0,
  261. 'operator' => 'name_op',
  262. 'identifier' => 'cv',
  263. 'label' => 'Vocabulary',
  264. 'optional' => 0,
  265. 'remember' => 0,
  266. ),
  267. 'case' => 1,
  268. 'id' => 'name',
  269. 'table' => 'cv',
  270. 'field' => 'name',
  271. 'relationship' => 'none',
  272. ),
  273. 'name_1' => array(
  274. 'operator' => '~',
  275. 'value' => '',
  276. 'group' => '0',
  277. 'exposed' => TRUE,
  278. 'expose' => array(
  279. 'use_operator' => 0,
  280. 'operator' => '',
  281. 'identifier' => 'name',
  282. 'label' => 'Name Contains',
  283. 'optional' => 1,
  284. 'remember' => 0,
  285. ),
  286. 'case' => 0,
  287. 'id' => 'name_1',
  288. 'table' => 'cvterm',
  289. 'field' => 'name',
  290. 'relationship' => 'none',
  291. 'values_form_type' => 'textfield',
  292. ),
  293. 'definition' => array(
  294. 'operator' => 'contains',
  295. 'value' => '',
  296. 'group' => '0',
  297. 'exposed' => TRUE,
  298. 'expose' => array(
  299. 'use_operator' => 0,
  300. 'operator' => 'definition_op',
  301. 'identifier' => 'definition',
  302. 'label' => 'Definition Contains',
  303. 'optional' => 1,
  304. 'remember' => 0,
  305. ),
  306. 'case' => 0,
  307. 'id' => 'definition',
  308. 'table' => 'cvterm',
  309. 'field' => 'definition',
  310. 'relationship' => 'none',
  311. ),
  312. ));
  313. $handler->override_option('access', array(
  314. 'type' => 'perm',
  315. 'perm' => 'access chado_cv content',
  316. ));
  317. $handler->override_option('cache', array(
  318. 'type' => 'none',
  319. ));
  320. $handler->override_option('title', 'Controlled Vocabulary Terms');
  321. $handler->override_option('empty', 'There are no terms associated with the selected controlled vocabulary. Please select a different vocabulary from the list above.');
  322. $handler->override_option('empty_format', '1');
  323. $handler->override_option('items_per_page', 50);
  324. $handler->override_option('use_pager', '1');
  325. $handler->override_option('style_plugin', 'table');
  326. $handler->override_option('style_options', array(
  327. 'grouping' => '',
  328. 'override' => 1,
  329. 'sticky' => 0,
  330. 'order' => 'asc',
  331. 'columns' => array(
  332. 'definition' => 'definition',
  333. 'is_obsolete' => 'is_obsolete',
  334. 'is_relationshiptype' => 'is_relationshiptype',
  335. 'name' => 'name',
  336. 'accession_link' => 'accession_link',
  337. ),
  338. 'info' => array(
  339. 'definition' => array(
  340. 'sortable' => 0,
  341. 'separator' => '',
  342. ),
  343. 'is_obsolete' => array(
  344. 'sortable' => 1,
  345. 'separator' => '',
  346. ),
  347. 'is_relationshiptype' => array(
  348. 'sortable' => 1,
  349. 'separator' => '',
  350. ),
  351. 'name' => array(
  352. 'sortable' => 1,
  353. 'separator' => '',
  354. ),
  355. 'accession_link' => array(
  356. 'sortable' => 1,
  357. 'separator' => '',
  358. ),
  359. ),
  360. 'default' => '-1',
  361. ));
  362. $handler = $view->new_display('page', 'Page', 'page_1');
  363. $handler->override_option('path', 'admin/tripal/tripal_cv/list_cvterms');
  364. $handler->override_option('menu', array(
  365. 'type' => 'normal',
  366. 'title' => 'Term Listing',
  367. 'description' => 'A listing of a controlled vocabulary terms for a given vocabulary',
  368. 'weight' => '0',
  369. 'name' => 'navigation',
  370. ));
  371. $handler->override_option('tab_options', array(
  372. 'type' => 'none',
  373. 'title' => '',
  374. 'description' => '',
  375. 'weight' => 0,
  376. 'name' => 'navigation',
  377. ));
  378. $views[$view->name] = $view;
  379. return $views;
  380. }