tripal_project.views.inc 11 KB

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