tripal_project.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. $description_type_id = tripal_core_chado_select('cvterm',array('cvterm_id'),array('name' => 'project_description'));
  84. $description_type_id = $description_type_id[0]->cvterm_id;
  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;
  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. 'value' => 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' => 'value',
  160. 'table' => 'projectprop',
  161. 'field' => 'value',
  162. 'override' => array(
  163. 'button' => 'Override',
  164. ),
  165. 'relationship' => 'none',
  166. ),
  167. ));
  168. $handler->override_option('filters', array(
  169. 'name' => array(
  170. 'operator' => '~',
  171. 'value' => '',
  172. 'group' => '0',
  173. 'exposed' => TRUE,
  174. 'expose' => array(
  175. 'use_operator' => 0,
  176. 'operator' => 'name_op',
  177. 'identifier' => 'name',
  178. 'label' => 'Name Contains',
  179. 'remember' => 0,
  180. ),
  181. 'case' => 0,
  182. 'id' => 'name',
  183. 'table' => 'project',
  184. 'field' => 'name',
  185. 'relationship' => 'none',
  186. 'agg' => array(
  187. 'records_with' => 1,
  188. 'aggregates_with' => 1,
  189. ),
  190. ),
  191. 'type_id' => array(
  192. 'operator' => '=',
  193. 'value' => $description_type_id,
  194. 'group' => '0',
  195. 'exposed' => FALSE,
  196. 'expose' => array(
  197. 'operator' => FALSE,
  198. 'label' => '',
  199. 'optional' => FALSE,
  200. ),
  201. 'case' => 1,
  202. 'id' => 'type_id',
  203. 'table' => 'projectprop',
  204. 'field' => 'type_id',
  205. 'override' => array(
  206. 'button' => 'Override',
  207. ),
  208. 'relationship' => 'none',
  209. 'values_form_type' => 'select',
  210. 'multiple' => 0,
  211. 'optional' => 0,
  212. 'show_all' => 0,
  213. 'agg' => array(
  214. 'records_with' => 0,
  215. 'aggregates_with' => 1,
  216. ),
  217. ),
  218. 'value' => array(
  219. 'operator' => '~',
  220. 'value' => '',
  221. 'group' => '0',
  222. 'exposed' => TRUE,
  223. 'expose' => array(
  224. 'use_operator' => 0,
  225. 'operator' => 'value_op',
  226. 'identifier' => 'description',
  227. 'label' => 'Description Contains',
  228. 'remember' => 0,
  229. ),
  230. 'case' => 0,
  231. 'id' => 'value',
  232. 'table' => 'projectprop',
  233. 'field' => 'value',
  234. 'override' => array(
  235. 'button' => 'Override',
  236. ),
  237. 'relationship' => 'none',
  238. 'agg' => array(
  239. 'records_with' => 1,
  240. 'aggregates_with' => 1,
  241. ),
  242. ),
  243. ));
  244. $handler->override_option('access', array(
  245. 'type' => 'perm',
  246. 'perm' => 'access chado_projects',
  247. ));
  248. $handler->override_option('cache', array(
  249. 'type' => 'none',
  250. ));
  251. $handler->override_option('title', 'Projects');
  252. $handler->override_option('empty', 'No projects match the supplied criteria.');
  253. $handler->override_option('empty_format', '2');
  254. $handler->override_option('items_per_page', 50);
  255. $handler->override_option('use_pager', '1');
  256. $handler->override_option('style_plugin', 'table');
  257. $handler->override_option('style_options', array(
  258. 'grouping' => '',
  259. 'override' => 1,
  260. 'sticky' => 0,
  261. 'order' => 'asc',
  262. 'summary' => '',
  263. 'columns' => array(
  264. 'name' => 'name',
  265. 'description' => 'description',
  266. ),
  267. 'info' => array(
  268. 'name' => array(
  269. 'sortable' => 1,
  270. 'separator' => '',
  271. ),
  272. 'description' => array(
  273. 'sortable' => 0,
  274. 'separator' => '',
  275. ),
  276. ),
  277. 'default' => 'name',
  278. ));
  279. $default_handler = $handler;
  280. $handler = $view->new_display('page', 'Page', 'page_1');
  281. $handler->override_option('path', 'chado/projects');
  282. $handler->override_option('menu', array(
  283. 'type' => 'normal',
  284. 'title' => 'Projects',
  285. 'description' => 'A project is a collection of data resulting from a biological experiment.',
  286. 'weight' => '10',
  287. 'name' => 'navigation',
  288. ));
  289. $handler->override_option('tab_options', array(
  290. 'type' => 'none',
  291. 'title' => '',
  292. 'description' => '',
  293. 'weight' => 0,
  294. 'name' => 'navigation',
  295. ));
  296. // Add code specific to a local chado installation
  297. // NOTE: Edit $handler above to $default_handler for the default display
  298. if (tripal_core_chado_schema_exists()) {
  299. // Add nid field
  300. $fields = $view->get_items('field', 'default');
  301. $new_fields = array(
  302. 'nid' => array(
  303. 'label' => 'Nid',
  304. 'alter' => array(
  305. 'alter_text' => 0,
  306. 'text' => '',
  307. 'make_link' => 0,
  308. 'path' => '',
  309. 'absolute' => 0,
  310. 'link_class' => '',
  311. 'alt' => '',
  312. 'rel' => '',
  313. 'prefix' => '',
  314. 'suffix' => '',
  315. 'target' => '',
  316. 'help' => '',
  317. 'trim' => 0,
  318. 'max_length' => '',
  319. 'word_boundary' => 1,
  320. 'ellipsis' => 1,
  321. 'html' => 0,
  322. 'strip_tags' => 0,
  323. ),
  324. 'empty' => '',
  325. 'hide_empty' => 0,
  326. 'empty_zero' => 0,
  327. 'hide_alter_empty' => 1,
  328. 'link_to_node' => 0,
  329. 'exclude' => 1,
  330. 'id' => 'nid',
  331. 'table' => 'node',
  332. 'field' => 'nid',
  333. 'relationship' => 'none',
  334. )
  335. );
  336. $fields = $new_fields + $fields;
  337. // Adds project => Node relationship
  338. $default_handler->override_option('relationships', array(
  339. 'nid' => array(
  340. 'label' => 'Project to Node',
  341. 'required' => 0,
  342. 'id' => 'nid',
  343. 'table' => 'chado_project',
  344. 'field' => 'nid',
  345. 'relationship' => 'none',
  346. ),
  347. ));
  348. // Change project.name to have a link to the node
  349. $fields['name']['alter']['link_to_node'] = 1;
  350. $default_handler->override_option('fields', $fields);
  351. // Only show records with published nodes
  352. /**
  353. $filters = $view->get_items('filter', 'default');
  354. $filters['status'] = array(
  355. 'operator' => '=',
  356. 'value' => '1',
  357. 'group' => '0',
  358. 'exposed' => FALSE,
  359. 'expose' => array(
  360. 'operator' => FALSE,
  361. 'label' => '',
  362. ),
  363. 'id' => 'status',
  364. 'table' => 'node',
  365. 'field' => 'status',
  366. 'relationship' => 'none',
  367. );
  368. $default_handler->override_option('filters', $filters);
  369. */
  370. }
  371. $views[$view->name] = $view;
  372. return $views;
  373. }