tripal_project.views.inc 11 KB

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