tripal_cv.views.inc 10 KB

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