tripal_contact.views.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal_contact 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. * Implements hook_views_data()
  13. * Purpose: Describe chado/tripal tables & fields to views
  14. *
  15. * @return: a data array which follows the structure outlined in the
  16. * views2 documentation for this hook. Essentially, it's an array of table
  17. * definitions keyed by chado/tripal table name. Each table definition
  18. * includes basic details about the table, fields in that table and
  19. * relationships between that table and others (joins)
  20. *
  21. * @ingroup tripal_contact
  22. */
  23. function tripal_contact_views_data() {
  24. $data = array();
  25. if (module_exists('tripal_views')) {
  26. // Base Table: contact
  27. $tablename = 'contact';
  28. $priority = 9;
  29. // check to see if the table is integrated. If it is then integrate it's
  30. // corresponding 'chado_[table]' table.
  31. if (!tripal_views_is_integrated($tablename, $priority)) {
  32. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  33. $status = tripal_views_integration_add_entry($table_integration_array);
  34. if (!$status) {
  35. drupal_set_message(t('Tripal Contact is unable to integrate %table', array('%table' => $tablename)), 'error');
  36. }
  37. }
  38. // Additional tables
  39. $tables = array(
  40. 'contact_relationship',
  41. );
  42. foreach ($tables as $tablename) {
  43. $priority = 9;
  44. if (!tripal_views_is_integrated($tablename, $priority)) {
  45. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  46. $status = tripal_views_integration_add_entry($table_integration_array);
  47. if (!$status) {
  48. drupal_set_message(t('Tripal Contact is unable to integrate %table', array('%table' => $tablename)), 'error');
  49. }
  50. }
  51. }
  52. }
  53. return $data;
  54. }
  55. /*************************************************************************
  56. * Implements hook_views_handlers()
  57. * Purpose: Register all custom handlers with views
  58. * where a handler describes either "the type of field",
  59. * "how a field should be filtered", "how a field should be sorted"
  60. *
  61. * @return: An array of handler definitions
  62. *
  63. * @ingroup tripal_contact
  64. */
  65. function tripal_contact_views_handlers() {
  66. return array(
  67. 'info' => array(
  68. 'path' => drupal_get_path('module', 'tripal_contact') . '/views/handlers',
  69. ),
  70. 'handlers' => array(
  71. ),
  72. );
  73. }
  74. /**
  75. *
  76. * @ingroup tripal_feature_views
  77. */
  78. function tripal_contact_views_default_views() {
  79. $views = array();
  80. if (!module_exists('tripal_views')) {
  81. return $views;
  82. }
  83. // Main default view
  84. $view = new view;
  85. $view->name = 'contact_listing';
  86. $view->description = 'A listing of chado contacts';
  87. $view->tag = 'chado default';
  88. $view->base_table = 'contact';
  89. $view->core = 6;
  90. $view->api_version = '2';
  91. $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
  92. $handler = $view->new_display('default', 'Defaults', 'default');
  93. $handler->override_option('fields', array(
  94. 'name' => array(
  95. 'label' => 'Name',
  96. 'alter' => array(
  97. 'alter_text' => 0,
  98. 'text' => '',
  99. 'make_link' => 0,
  100. 'path' => '',
  101. 'absolute' => 0,
  102. 'link_class' => '',
  103. 'alt' => '',
  104. 'rel' => '',
  105. 'prefix' => '',
  106. 'suffix' => '',
  107. 'target' => '',
  108. 'help' => '',
  109. 'trim' => 0,
  110. 'max_length' => '',
  111. 'word_boundary' => 1,
  112. 'ellipsis' => 1,
  113. 'html' => 0,
  114. 'strip_tags' => 0,
  115. ),
  116. 'empty' => '',
  117. 'hide_empty' => 0,
  118. 'empty_zero' => 0,
  119. 'hide_alter_empty' => 1,
  120. 'type' => 'separator',
  121. 'separator' => ', ',
  122. 'exclude' => 0,
  123. 'id' => 'name',
  124. 'table' => 'contact',
  125. 'field' => 'name',
  126. 'relationship' => 'none',
  127. ),
  128. 'name_1' => array(
  129. 'label' => 'Type',
  130. 'alter' => array(
  131. 'alter_text' => 0,
  132. 'text' => '',
  133. 'make_link' => 0,
  134. 'path' => '',
  135. 'absolute' => 0,
  136. 'link_class' => '',
  137. 'alt' => '',
  138. 'rel' => '',
  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. 'hide_alter_empty' => 1,
  154. 'type' => 'separator',
  155. 'separator' => ', ',
  156. 'exclude' => 0,
  157. 'id' => 'name_1',
  158. 'table' => 'cvterm',
  159. 'field' => 'name',
  160. 'relationship' => 'none',
  161. ),
  162. 'description' => array(
  163. 'label' => 'Description',
  164. 'alter' => array(
  165. 'alter_text' => 0,
  166. 'text' => '',
  167. 'make_link' => 0,
  168. 'path' => '',
  169. 'absolute' => 0,
  170. 'link_class' => '',
  171. 'alt' => '',
  172. 'rel' => '',
  173. 'prefix' => '',
  174. 'suffix' => '',
  175. 'target' => '',
  176. 'help' => '',
  177. 'trim' => 0,
  178. 'max_length' => '',
  179. 'word_boundary' => 1,
  180. 'ellipsis' => 1,
  181. 'html' => 0,
  182. 'strip_tags' => 0,
  183. ),
  184. 'empty' => '',
  185. 'hide_empty' => 0,
  186. 'empty_zero' => 0,
  187. 'hide_alter_empty' => 1,
  188. 'type' => 'separator',
  189. 'separator' => ', ',
  190. 'exclude' => 0,
  191. 'id' => 'description',
  192. 'table' => 'contact',
  193. 'field' => 'description',
  194. 'relationship' => 'none',
  195. ),
  196. ));
  197. $handler->override_option('filters', array(
  198. 'search_results' => array(
  199. 'operator' => '=',
  200. 'value' => '',
  201. 'group' => '0',
  202. 'exposed' => FALSE,
  203. 'expose' => array(
  204. 'operator' => FALSE,
  205. 'label' => '',
  206. ),
  207. 'id' => 'search_results',
  208. 'table' => 'views',
  209. 'field' => 'search_results',
  210. 'relationship' => 'none',
  211. 'apply_button' => 'Show',
  212. 'no_results_text' => 'Click "Show" to see a list of all contacts matching the entered criteria. If you leave a any of the criteria blank then the contacts will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all contacts will be listed.',
  213. ),
  214. 'type_id' => array(
  215. 'operator' => '=',
  216. 'value' => '',
  217. 'group' => '0',
  218. 'exposed' => TRUE,
  219. 'expose' => array(
  220. 'use_operator' => 0,
  221. 'operator' => 'type_id_op',
  222. 'identifier' => 'type_id',
  223. 'label' => 'Type',
  224. 'remember' => 0,
  225. ),
  226. 'case' => 1,
  227. 'id' => 'type_id',
  228. 'table' => 'contact',
  229. 'field' => 'type_id',
  230. 'relationship' => 'none',
  231. 'values_form_type' => 'select',
  232. 'multiple' => 1,
  233. 'optional' => 0,
  234. 'show_all' => 0,
  235. 'agg' => array(
  236. 'records_with' => 1,
  237. 'aggregates_with' => 1,
  238. ),
  239. ),
  240. 'name' => array(
  241. 'operator' => '~',
  242. 'value' => '',
  243. 'group' => '0',
  244. 'exposed' => TRUE,
  245. 'expose' => array(
  246. 'use_operator' => 0,
  247. 'operator' => 'name_op',
  248. 'identifier' => 'name',
  249. 'label' => 'Name Contains',
  250. 'remember' => 0,
  251. ),
  252. 'case' => 0,
  253. 'id' => 'name',
  254. 'table' => 'contact',
  255. 'field' => 'name',
  256. 'relationship' => 'none',
  257. 'agg' => array(
  258. 'records_with' => 1,
  259. 'aggregates_with' => 1,
  260. ),
  261. ),
  262. 'description' => array(
  263. 'operator' => '~',
  264. 'value' => '',
  265. 'group' => '0',
  266. 'exposed' => TRUE,
  267. 'expose' => array(
  268. 'use_operator' => 0,
  269. 'operator' => 'description_op',
  270. 'identifier' => 'description',
  271. 'label' => 'Description Contains',
  272. 'remember' => 0,
  273. ),
  274. 'case' => 0,
  275. 'id' => 'description',
  276. 'table' => 'contact',
  277. 'field' => 'description',
  278. 'relationship' => 'none',
  279. 'agg' => array(
  280. 'records_with' => 1,
  281. 'aggregates_with' => 1,
  282. ),
  283. ),
  284. ));
  285. $handler->override_option('access', array(
  286. 'type' => 'perm',
  287. 'perm' => 'access content',
  288. ));
  289. $handler->override_option('cache', array(
  290. 'type' => 'none',
  291. ));
  292. $handler->override_option('title', 'Contacts');
  293. $handler->override_option('header', 'Click "Show" to see a list of all contacts matching the entered criteria. If you leave a any of the criteria blank then the contacts will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all contacts will be listed.');
  294. $handler->override_option('header_format', '2');
  295. $handler->override_option('header_empty', 0);
  296. $handler->override_option('empty', 'No contacts match the current criteria.');
  297. $handler->override_option('empty_format', '2');
  298. $handler->override_option('items_per_page', 50);
  299. $handler->override_option('use_pager', '1');
  300. $handler->override_option('style_plugin', 'table');
  301. $handler->override_option('style_options', array(
  302. 'grouping' => '',
  303. 'override' => 1,
  304. 'sticky' => 0,
  305. 'order' => 'asc',
  306. 'summary' => '',
  307. 'columns' => array(
  308. 'name' => 'name',
  309. 'name_1' => 'name_1',
  310. 'description' => 'description',
  311. ),
  312. 'info' => array(
  313. 'name' => array(
  314. 'sortable' => 1,
  315. 'separator' => '',
  316. ),
  317. 'name_1' => array(
  318. 'sortable' => 1,
  319. 'separator' => '',
  320. ),
  321. 'description' => array(
  322. 'sortable' => 0,
  323. 'separator' => '',
  324. ),
  325. ),
  326. 'default' => 'name',
  327. ));
  328. $handler = $view->new_display('page', 'Page', 'page_1');
  329. $handler->override_option('path', 'chado/contacts');
  330. $handler->override_option('menu', array(
  331. 'type' => 'normal',
  332. 'title' => 'Contacts',
  333. 'description' => 'Contacts can be persons, institutes, groups, or organizations.',
  334. 'weight' => '10',
  335. 'name' => 'navigation',
  336. ));
  337. $handler->override_option('tab_options', array(
  338. 'type' => 'none',
  339. 'title' => '',
  340. 'description' => '',
  341. 'weight' => 0,
  342. 'name' => 'navigation',
  343. ));
  344. $views[$view->name] = $view;
  345. return $views;
  346. }