tripal_project.views.inc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. $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. // Add in node relationships if chado is in the same db as drupal
  34. if (tripal_core_chado_schema_exists()) {
  35. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  36. foreach ($integrations as $integration) {
  37. tripal_views_integration_add_entry($integration);
  38. }
  39. }
  40. else {
  41. tripal_views_integration_add_entry($table_integration_array);
  42. }
  43. }
  44. }
  45. $tables = array(
  46. );
  47. foreach ($tables as $tablename) {
  48. $priority = 9;
  49. if (!tripal_views_is_integrated($tablename, $priority)) {
  50. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  51. tripal_views_integration_add_entry($table_integration_array);
  52. }
  53. }
  54. }
  55. return $data;
  56. }
  57. /*************************************************************************
  58. * Implements hook_views_handlers()
  59. * Purpose: Register all custom handlers with views
  60. * where a handler describes either "the type of field",
  61. * "how a field should be filtered", "how a field should be sorted"
  62. *
  63. * @return: An array of handler definitions
  64. */
  65. function tripal_project_views_handlers() {
  66. return array(
  67. 'info' => array(
  68. 'path' => drupal_get_path('module', 'tripal_project') . '/views/handlers',
  69. ),
  70. 'handlers' => array(
  71. ),
  72. );
  73. }
  74. /**
  75. *
  76. * @ingroup tripal_feature_views
  77. */
  78. function tripal_project_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 = 'project_listing';
  86. $view->description = 'A listing of chado projects';
  87. $view->tag = 'chado default';
  88. $view->base_table = 'project';
  89. $view->core = 6;
  90. $view->api_version = '2';
  91. $view->disabled = FALSE; /* 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' => 'project',
  125. 'field' => 'name',
  126. 'relationship' => 'none',
  127. ),
  128. 'description' => array(
  129. 'label' => 'Description',
  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' => 'description',
  158. 'table' => 'project',
  159. 'field' => 'description',
  160. 'relationship' => 'none',
  161. ),
  162. ));
  163. $handler->override_option('filters', array(
  164. 'name' => array(
  165. 'operator' => 'contains',
  166. 'value' => '',
  167. 'group' => '0',
  168. 'exposed' => TRUE,
  169. 'expose' => array(
  170. 'use_operator' => 0,
  171. 'operator' => 'name_op',
  172. 'identifier' => 'name',
  173. 'label' => 'Name Contains',
  174. 'remember' => 0,
  175. ),
  176. 'case' => 0,
  177. 'id' => 'name',
  178. 'table' => 'project',
  179. 'field' => 'name',
  180. 'relationship' => 'none',
  181. 'agg' => array(
  182. 'records_with' => 1,
  183. 'aggregates_with' => 1,
  184. ),
  185. ),
  186. 'description' => array(
  187. 'operator' => 'contains',
  188. 'value' => '',
  189. 'group' => '0',
  190. 'exposed' => TRUE,
  191. 'expose' => array(
  192. 'use_operator' => 0,
  193. 'operator' => 'description_op',
  194. 'identifier' => 'description',
  195. 'label' => 'Description Contains',
  196. 'remember' => 0,
  197. ),
  198. 'case' => 1,
  199. 'id' => 'description',
  200. 'table' => 'project',
  201. 'field' => 'description',
  202. 'relationship' => 'none',
  203. 'agg' => array(
  204. 'records_with' => 1,
  205. 'aggregates_with' => 1,
  206. ),
  207. ),
  208. ));
  209. $handler->override_option('access', array(
  210. 'type' => 'perm',
  211. 'perm' => 'access chado_projects',
  212. ));
  213. $handler->override_option('cache', array(
  214. 'type' => 'none',
  215. ));
  216. $handler->override_option('title', 'Projects');
  217. $handler->override_option('empty', 'No projects match the supplied criteria.');
  218. $handler->override_option('empty_format', '2');
  219. $handler->override_option('items_per_page', 50);
  220. $handler->override_option('use_pager', '1');
  221. $handler->override_option('style_plugin', 'table');
  222. $handler->override_option('style_options', array(
  223. 'grouping' => '',
  224. 'override' => 1,
  225. 'sticky' => 0,
  226. 'order' => 'asc',
  227. 'summary' => '',
  228. 'columns' => array(
  229. 'name' => 'name',
  230. 'description' => 'description',
  231. ),
  232. 'info' => array(
  233. 'name' => array(
  234. 'sortable' => 1,
  235. 'separator' => '',
  236. ),
  237. 'description' => array(
  238. 'sortable' => 0,
  239. 'separator' => '',
  240. ),
  241. ),
  242. 'default' => 'name',
  243. ));
  244. $default_handler = $handler;
  245. $handler = $view->new_display('page', 'Page', 'page_1');
  246. $handler->override_option('path', 'chado/projects');
  247. $handler->override_option('menu', array(
  248. 'type' => 'normal',
  249. 'title' => 'Projects',
  250. 'description' => 'A project is a collection of data resulting from a biological experiment.',
  251. 'weight' => '10',
  252. 'name' => 'navigation',
  253. ));
  254. $handler->override_option('tab_options', array(
  255. 'type' => 'none',
  256. 'title' => '',
  257. 'description' => '',
  258. 'weight' => 0,
  259. 'name' => 'navigation',
  260. ));
  261. // Add code specific to a local chado installation
  262. // NOTE: Edit $handler above to $default_handler for the default display
  263. if (tripal_core_chado_schema_exists()) {
  264. // Add nid field
  265. $fields = $view->get_items('field', 'default');
  266. $new_fields = array(
  267. 'nid' => array(
  268. 'label' => 'Nid',
  269. 'alter' => array(
  270. 'alter_text' => 0,
  271. 'text' => '',
  272. 'make_link' => 0,
  273. 'path' => '',
  274. 'absolute' => 0,
  275. 'link_class' => '',
  276. 'alt' => '',
  277. 'rel' => '',
  278. 'prefix' => '',
  279. 'suffix' => '',
  280. 'target' => '',
  281. 'help' => '',
  282. 'trim' => 0,
  283. 'max_length' => '',
  284. 'word_boundary' => 1,
  285. 'ellipsis' => 1,
  286. 'html' => 0,
  287. 'strip_tags' => 0,
  288. ),
  289. 'empty' => '',
  290. 'hide_empty' => 0,
  291. 'empty_zero' => 0,
  292. 'hide_alter_empty' => 1,
  293. 'link_to_node' => 0,
  294. 'exclude' => 1,
  295. 'id' => 'nid',
  296. 'table' => 'node',
  297. 'field' => 'nid',
  298. 'relationship' => 'none',
  299. )
  300. );
  301. $fields = $new_fields + $fields;
  302. // Adds project => Node relationship
  303. $default_handler->override_option('relationships', array(
  304. 'nid' => array(
  305. 'label' => 'Project to Node',
  306. 'required' => 0,
  307. 'id' => 'nid',
  308. 'table' => 'chado_project',
  309. 'field' => 'nid',
  310. 'relationship' => 'none',
  311. ),
  312. ));
  313. // Change project.name to have a link to the node
  314. $fields['name']['alter']['make_link'] = 1;
  315. $fields['name']['alter']['path'] = 'node/[nid]';
  316. $default_handler->override_option('fields', $fields);
  317. // Only show records with published nodes
  318. $filters = $view->get_items('filter', 'default');
  319. $filters['status'] = array(
  320. 'operator' => '=',
  321. 'value' => '1',
  322. 'group' => '0',
  323. 'exposed' => FALSE,
  324. 'expose' => array(
  325. 'operator' => FALSE,
  326. 'label' => '',
  327. ),
  328. 'id' => 'status',
  329. 'table' => 'node',
  330. 'field' => 'status',
  331. 'relationship' => 'none',
  332. );
  333. $default_handler->override_option('filters', $filters);
  334. }
  335. $views[$view->name] = $view;
  336. return $views;
  337. }