tripal_project.views.inc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. if (!module_exists('tripal_views')) {
  77. return $views;
  78. }
  79. // Main default view
  80. $view = new view;
  81. $view->name = 'project_listing';
  82. $view->description = 'A listing of chado projects';
  83. $view->tag = 'chado default';
  84. $view->base_table = 'project';
  85. $view->core = 6;
  86. $view->api_version = '2';
  87. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  88. $handler = $view->new_display('default', 'Defaults', 'default');
  89. $handler->override_option('fields', array(
  90. 'name' => array(
  91. 'label' => 'Name',
  92. 'alter' => array(
  93. 'alter_text' => 0,
  94. 'text' => '',
  95. 'make_link' => 0,
  96. 'path' => '',
  97. 'absolute' => 0,
  98. 'link_class' => '',
  99. 'alt' => '',
  100. 'rel' => '',
  101. 'prefix' => '',
  102. 'suffix' => '',
  103. 'target' => '',
  104. 'help' => '',
  105. 'trim' => 0,
  106. 'max_length' => '',
  107. 'word_boundary' => 1,
  108. 'ellipsis' => 1,
  109. 'html' => 0,
  110. 'strip_tags' => 0,
  111. ),
  112. 'empty' => '',
  113. 'hide_empty' => 0,
  114. 'empty_zero' => 0,
  115. 'hide_alter_empty' => 1,
  116. 'type' => 'separator',
  117. 'separator' => ', ',
  118. 'exclude' => 0,
  119. 'id' => 'name',
  120. 'table' => 'project',
  121. 'field' => 'name',
  122. 'relationship' => 'none',
  123. ),
  124. 'description' => array(
  125. 'label' => 'Description',
  126. 'alter' => array(
  127. 'alter_text' => 0,
  128. 'text' => '',
  129. 'make_link' => 0,
  130. 'path' => '',
  131. 'absolute' => 0,
  132. 'link_class' => '',
  133. 'alt' => '',
  134. 'rel' => '',
  135. 'prefix' => '',
  136. 'suffix' => '',
  137. 'target' => '',
  138. 'help' => '',
  139. 'trim' => 0,
  140. 'max_length' => '',
  141. 'word_boundary' => 1,
  142. 'ellipsis' => 1,
  143. 'html' => 0,
  144. 'strip_tags' => 0,
  145. ),
  146. 'empty' => '',
  147. 'hide_empty' => 0,
  148. 'empty_zero' => 0,
  149. 'hide_alter_empty' => 1,
  150. 'type' => 'separator',
  151. 'separator' => ', ',
  152. 'exclude' => 0,
  153. 'id' => 'description',
  154. 'table' => 'project',
  155. 'field' => 'description',
  156. 'relationship' => 'none',
  157. ),
  158. ));
  159. $handler->override_option('filters', array(
  160. 'name' => array(
  161. 'operator' => 'contains',
  162. 'value' => '',
  163. 'group' => '0',
  164. 'exposed' => TRUE,
  165. 'expose' => array(
  166. 'use_operator' => 0,
  167. 'operator' => 'name_op',
  168. 'identifier' => 'name',
  169. 'label' => 'Name Contains',
  170. 'remember' => 0,
  171. ),
  172. 'case' => 0,
  173. 'id' => 'name',
  174. 'table' => 'project',
  175. 'field' => 'name',
  176. 'relationship' => 'none',
  177. 'agg' => array(
  178. 'records_with' => 1,
  179. 'aggregates_with' => 1,
  180. ),
  181. ),
  182. 'description' => array(
  183. 'operator' => 'contains',
  184. 'value' => '',
  185. 'group' => '0',
  186. 'exposed' => TRUE,
  187. 'expose' => array(
  188. 'use_operator' => 0,
  189. 'operator' => 'description_op',
  190. 'identifier' => 'description',
  191. 'label' => 'Description Contains',
  192. 'remember' => 0,
  193. ),
  194. 'case' => 1,
  195. 'id' => 'description',
  196. 'table' => 'project',
  197. 'field' => 'description',
  198. 'relationship' => 'none',
  199. 'agg' => array(
  200. 'records_with' => 1,
  201. 'aggregates_with' => 1,
  202. ),
  203. ),
  204. ));
  205. $handler->override_option('access', array(
  206. 'type' => 'perm',
  207. 'perm' => 'access chado_projects',
  208. ));
  209. $handler->override_option('cache', array(
  210. 'type' => 'none',
  211. ));
  212. $handler->override_option('title', 'Projects');
  213. $handler->override_option('empty', 'No projects match the supplied criteria.');
  214. $handler->override_option('empty_format', '2');
  215. $handler->override_option('items_per_page', 50);
  216. $handler->override_option('use_pager', '1');
  217. $handler->override_option('style_plugin', 'table');
  218. $handler->override_option('style_options', array(
  219. 'grouping' => '',
  220. 'override' => 1,
  221. 'sticky' => 0,
  222. 'order' => 'asc',
  223. 'summary' => '',
  224. 'columns' => array(
  225. 'name' => 'name',
  226. 'description' => 'description',
  227. ),
  228. 'info' => array(
  229. 'name' => array(
  230. 'sortable' => 1,
  231. 'separator' => '',
  232. ),
  233. 'description' => array(
  234. 'sortable' => 0,
  235. 'separator' => '',
  236. ),
  237. ),
  238. 'default' => 'name',
  239. ));
  240. $default_handler = $handler;
  241. $handler = $view->new_display('page', 'Page', 'page_1');
  242. $handler->override_option('path', 'chado/projects');
  243. $handler->override_option('menu', array(
  244. 'type' => 'normal',
  245. 'title' => 'Projects',
  246. 'description' => 'A project is a collection of data resulting from a biological experiment.',
  247. 'weight' => '10',
  248. 'name' => 'navigation',
  249. ));
  250. $handler->override_option('tab_options', array(
  251. 'type' => 'none',
  252. 'title' => '',
  253. 'description' => '',
  254. 'weight' => 0,
  255. 'name' => 'navigation',
  256. ));
  257. // Add code specific to a local chado installation
  258. // NOTE: Edit $handler above to $default_handler for the default display
  259. if (tripal_core_chado_schema_exists()) {
  260. // Add nid field
  261. $fields = $view->get_items('field', 'default');
  262. $new_fields = array(
  263. 'nid' => array(
  264. 'label' => 'Nid',
  265. 'alter' => array(
  266. 'alter_text' => 0,
  267. 'text' => '',
  268. 'make_link' => 0,
  269. 'path' => '',
  270. 'absolute' => 0,
  271. 'link_class' => '',
  272. 'alt' => '',
  273. 'rel' => '',
  274. 'prefix' => '',
  275. 'suffix' => '',
  276. 'target' => '',
  277. 'help' => '',
  278. 'trim' => 0,
  279. 'max_length' => '',
  280. 'word_boundary' => 1,
  281. 'ellipsis' => 1,
  282. 'html' => 0,
  283. 'strip_tags' => 0,
  284. ),
  285. 'empty' => '',
  286. 'hide_empty' => 0,
  287. 'empty_zero' => 0,
  288. 'hide_alter_empty' => 1,
  289. 'link_to_node' => 0,
  290. 'exclude' => 1,
  291. 'id' => 'nid',
  292. 'table' => 'node',
  293. 'field' => 'nid',
  294. 'relationship' => 'none',
  295. )
  296. );
  297. $fields = $new_fields + $fields;
  298. // Adds project => Node relationship
  299. $default_handler->override_option('relationships', array(
  300. 'nid' => array(
  301. 'label' => 'Project to Node',
  302. 'required' => 0,
  303. 'id' => 'nid',
  304. 'table' => 'chado_project',
  305. 'field' => 'nid',
  306. 'relationship' => 'none',
  307. ),
  308. ));
  309. // Change project.name to have a link to the node
  310. $fields['name']['alter']['make_link'] = 1;
  311. $fields['name']['alter']['path'] = 'node/[nid]';
  312. $default_handler->override_option('fields', $fields);
  313. // Only show records with published nodes
  314. $filters = $view->get_items('filter', 'default');
  315. $filters['status'] = array(
  316. 'operator' => '=',
  317. 'value' => '1',
  318. 'group' => '0',
  319. 'exposed' => FALSE,
  320. 'expose' => array(
  321. 'operator' => FALSE,
  322. 'label' => '',
  323. ),
  324. 'id' => 'status',
  325. 'table' => 'node',
  326. 'field' => 'status',
  327. 'relationship' => 'none',
  328. );
  329. $default_handler->override_option('filters', $filters);
  330. }
  331. $views[$view->name] = $view;
  332. return $views;
  333. }