tripal_project.views.inc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal_project 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. function tripal_project_views_data() {
  22. $data = array();
  23. if (module_exists('tripal_views')) {
  24. $tables = array(
  25. 'project'
  26. );
  27. foreach ($tables as $tablename) {
  28. if (!tripal_views_is_integrated($tablename, 9)) {
  29. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  30. // Add in node relationships if chado is in the same db as drupal
  31. if (tripal_core_chado_schema_exists()) {
  32. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  33. foreach ($integrations as $integration) {
  34. tripal_views_integration_add_entry($integration);
  35. }
  36. }
  37. else {
  38. tripal_views_integration_add_entry($table_integration_array);
  39. }
  40. }
  41. }
  42. $tables = array(
  43. );
  44. foreach ($tables as $tablename) {
  45. if (!tripal_views_is_integrated($tablename, 9)) {
  46. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  47. tripal_views_integration_add_entry($table_integration_array);
  48. }
  49. }
  50. }
  51. return $data;
  52. }
  53. /*************************************************************************
  54. * Implements hook_views_handlers()
  55. * Purpose: Register all custom handlers with views
  56. * where a handler describes either "the type of field",
  57. * "how a field should be filtered", "how a field should be sorted"
  58. *
  59. * @return: An array of handler definitions
  60. */
  61. function tripal_project_views_handlers() {
  62. return array(
  63. 'info' => array(
  64. 'path' => drupal_get_path('module', 'tripal_project') . '/views/handlers',
  65. ),
  66. 'handlers' => array(
  67. ),
  68. );
  69. }
  70. /**
  71. *
  72. * @ingroup tripal_feature_views
  73. */
  74. function tripal_project_views_default_views() {
  75. $views = array();
  76. // Main default view
  77. $view = new view;
  78. $view->name = 'project_listing';
  79. $view->description = 'A listing of chado projects';
  80. $view->tag = 'chado default';
  81. $view->base_table = 'project';
  82. $view->core = 6;
  83. $view->api_version = '2';
  84. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  85. $handler = $view->new_display('default', 'Defaults', 'default');
  86. $handler->override_option('fields', array(
  87. 'name' => array(
  88. 'label' => 'Name',
  89. 'alter' => array(
  90. 'alter_text' => 0,
  91. 'text' => '',
  92. 'make_link' => 0,
  93. 'path' => '',
  94. 'absolute' => 0,
  95. 'link_class' => '',
  96. 'alt' => '',
  97. 'rel' => '',
  98. 'prefix' => '',
  99. 'suffix' => '',
  100. 'target' => '',
  101. 'help' => '',
  102. 'trim' => 0,
  103. 'max_length' => '',
  104. 'word_boundary' => 1,
  105. 'ellipsis' => 1,
  106. 'html' => 0,
  107. 'strip_tags' => 0,
  108. ),
  109. 'empty' => '',
  110. 'hide_empty' => 0,
  111. 'empty_zero' => 0,
  112. 'hide_alter_empty' => 1,
  113. 'type' => 'separator',
  114. 'separator' => ', ',
  115. 'exclude' => 0,
  116. 'id' => 'name',
  117. 'table' => 'project',
  118. 'field' => 'name',
  119. 'relationship' => 'none',
  120. ),
  121. 'description' => array(
  122. 'label' => 'Description',
  123. 'alter' => array(
  124. 'alter_text' => 0,
  125. 'text' => '',
  126. 'make_link' => 0,
  127. 'path' => '',
  128. 'absolute' => 0,
  129. 'link_class' => '',
  130. 'alt' => '',
  131. 'rel' => '',
  132. 'prefix' => '',
  133. 'suffix' => '',
  134. 'target' => '',
  135. 'help' => '',
  136. 'trim' => 0,
  137. 'max_length' => '',
  138. 'word_boundary' => 1,
  139. 'ellipsis' => 1,
  140. 'html' => 0,
  141. 'strip_tags' => 0,
  142. ),
  143. 'empty' => '',
  144. 'hide_empty' => 0,
  145. 'empty_zero' => 0,
  146. 'hide_alter_empty' => 1,
  147. 'type' => 'separator',
  148. 'separator' => ', ',
  149. 'exclude' => 0,
  150. 'id' => 'description',
  151. 'table' => 'project',
  152. 'field' => 'description',
  153. 'relationship' => 'none',
  154. ),
  155. ));
  156. $handler->override_option('filters', array(
  157. 'name' => array(
  158. 'operator' => 'contains',
  159. 'value' => '',
  160. 'group' => '0',
  161. 'exposed' => TRUE,
  162. 'expose' => array(
  163. 'use_operator' => 0,
  164. 'operator' => 'name_op',
  165. 'identifier' => 'name',
  166. 'label' => 'Name Contains',
  167. 'remember' => 0,
  168. ),
  169. 'case' => 0,
  170. 'id' => 'name',
  171. 'table' => 'project',
  172. 'field' => 'name',
  173. 'relationship' => 'none',
  174. 'agg' => array(
  175. 'records_with' => 1,
  176. 'aggregates_with' => 1,
  177. ),
  178. ),
  179. 'description' => array(
  180. 'operator' => 'contains',
  181. 'value' => '',
  182. 'group' => '0',
  183. 'exposed' => TRUE,
  184. 'expose' => array(
  185. 'use_operator' => 0,
  186. 'operator' => 'description_op',
  187. 'identifier' => 'description',
  188. 'label' => 'Description Contains',
  189. 'remember' => 0,
  190. ),
  191. 'case' => 1,
  192. 'id' => 'description',
  193. 'table' => 'project',
  194. 'field' => 'description',
  195. 'relationship' => 'none',
  196. 'agg' => array(
  197. 'records_with' => 1,
  198. 'aggregates_with' => 1,
  199. ),
  200. ),
  201. ));
  202. $handler->override_option('access', array(
  203. 'type' => 'perm',
  204. 'perm' => 'access chado_projects',
  205. ));
  206. $handler->override_option('cache', array(
  207. 'type' => 'none',
  208. ));
  209. $handler->override_option('title', 'Projects');
  210. $handler->override_option('empty', 'There are currently no projects available.');
  211. $handler->override_option('empty_format', '2');
  212. $handler->override_option('items_per_page', 50);
  213. $handler->override_option('use_pager', '1');
  214. $handler->override_option('style_plugin', 'table');
  215. $handler->override_option('style_options', array(
  216. 'grouping' => '',
  217. 'override' => 1,
  218. 'sticky' => 0,
  219. 'order' => 'asc',
  220. 'summary' => '',
  221. 'columns' => array(
  222. 'name' => 'name',
  223. 'description' => 'description',
  224. ),
  225. 'info' => array(
  226. 'name' => array(
  227. 'sortable' => 1,
  228. 'separator' => '',
  229. ),
  230. 'description' => array(
  231. 'sortable' => 0,
  232. 'separator' => '',
  233. ),
  234. ),
  235. 'default' => 'name',
  236. ));
  237. $default_handler = $handler;
  238. $handler = $view->new_display('page', 'Page', 'page_1');
  239. $handler->override_option('path', 'chado/projects');
  240. $handler->override_option('menu', array(
  241. 'type' => 'normal',
  242. 'title' => 'Projects',
  243. 'description' => 'A project is a collection of data resulting from a biological experiment.',
  244. 'weight' => '10',
  245. 'name' => 'navigation',
  246. ));
  247. $handler->override_option('tab_options', array(
  248. 'type' => 'none',
  249. 'title' => '',
  250. 'description' => '',
  251. 'weight' => 0,
  252. 'name' => 'navigation',
  253. ));
  254. // Add code specific to a local chado installation
  255. // NOTE: Edit $handler above to $default_handler for the default display
  256. if (tripal_core_chado_schema_exists()) {
  257. // Add nid field
  258. $fields = $view->get_items('field', 'default');
  259. $new_fields = array(
  260. 'nid' => array(
  261. 'label' => 'Nid',
  262. 'alter' => array(
  263. 'alter_text' => 0,
  264. 'text' => '',
  265. 'make_link' => 0,
  266. 'path' => '',
  267. 'absolute' => 0,
  268. 'link_class' => '',
  269. 'alt' => '',
  270. 'rel' => '',
  271. 'prefix' => '',
  272. 'suffix' => '',
  273. 'target' => '',
  274. 'help' => '',
  275. 'trim' => 0,
  276. 'max_length' => '',
  277. 'word_boundary' => 1,
  278. 'ellipsis' => 1,
  279. 'html' => 0,
  280. 'strip_tags' => 0,
  281. ),
  282. 'empty' => '',
  283. 'hide_empty' => 0,
  284. 'empty_zero' => 0,
  285. 'hide_alter_empty' => 1,
  286. 'link_to_node' => 0,
  287. 'exclude' => 1,
  288. 'id' => 'nid',
  289. 'table' => 'node',
  290. 'field' => 'nid',
  291. 'relationship' => 'none',
  292. )
  293. );
  294. $fields = $new_fields + $fields;
  295. // Adds project => Node relationship
  296. $default_handler->override_option('relationships', array(
  297. 'nid' => array(
  298. 'label' => 'Project to Node',
  299. 'required' => 0,
  300. 'id' => 'nid',
  301. 'table' => 'chado_project',
  302. 'field' => 'nid',
  303. 'relationship' => 'none',
  304. ),
  305. ));
  306. // Change project.name to have a link to the node
  307. $fields['name']['alter']['make_link'] = 1;
  308. $fields['name']['alter']['path'] = 'node/[nid]';
  309. $default_handler->override_option('fields', $fields);
  310. // Only show records with published nodes
  311. $filters = $view->get_items('filter', 'default');
  312. $filters['status'] = array(
  313. 'operator' => '=',
  314. 'value' => '1',
  315. 'group' => '0',
  316. 'exposed' => FALSE,
  317. 'expose' => array(
  318. 'operator' => FALSE,
  319. 'label' => '',
  320. ),
  321. 'id' => 'status',
  322. 'table' => 'node',
  323. 'field' => 'status',
  324. 'relationship' => 'none',
  325. );
  326. $default_handler->override_option('filters', $filters);
  327. }
  328. $views[$view->name] = $view;
  329. return $views;
  330. }