tripal_featuremap.views.inc 12 KB

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