tripal_project.views.inc 9.9 KB

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