tripal_project.views.inc 11 KB

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