tripal_featuremap.views.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal organism 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_featuremap_views Map Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_featuremap
  15. */
  16. /*************************************************************************
  17. * Implements hook_views_data()
  18. * Purpose: Describe chado/tripal tables & fields to views
  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_featuremap_views
  26. */
  27. function tripal_featuremap_views_data() {
  28. $data = array();
  29. if (module_exists('tripal_views')) {
  30. $tables = array(
  31. 'featuremap'
  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 custom handle to handle type_ids
  40. $table_integration_array['fields']['unittype_id']['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
  41. // Add in node relationships if chado is in the same db as drupal
  42. if (tripal_core_chado_schema_exists()) {
  43. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  44. foreach ($integrations as $integration) {
  45. tripal_views_integration_add_entry($integration);
  46. }
  47. }
  48. else {
  49. tripal_views_integration_add_entry($table_integration_array);
  50. }
  51. }
  52. }
  53. $tables = array(
  54. 'map_cvterm',
  55. 'map_feature',
  56. 'map_pub',
  57. 'map_synonym',
  58. 'mapprop'
  59. );
  60. foreach ($tables as $tablename) {
  61. $priority = 9;
  62. if (!tripal_views_is_integrated($tablename, $priority)) {
  63. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  64. tripal_views_integration_add_entry($table_integration_array);
  65. }
  66. }
  67. }
  68. return $data;
  69. }
  70. /*************************************************************************
  71. * Implements hook_views_handlers()
  72. * Purpose: Register all custom handlers with views
  73. * where a handler describes either "the type of field",
  74. * "how a field should be filtered", "how a field should be sorted"
  75. * @return: An array of handler definitions
  76. *
  77. * @ingroup tripal_featuremap_views
  78. */
  79. function tripal_featuremap_views_handlers() {
  80. return array(
  81. 'info' => array(
  82. 'path' => drupal_get_path('module', 'tripal_featuremap') . '/views/handlers',
  83. ),
  84. 'handlers' => array(
  85. 'views_handler_field_computed_map_nid' => array(
  86. 'parent' => 'views_handler_field_numeric',
  87. ),
  88. ),
  89. );
  90. }
  91. /**
  92. * Implementation of hook_views_data_alter().
  93. */
  94. function tripal_featuremap_views_data_alter(&$data) {
  95. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  96. // Add featuer relationship to node
  97. $data['node']['map_chado_nid'] = array(
  98. 'group' => 'Map',
  99. 'title' => 'Map Node',
  100. 'help' => 'Links Chado Map Fields/Data to the Nodes in the current View.',
  101. 'real field' => 'nid',
  102. 'relationship' => array(
  103. 'handler' => 'views_handler_relationship',
  104. 'title' => t('Node => Chado'),
  105. 'label' => t('Node => Chado'),
  106. 'real field' => 'nid',
  107. 'base' => 'chado_map',
  108. 'base field' => 'nid'
  109. ),
  110. );
  111. }
  112. }
  113. /**
  114. *
  115. *
  116. * @ingroup tripal_featuremap_views
  117. */
  118. function tripal_featuremap_views_default_views() {
  119. $views = array();
  120. if (!module_exists('tripal_views')) {
  121. return $views;
  122. }
  123. // Main default view
  124. $view = new view;
  125. $view->name = 'featuremap_listing';
  126. $view->description = 'A listing of all chado feature maps';
  127. $view->tag = 'chado default';
  128. $view->base_table = 'featuremap';
  129. $view->core = 6;
  130. $view->api_version = '2';
  131. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  132. $handler = $view->new_display('default', 'Defaults', 'default');
  133. $handler->override_option('fields', array(
  134. 'name' => array(
  135. 'label' => 'Name',
  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' => 'name',
  164. 'table' => 'featuremap',
  165. 'field' => 'name',
  166. 'relationship' => 'none',
  167. ),
  168. 'description' => array(
  169. 'label' => 'Description',
  170. 'alter' => array(
  171. 'alter_text' => 0,
  172. 'text' => '',
  173. 'make_link' => 0,
  174. 'path' => '',
  175. 'absolute' => 0,
  176. 'link_class' => '',
  177. 'alt' => '',
  178. 'rel' => '',
  179. 'prefix' => '',
  180. 'suffix' => '',
  181. 'target' => '',
  182. 'help' => '',
  183. 'trim' => 0,
  184. 'max_length' => '',
  185. 'word_boundary' => 1,
  186. 'ellipsis' => 1,
  187. 'html' => 0,
  188. 'strip_tags' => 0,
  189. ),
  190. 'empty' => '',
  191. 'hide_empty' => 0,
  192. 'empty_zero' => 0,
  193. 'hide_alter_empty' => 1,
  194. 'type' => 'separator',
  195. 'separator' => ', ',
  196. 'exclude' => 0,
  197. 'id' => 'description',
  198. 'table' => 'featuremap',
  199. 'field' => 'description',
  200. 'relationship' => 'none',
  201. ),
  202. 'name_1' => array(
  203. 'label' => 'Map Units',
  204. 'alter' => array(
  205. 'alter_text' => 0,
  206. 'text' => '',
  207. 'make_link' => 0,
  208. 'path' => '',
  209. 'absolute' => 0,
  210. 'link_class' => '',
  211. 'alt' => '',
  212. 'rel' => '',
  213. 'prefix' => '',
  214. 'suffix' => '',
  215. 'target' => '',
  216. 'help' => '',
  217. 'trim' => 0,
  218. 'max_length' => '',
  219. 'word_boundary' => 1,
  220. 'ellipsis' => 1,
  221. 'html' => 0,
  222. 'strip_tags' => 0,
  223. ),
  224. 'empty' => '',
  225. 'hide_empty' => 0,
  226. 'empty_zero' => 0,
  227. 'hide_alter_empty' => 1,
  228. 'type' => 'separator',
  229. 'separator' => ', ',
  230. 'exclude' => 0,
  231. 'id' => 'name_1',
  232. 'table' => 'cvterm',
  233. 'field' => 'name',
  234. 'relationship' => 'none',
  235. ),
  236. ));
  237. $handler->override_option('sorts', array(
  238. 'name' => array(
  239. 'order' => 'ASC',
  240. 'id' => 'name',
  241. 'table' => 'featuremap',
  242. 'field' => 'name',
  243. 'relationship' => 'none',
  244. ),
  245. ));
  246. $handler->override_option('filters', array(
  247. 'unittype_id' => array(
  248. 'operator' => '=',
  249. 'value' => '',
  250. 'group' => '0',
  251. 'exposed' => TRUE,
  252. 'expose' => array(
  253. 'use_operator' => 0,
  254. 'operator' => 'unittype_id_op',
  255. 'identifier' => 'unittype_id',
  256. 'label' => 'Map Units',
  257. 'remember' => 0,
  258. ),
  259. 'case' => 1,
  260. 'id' => 'unittype_id',
  261. 'table' => 'featuremap',
  262. 'field' => 'unittype_id',
  263. 'relationship' => 'none',
  264. 'values_form_type' => 'select',
  265. 'multiple' => 1,
  266. 'optional' => 0,
  267. 'show_all' => 0,
  268. 'agg' => array(
  269. 'records_with' => 1,
  270. 'aggregates_with' => 1,
  271. ),
  272. ),
  273. 'name_1' => array(
  274. 'operator' => '~',
  275. 'value' => '',
  276. 'group' => '0',
  277. 'exposed' => TRUE,
  278. 'expose' => array(
  279. 'use_operator' => 0,
  280. 'operator' => 'name_1_op',
  281. 'identifier' => 'name_1',
  282. 'label' => 'Name',
  283. 'remember' => 0,
  284. ),
  285. 'case' => 0,
  286. 'id' => 'name_1',
  287. 'table' => 'featuremap',
  288. 'field' => 'name',
  289. 'relationship' => 'none',
  290. 'agg' => array(
  291. 'records_with' => 1,
  292. 'aggregates_with' => 1,
  293. ),
  294. ),
  295. 'description' => array(
  296. 'operator' => '~',
  297. 'value' => '',
  298. 'group' => '0',
  299. 'exposed' => TRUE,
  300. 'expose' => array(
  301. 'use_operator' => 0,
  302. 'operator' => 'description_op',
  303. 'identifier' => 'description',
  304. 'label' => 'Description',
  305. 'remember' => 0,
  306. ),
  307. 'case' => 0,
  308. 'id' => 'description',
  309. 'table' => 'featuremap',
  310. 'field' => 'description',
  311. 'relationship' => 'none',
  312. 'agg' => array(
  313. 'records_with' => 1,
  314. 'aggregates_with' => 1,
  315. ),
  316. ),
  317. 'search_results' => array(
  318. 'operator' => '=',
  319. 'value' => '',
  320. 'group' => '0',
  321. 'exposed' => FALSE,
  322. 'expose' => array(
  323. 'operator' => FALSE,
  324. 'label' => '',
  325. ),
  326. 'id' => 'search_results',
  327. 'table' => 'views',
  328. 'field' => 'search_results',
  329. 'relationship' => 'none',
  330. 'apply_button' => 'Show',
  331. 'no_results_text' => 'Click "Show" to see a list of all feature maps matching the entered criteria. If you leave a any of the criteria blank then the maps will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all maps will be listed.',
  332. ),
  333. ));
  334. $handler->override_option('access', array(
  335. 'type' => 'perm',
  336. 'perm' => 'access chado_featuremap content',
  337. ));
  338. $handler->override_option('cache', array(
  339. 'type' => 'none',
  340. ));
  341. $handler->override_option('title', 'Maps');
  342. $handler->override_option('header', 'Click "Show" to see a list of all feature maps matching the entered criteria. If you leave a any of the criteria blank then the maps will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all maps will be listed.');
  343. $handler->override_option('header_format', '1');
  344. $handler->override_option('header_empty', 1);
  345. $handler->override_option('empty', 'No feature maps match the current criteria.');
  346. $handler->override_option('empty_format', '1');
  347. $handler->override_option('items_per_page', 25);
  348. $handler->override_option('use_pager', '1');
  349. $handler->override_option('style_plugin', 'table');
  350. $handler->override_option('style_options', array(
  351. 'grouping' => '',
  352. 'override' => 1,
  353. 'sticky' => 0,
  354. 'order' => 'asc',
  355. 'summary' => '',
  356. 'columns' => array(
  357. 'name' => 'name',
  358. 'description' => 'description',
  359. 'name_1' => 'name_1',
  360. ),
  361. 'info' => array(
  362. 'name' => array(
  363. 'sortable' => 1,
  364. 'separator' => '',
  365. ),
  366. 'description' => array(
  367. 'sortable' => 1,
  368. 'separator' => '',
  369. ),
  370. 'name_1' => array(
  371. 'sortable' => 1,
  372. 'separator' => '',
  373. ),
  374. ),
  375. 'default' => '-1',
  376. ));
  377. $handler = $view->new_display('page', 'Page', 'page_1');
  378. $handler->override_option('path', 'chado/featuremaps');
  379. $handler->override_option('menu', array(
  380. 'type' => 'normal',
  381. 'title' => 'Maps',
  382. 'description' => 'A listing of chado feature maps.',
  383. 'weight' => '0',
  384. 'name' => 'navigation',
  385. ));
  386. $handler->override_option('tab_options', array(
  387. 'type' => 'none',
  388. 'title' => '',
  389. 'description' => '',
  390. 'weight' => 0,
  391. 'name' => 'navigation',
  392. ));
  393. $views[$view->name] = $view;
  394. return $views;
  395. }